src/work/klao/iter_map_test.cc
author klao
Wed, 21 Apr 2004 18:56:26 +0000
changeset 365 9ca84022df34
parent 362 6c2e8a1f380a
child 366 be6fe0ea99b5
permissions -rw-r--r--
Masikfele iteralas, Node-hoz alkalmazkodva...
     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 int main() {
    30 
    31   {
    32     BaseMap base(344);
    33     TestMap test(base);
    34 
    35 
    36     print(test);
    37 
    38     cout << "Inserting 12 to class 2...\n";
    39     test.insert(12,2);
    40     print(test);
    41 
    42 
    43     cout << "Inserting 22 to class 2...\n";
    44     test.insert(22,2);
    45     print(test);
    46 
    47     cout << "Testing some map values:\n";
    48     cout << " 12: " << int(test[12]) << endl;
    49 
    50     cout << "Inserting 10 to class 0...\n";
    51     test.insert(10,0);
    52     print(test);
    53 
    54     cout << "Testing some map values:\n";
    55     cout << " 12: " << int(test[12]) << endl;
    56 
    57     cout << "Inserting 11 to class 1...\n";
    58     test.insert(11,1);
    59     print(test);
    60 
    61     cout << "Testing some map values:\n";
    62     cout << " 12: " << int(test[12]) << endl;
    63     cout << " 22: " << int(test[22]) << endl;
    64     cout << " 10: " << int(test[10]) << endl;
    65     cout << " 11: " << int(test[11]) << endl;
    66     cout << " 42: " << int(test[42]) << endl;
    67 
    68     cout << "Inserting 21 to class 1...\n";
    69     test.insert(21,1);
    70     print(test);
    71 
    72     cout << "Inserting 20 to class 1...\n";
    73     test.insert(20,0);
    74     print(test);
    75 
    76     cout << "Testing some map values:\n";
    77     cout << " 12: " << int(test[12]) << endl;
    78     cout << " 22: " << int(test[22]) << endl;
    79     cout << " 10: " << int(test[10]) << endl;
    80     cout << " 20: " << int(test[20]) << endl;
    81     cout << " 11: " << int(test[11]) << endl;
    82     cout << " 21: " << int(test[21]) << endl;
    83     cout << " 42: " << int(test[42]) << endl;
    84 
    85     cout << "Setting 20 to class 2...\n";
    86     test.set(20,2);
    87     print(test);
    88   
    89     cout << "Setting 10 to class 1...\n";
    90     test.set(10,1);
    91     print(test);
    92   
    93     cout << "Setting 11 to class 1...\n";
    94     test.set(11,1);
    95     print(test);
    96   
    97     cout << "Setting 12 to class 1...\n";
    98     test.set(12,1);
    99     print(test);
   100   
   101     cout << "Setting 21 to class 2...\n";
   102     test.set(21,2);
   103     print(test);
   104   
   105     cout << "Setting 22 to class 2...\n";
   106     test.set(22,2);
   107     print(test);
   108   
   109     cout << "Testing some map values:\n";
   110     cout << " 12: " << int(test[12]) << endl;
   111     cout << " 22: " << int(test[22]) << endl;
   112     cout << " 10: " << int(test[10]) << endl;
   113     cout << " 20: " << int(test[20]) << endl;
   114     cout << " 11: " << int(test[11]) << endl;
   115     cout << " 21: " << int(test[21]) << endl;
   116     cout << " 42: " << int(test[42]) << endl;
   117   }
   118 
   119   {
   120     cout << "\n\n\nTesting the IterableBoolMap...\n";
   121 
   122     BaseMap base(344);
   123     TestBoolMap test(base,true);
   124 
   125 
   126     print(test,2);
   127 
   128     cout << "Inserting 12 to class true...\n";
   129     test.insert(12,true);
   130     print(test,2);
   131 
   132 
   133     cout << "Inserting 22 to class true...\n";
   134     test.insert(22,true);
   135     print(test,2);
   136 
   137     cout << "Testing some map values:\n";
   138     cout << " 12: " << test[12] << endl;
   139 
   140     cout << "Inserting 10 to class false...\n";
   141     test.insert(10,false);
   142     print(test,2);
   143 
   144     cout << "Testing some map values:\n";
   145     cout << " 12: " << test[12] << endl;
   146 
   147     cout << "Inserting 11 to class false...\n";
   148     test.insert(11,false);
   149     print(test,2);
   150 
   151     cout << "Testing some map values:\n";
   152     cout << " 12: " << test[12] << endl;
   153     cout << " 22: " << test[22] << endl;
   154     cout << " 10: " << test[10] << endl;
   155     cout << " 11: " << test[11] << endl;
   156     cout << " 42: " << test[42] << endl;
   157 
   158     cout << "Setting 10 to class true...\n";
   159     test.set(10,true);
   160     print(test,2);
   161   
   162     cout << "Setting 11 to class true...\n";
   163     test.set(11,1);
   164     print(test,2);
   165   
   166     cout << "Setting 12 to class false...\n";
   167     test.set(12,false);
   168     print(test,2);
   169   
   170     cout << "Setting 22 to class false...\n";
   171     test.set(22,false);
   172     print(test,2);
   173   
   174     cout << "Testing some map values:\n";
   175     cout << " 12: " << test[12] << endl;
   176     cout << " 22: " << test[22] << endl;
   177     cout << " 10: " << test[10] << endl;
   178     cout << " 11: " << test[11] << endl;
   179     cout << " 42: " << test[42] << endl;
   180 
   181   }
   182 }