src/work/klao/iter_map_test.cc
changeset 361 ab0899df30d2
parent 347 e4ab32225f1c
child 362 6c2e8a1f380a
equal deleted inserted replaced
0:e1b5a630faf4 1:a7880e745f22
     8 
     8 
     9 const int N = 3;
     9 const int N = 3;
    10 
    10 
    11 typedef StdMap<int,int> BaseMap;
    11 typedef StdMap<int,int> BaseMap;
    12 typedef IterableMap<BaseMap, N> TestMap;
    12 typedef IterableMap<BaseMap, N> TestMap;
    13 
    13 typedef IterableBoolMap<BaseMap> TestBoolMap;
    14 
    14 
    15 void print(TestMap const& m) {
    15 
       
    16 template<typename TM>
       
    17 void print(TM const& m, int N = 3) {
    16   cout << "Size of the map: " << m.size() << endl;
    18   cout << "Size of the map: " << m.size() << endl;
    17   for(int i=0; i<N; ++i) {
    19   for(int i=0; i<N; ++i) {
    18     cout << "  Class " << i << ". (size=" << m.size(i) << "): " << flush;
    20     cout << "  Class " << i << ". (size=" << m.size(i) << "): " << flush;
    19     cout << "    ";
    21     cout << "    ";
    20     for(TestMap::iterator j = m.begin(i); j!=m.end(i); ++j) {
    22     for(typename TM::iterator j = m.begin(i); j!=m.end(i); ++j) {
    21       cout << " " << *j;
    23       cout << " " << *j;
    22     }
    24     }
    23     cout << endl;
    25     cout << endl;
    24   }
    26   }
    25 }
    27 }
    26 
    28 
    27 
    29 
    28 
    30 
    29 int main() {
    31 int main() {
    30 
    32 
    31   BaseMap base(344);
    33   {
    32   TestMap test(base);
    34     BaseMap base(344);
    33 
    35     TestMap test(base);
    34 
    36 
    35   print(test);
    37 
    36 
    38     print(test);
    37   cout << "Inserting 12 to class 2...\n";
    39 
    38   test.insert(12,2);
    40     cout << "Inserting 12 to class 2...\n";
    39   print(test);
    41     test.insert(12,2);
    40 
    42     print(test);
    41 
    43 
    42   cout << "Inserting 22 to class 2...\n";
    44 
    43   test.insert(22,2);
    45     cout << "Inserting 22 to class 2...\n";
    44   print(test);
    46     test.insert(22,2);
    45 
    47     print(test);
    46   cout << "Testing some map values:\n";
    48 
    47   cout << " 12: " << int(test[12]) << endl;
    49     cout << "Testing some map values:\n";
    48 
    50     cout << " 12: " << int(test[12]) << endl;
    49   cout << "Inserting 10 to class 0...\n";
    51 
    50   test.insert(10,0);
    52     cout << "Inserting 10 to class 0...\n";
    51   print(test);
    53     test.insert(10,0);
    52 
    54     print(test);
    53   cout << "Testing some map values:\n";
    55 
    54   cout << " 12: " << int(test[12]) << endl;
    56     cout << "Testing some map values:\n";
    55 
    57     cout << " 12: " << int(test[12]) << endl;
    56   cout << "Inserting 11 to class 1...\n";
    58 
    57   test.insert(11,1);
    59     cout << "Inserting 11 to class 1...\n";
    58   print(test);
    60     test.insert(11,1);
    59 
    61     print(test);
    60   cout << "Testing some map values:\n";
    62 
    61   cout << " 12: " << int(test[12]) << endl;
    63     cout << "Testing some map values:\n";
    62   cout << " 22: " << int(test[22]) << endl;
    64     cout << " 12: " << int(test[12]) << endl;
    63   cout << " 10: " << int(test[10]) << endl;
    65     cout << " 22: " << int(test[22]) << endl;
    64   cout << " 11: " << int(test[11]) << endl;
    66     cout << " 10: " << int(test[10]) << endl;
    65   cout << " 42: " << int(test[42]) << endl;
    67     cout << " 11: " << int(test[11]) << endl;
    66 
    68     cout << " 42: " << int(test[42]) << endl;
    67   cout << "Inserting 21 to class 1...\n";
    69 
    68   test.insert(21,1);
    70     cout << "Inserting 21 to class 1...\n";
    69   print(test);
    71     test.insert(21,1);
    70 
    72     print(test);
    71   cout << "Inserting 20 to class 1...\n";
    73 
    72   test.insert(20,0);
    74     cout << "Inserting 20 to class 1...\n";
    73   print(test);
    75     test.insert(20,0);
    74 
    76     print(test);
    75   cout << "Testing some map values:\n";
    77 
    76   cout << " 12: " << int(test[12]) << endl;
    78     cout << "Testing some map values:\n";
    77   cout << " 22: " << int(test[22]) << endl;
    79     cout << " 12: " << int(test[12]) << endl;
    78   cout << " 10: " << int(test[10]) << endl;
    80     cout << " 22: " << int(test[22]) << endl;
    79   cout << " 20: " << int(test[20]) << endl;
    81     cout << " 10: " << int(test[10]) << endl;
    80   cout << " 11: " << int(test[11]) << endl;
    82     cout << " 20: " << int(test[20]) << endl;
    81   cout << " 21: " << int(test[21]) << endl;
    83     cout << " 11: " << int(test[11]) << endl;
    82   cout << " 42: " << int(test[42]) << endl;
    84     cout << " 21: " << int(test[21]) << endl;
    83 
    85     cout << " 42: " << int(test[42]) << endl;
    84   cout << "Setting 20 to class 2...\n";
    86 
    85   test.set(20,2);
    87     cout << "Setting 20 to class 2...\n";
    86   print(test);
    88     test.set(20,2);
    87   
    89     print(test);
    88   cout << "Setting 10 to class 1...\n";
    90   
    89   test.set(10,1);
    91     cout << "Setting 10 to class 1...\n";
    90   print(test);
    92     test.set(10,1);
    91   
    93     print(test);
    92   cout << "Setting 11 to class 1...\n";
    94   
    93   test.set(11,1);
    95     cout << "Setting 11 to class 1...\n";
    94   print(test);
    96     test.set(11,1);
    95   
    97     print(test);
    96   cout << "Setting 12 to class 1...\n";
    98   
    97   test.set(12,1);
    99     cout << "Setting 12 to class 1...\n";
    98   print(test);
   100     test.set(12,1);
    99   
   101     print(test);
   100   cout << "Setting 21 to class 2...\n";
   102   
   101   test.set(21,2);
   103     cout << "Setting 21 to class 2...\n";
   102   print(test);
   104     test.set(21,2);
   103   
   105     print(test);
   104   cout << "Setting 22 to class 2...\n";
   106   
   105   test.set(22,2);
   107     cout << "Setting 22 to class 2...\n";
   106   print(test);
   108     test.set(22,2);
   107   
   109     print(test);
   108   cout << "Testing some map values:\n";
   110   
   109   cout << " 12: " << int(test[12]) << endl;
   111     cout << "Testing some map values:\n";
   110   cout << " 22: " << int(test[22]) << endl;
   112     cout << " 12: " << int(test[12]) << endl;
   111   cout << " 10: " << int(test[10]) << endl;
   113     cout << " 22: " << int(test[22]) << endl;
   112   cout << " 20: " << int(test[20]) << endl;
   114     cout << " 10: " << int(test[10]) << endl;
   113   cout << " 11: " << int(test[11]) << endl;
   115     cout << " 20: " << int(test[20]) << endl;
   114   cout << " 21: " << int(test[21]) << endl;
   116     cout << " 11: " << int(test[11]) << endl;
   115   cout << " 42: " << int(test[42]) << endl;
   117     cout << " 21: " << int(test[21]) << endl;
   116 
   118     cout << " 42: " << int(test[42]) << endl;
       
   119   }
       
   120 
       
   121   {
       
   122     cout << "Testing the IterableBoolMap...\n";
       
   123 
       
   124     BaseMap base(344);
       
   125     TestBoolMap test(base);
       
   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 << "Inserting 21 to class 1...\n";
       
   161     test.insert(21,1);
       
   162     print(test,2);
       
   163 
       
   164     cout << "Inserting 20 to class 1...\n";
       
   165     test.insert(20,0);
       
   166     print(test,2);
       
   167 
       
   168     cout << "Testing some map values:\n";
       
   169     cout << " 12: " << test[12] << endl;
       
   170     cout << " 22: " << test[22] << endl;
       
   171     cout << " 10: " << test[10] << endl;
       
   172     cout << " 20: " << test[20] << endl;
       
   173     cout << " 11: " << test[11] << endl;
       
   174     cout << " 21: " << test[21] << endl;
       
   175     cout << " 42: " << test[42] << endl;
       
   176 
       
   177     cout << "Setting 20 to class 2...\n";
       
   178     test.set(20,2);
       
   179     print(test,2);
       
   180   
       
   181     cout << "Setting 10 to class 1...\n";
       
   182     test.set(10,1);
       
   183     print(test,2);
       
   184   
       
   185     cout << "Setting 11 to class 1...\n";
       
   186     test.set(11,1);
       
   187     print(test,2);
       
   188   
       
   189     cout << "Setting 12 to class 1...\n";
       
   190     test.set(12,1);
       
   191     print(test,2);
       
   192   
       
   193     cout << "Setting 21 to class 2...\n";
       
   194     test.set(21,2);
       
   195     print(test,2);
       
   196   
       
   197     cout << "Setting 22 to class 2...\n";
       
   198     test.set(22,2);
       
   199     print(test,2);
       
   200   
       
   201     cout << "Testing some map values:\n";
       
   202     cout << " 12: " << test[12] << endl;
       
   203     cout << " 22: " << test[22] << endl;
       
   204     cout << " 10: " << test[10] << endl;
       
   205     cout << " 20: " << test[20] << endl;
       
   206     cout << " 11: " << test[11] << endl;
       
   207     cout << " 21: " << test[21] << endl;
       
   208     cout << " 42: " << test[42] << endl;
       
   209 
       
   210   }
   117 }
   211 }