src/work/klao/iter_map_test.cc
changeset 350 3a9a767b841e
child 361 ab0899df30d2
equal deleted inserted replaced
-1:000000000000 0:e1b5a630faf4
       
     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 
       
    14 
       
    15 void print(TestMap const& m) {
       
    16   cout << "Size of the map: " << m.size() << endl;
       
    17   for(int i=0; i<N; ++i) {
       
    18     cout << "  Class " << i << ". (size=" << m.size(i) << "): " << flush;
       
    19     cout << "    ";
       
    20     for(TestMap::iterator j = m.begin(i); j!=m.end(i); ++j) {
       
    21       cout << " " << *j;
       
    22     }
       
    23     cout << endl;
       
    24   }
       
    25 }
       
    26 
       
    27 
       
    28 
       
    29 int main() {
       
    30 
       
    31   BaseMap base(344);
       
    32   TestMap test(base);
       
    33 
       
    34 
       
    35   print(test);
       
    36 
       
    37   cout << "Inserting 12 to class 2...\n";
       
    38   test.insert(12,2);
       
    39   print(test);
       
    40 
       
    41 
       
    42   cout << "Inserting 22 to class 2...\n";
       
    43   test.insert(22,2);
       
    44   print(test);
       
    45 
       
    46   cout << "Testing some map values:\n";
       
    47   cout << " 12: " << int(test[12]) << endl;
       
    48 
       
    49   cout << "Inserting 10 to class 0...\n";
       
    50   test.insert(10,0);
       
    51   print(test);
       
    52 
       
    53   cout << "Testing some map values:\n";
       
    54   cout << " 12: " << int(test[12]) << endl;
       
    55 
       
    56   cout << "Inserting 11 to class 1...\n";
       
    57   test.insert(11,1);
       
    58   print(test);
       
    59 
       
    60   cout << "Testing some map values:\n";
       
    61   cout << " 12: " << int(test[12]) << endl;
       
    62   cout << " 22: " << int(test[22]) << endl;
       
    63   cout << " 10: " << int(test[10]) << endl;
       
    64   cout << " 11: " << int(test[11]) << endl;
       
    65   cout << " 42: " << int(test[42]) << endl;
       
    66 
       
    67   cout << "Inserting 21 to class 1...\n";
       
    68   test.insert(21,1);
       
    69   print(test);
       
    70 
       
    71   cout << "Inserting 20 to class 1...\n";
       
    72   test.insert(20,0);
       
    73   print(test);
       
    74 
       
    75   cout << "Testing some map values:\n";
       
    76   cout << " 12: " << int(test[12]) << endl;
       
    77   cout << " 22: " << int(test[22]) << endl;
       
    78   cout << " 10: " << int(test[10]) << endl;
       
    79   cout << " 20: " << int(test[20]) << endl;
       
    80   cout << " 11: " << int(test[11]) << endl;
       
    81   cout << " 21: " << int(test[21]) << endl;
       
    82   cout << " 42: " << int(test[42]) << endl;
       
    83 
       
    84   cout << "Setting 20 to class 2...\n";
       
    85   test.set(20,2);
       
    86   print(test);
       
    87   
       
    88   cout << "Setting 10 to class 1...\n";
       
    89   test.set(10,1);
       
    90   print(test);
       
    91   
       
    92   cout << "Setting 11 to class 1...\n";
       
    93   test.set(11,1);
       
    94   print(test);
       
    95   
       
    96   cout << "Setting 12 to class 1...\n";
       
    97   test.set(12,1);
       
    98   print(test);
       
    99   
       
   100   cout << "Setting 21 to class 2...\n";
       
   101   test.set(21,2);
       
   102   print(test);
       
   103   
       
   104   cout << "Setting 22 to class 2...\n";
       
   105   test.set(22,2);
       
   106   print(test);
       
   107   
       
   108   cout << "Testing some map values:\n";
       
   109   cout << " 12: " << int(test[12]) << endl;
       
   110   cout << " 22: " << int(test[22]) << endl;
       
   111   cout << " 10: " << int(test[10]) << endl;
       
   112   cout << " 20: " << int(test[20]) << endl;
       
   113   cout << " 11: " << int(test[11]) << endl;
       
   114   cout << " 21: " << int(test[21]) << endl;
       
   115   cout << " 42: " << int(test[42]) << endl;
       
   116 
       
   117 }