src/work/klao/iter_map_test.cc
author klao
Wed, 21 Apr 2004 16:22:50 +0000
changeset 363 7a05119c121a
parent 361 ab0899df30d2
child 365 9ca84022df34
permissions -rw-r--r--
Idezni csak pontosan, szepen, ahogy a csiga...
     1 #include <iter_map.h>
     2 #include <maps.h>
     3 
     4 #include <iostream>
     5 
     6 using namespace hugo;
     7 using namespace std;
     8 
     9 const int N = 3;
    10 
    11 typedef StdMap<int,int> BaseMap;
    12 typedef IterableMap<BaseMap, N> TestMap;
    13 typedef IterableBoolMap<BaseMap> TestBoolMap;
    14 
    15 
    16 template<typename TM>
    17 void print(TM const& m, int N = 3) {
    18   cout << "Size of the map: " << m.size() << endl;
    19   for(int i=0; i<N; ++i) {
    20     cout << "  Class " << i << ". (size=" << m.size(i) << "): " << flush;
    21     cout << "    ";
    22     for(typename TM::iterator j = m.begin(i); j!=m.end(i); ++j) {
    23       cout << " " << *j;
    24     }
    25     cout << endl;
    26   }
    27 }
    28 
    29 
    30 
    31 int main() {
    32 
    33   {
    34     BaseMap base(344);
    35     TestMap test(base);
    36 
    37 
    38     print(test);
    39 
    40     cout << "Inserting 12 to class 2...\n";
    41     test.insert(12,2);
    42     print(test);
    43 
    44 
    45     cout << "Inserting 22 to class 2...\n";
    46     test.insert(22,2);
    47     print(test);
    48 
    49     cout << "Testing some map values:\n";
    50     cout << " 12: " << int(test[12]) << endl;
    51 
    52     cout << "Inserting 10 to class 0...\n";
    53     test.insert(10,0);
    54     print(test);
    55 
    56     cout << "Testing some map values:\n";
    57     cout << " 12: " << int(test[12]) << endl;
    58 
    59     cout << "Inserting 11 to class 1...\n";
    60     test.insert(11,1);
    61     print(test);
    62 
    63     cout << "Testing some map values:\n";
    64     cout << " 12: " << int(test[12]) << endl;
    65     cout << " 22: " << int(test[22]) << endl;
    66     cout << " 10: " << int(test[10]) << endl;
    67     cout << " 11: " << int(test[11]) << endl;
    68     cout << " 42: " << int(test[42]) << endl;
    69 
    70     cout << "Inserting 21 to class 1...\n";
    71     test.insert(21,1);
    72     print(test);
    73 
    74     cout << "Inserting 20 to class 1...\n";
    75     test.insert(20,0);
    76     print(test);
    77 
    78     cout << "Testing some map values:\n";
    79     cout << " 12: " << int(test[12]) << endl;
    80     cout << " 22: " << int(test[22]) << endl;
    81     cout << " 10: " << int(test[10]) << endl;
    82     cout << " 20: " << int(test[20]) << endl;
    83     cout << " 11: " << int(test[11]) << endl;
    84     cout << " 21: " << int(test[21]) << endl;
    85     cout << " 42: " << int(test[42]) << endl;
    86 
    87     cout << "Setting 20 to class 2...\n";
    88     test.set(20,2);
    89     print(test);
    90   
    91     cout << "Setting 10 to class 1...\n";
    92     test.set(10,1);
    93     print(test);
    94   
    95     cout << "Setting 11 to class 1...\n";
    96     test.set(11,1);
    97     print(test);
    98   
    99     cout << "Setting 12 to class 1...\n";
   100     test.set(12,1);
   101     print(test);
   102   
   103     cout << "Setting 21 to class 2...\n";
   104     test.set(21,2);
   105     print(test);
   106   
   107     cout << "Setting 22 to class 2...\n";
   108     test.set(22,2);
   109     print(test);
   110   
   111     cout << "Testing some map values:\n";
   112     cout << " 12: " << int(test[12]) << endl;
   113     cout << " 22: " << int(test[22]) << endl;
   114     cout << " 10: " << int(test[10]) << endl;
   115     cout << " 20: " << int(test[20]) << endl;
   116     cout << " 11: " << int(test[11]) << endl;
   117     cout << " 21: " << int(test[21]) << endl;
   118     cout << " 42: " << int(test[42]) << endl;
   119   }
   120 
   121   {
   122     cout << "\n\n\nTesting the IterableBoolMap...\n";
   123 
   124     BaseMap base(344);
   125     TestBoolMap test(base,true);
   126 
   127 
   128     print(test,2);
   129 
   130     cout << "Inserting 12 to class true...\n";
   131     test.insert(12,true);
   132     print(test,2);
   133 
   134 
   135     cout << "Inserting 22 to class true...\n";
   136     test.insert(22,true);
   137     print(test,2);
   138 
   139     cout << "Testing some map values:\n";
   140     cout << " 12: " << test[12] << endl;
   141 
   142     cout << "Inserting 10 to class false...\n";
   143     test.insert(10,false);
   144     print(test,2);
   145 
   146     cout << "Testing some map values:\n";
   147     cout << " 12: " << test[12] << endl;
   148 
   149     cout << "Inserting 11 to class false...\n";
   150     test.insert(11,false);
   151     print(test,2);
   152 
   153     cout << "Testing some map values:\n";
   154     cout << " 12: " << test[12] << endl;
   155     cout << " 22: " << test[22] << endl;
   156     cout << " 10: " << test[10] << endl;
   157     cout << " 11: " << test[11] << endl;
   158     cout << " 42: " << test[42] << endl;
   159 
   160     cout << "Setting 10 to class true...\n";
   161     test.set(10,true);
   162     print(test,2);
   163   
   164     cout << "Setting 11 to class true...\n";
   165     test.set(11,1);
   166     print(test,2);
   167   
   168     cout << "Setting 12 to class false...\n";
   169     test.set(12,false);
   170     print(test,2);
   171   
   172     cout << "Setting 22 to class false...\n";
   173     test.set(22,false);
   174     print(test,2);
   175   
   176     cout << "Testing some map values:\n";
   177     cout << " 12: " << test[12] << endl;
   178     cout << " 22: " << test[22] << endl;
   179     cout << " 10: " << test[10] << endl;
   180     cout << " 11: " << test[11] << endl;
   181     cout << " 42: " << test[42] << endl;
   182 
   183   }
   184 }