src/work/klao/iter_map_test.cc
changeset 361 ab0899df30d2
parent 347 e4ab32225f1c
child 362 6c2e8a1f380a
     1.1 --- a/src/work/klao/iter_map_test.cc	Wed Apr 21 15:14:45 2004 +0000
     1.2 +++ b/src/work/klao/iter_map_test.cc	Wed Apr 21 15:46:40 2004 +0000
     1.3 @@ -10,14 +10,16 @@
     1.4  
     1.5  typedef StdMap<int,int> BaseMap;
     1.6  typedef IterableMap<BaseMap, N> TestMap;
     1.7 +typedef IterableBoolMap<BaseMap> TestBoolMap;
     1.8  
     1.9  
    1.10 -void print(TestMap const& m) {
    1.11 +template<typename TM>
    1.12 +void print(TM const& m, int N = 3) {
    1.13    cout << "Size of the map: " << m.size() << endl;
    1.14    for(int i=0; i<N; ++i) {
    1.15      cout << "  Class " << i << ". (size=" << m.size(i) << "): " << flush;
    1.16      cout << "    ";
    1.17 -    for(TestMap::iterator j = m.begin(i); j!=m.end(i); ++j) {
    1.18 +    for(typename TM::iterator j = m.begin(i); j!=m.end(i); ++j) {
    1.19        cout << " " << *j;
    1.20      }
    1.21      cout << endl;
    1.22 @@ -28,90 +30,182 @@
    1.23  
    1.24  int main() {
    1.25  
    1.26 -  BaseMap base(344);
    1.27 -  TestMap test(base);
    1.28 +  {
    1.29 +    BaseMap base(344);
    1.30 +    TestMap test(base);
    1.31  
    1.32  
    1.33 -  print(test);
    1.34 +    print(test);
    1.35  
    1.36 -  cout << "Inserting 12 to class 2...\n";
    1.37 -  test.insert(12,2);
    1.38 -  print(test);
    1.39 +    cout << "Inserting 12 to class 2...\n";
    1.40 +    test.insert(12,2);
    1.41 +    print(test);
    1.42  
    1.43  
    1.44 -  cout << "Inserting 22 to class 2...\n";
    1.45 -  test.insert(22,2);
    1.46 -  print(test);
    1.47 +    cout << "Inserting 22 to class 2...\n";
    1.48 +    test.insert(22,2);
    1.49 +    print(test);
    1.50  
    1.51 -  cout << "Testing some map values:\n";
    1.52 -  cout << " 12: " << int(test[12]) << endl;
    1.53 +    cout << "Testing some map values:\n";
    1.54 +    cout << " 12: " << int(test[12]) << endl;
    1.55  
    1.56 -  cout << "Inserting 10 to class 0...\n";
    1.57 -  test.insert(10,0);
    1.58 -  print(test);
    1.59 +    cout << "Inserting 10 to class 0...\n";
    1.60 +    test.insert(10,0);
    1.61 +    print(test);
    1.62  
    1.63 -  cout << "Testing some map values:\n";
    1.64 -  cout << " 12: " << int(test[12]) << endl;
    1.65 +    cout << "Testing some map values:\n";
    1.66 +    cout << " 12: " << int(test[12]) << endl;
    1.67  
    1.68 -  cout << "Inserting 11 to class 1...\n";
    1.69 -  test.insert(11,1);
    1.70 -  print(test);
    1.71 +    cout << "Inserting 11 to class 1...\n";
    1.72 +    test.insert(11,1);
    1.73 +    print(test);
    1.74  
    1.75 -  cout << "Testing some map values:\n";
    1.76 -  cout << " 12: " << int(test[12]) << endl;
    1.77 -  cout << " 22: " << int(test[22]) << endl;
    1.78 -  cout << " 10: " << int(test[10]) << endl;
    1.79 -  cout << " 11: " << int(test[11]) << endl;
    1.80 -  cout << " 42: " << int(test[42]) << endl;
    1.81 +    cout << "Testing some map values:\n";
    1.82 +    cout << " 12: " << int(test[12]) << endl;
    1.83 +    cout << " 22: " << int(test[22]) << endl;
    1.84 +    cout << " 10: " << int(test[10]) << endl;
    1.85 +    cout << " 11: " << int(test[11]) << endl;
    1.86 +    cout << " 42: " << int(test[42]) << endl;
    1.87  
    1.88 -  cout << "Inserting 21 to class 1...\n";
    1.89 -  test.insert(21,1);
    1.90 -  print(test);
    1.91 +    cout << "Inserting 21 to class 1...\n";
    1.92 +    test.insert(21,1);
    1.93 +    print(test);
    1.94  
    1.95 -  cout << "Inserting 20 to class 1...\n";
    1.96 -  test.insert(20,0);
    1.97 -  print(test);
    1.98 +    cout << "Inserting 20 to class 1...\n";
    1.99 +    test.insert(20,0);
   1.100 +    print(test);
   1.101  
   1.102 -  cout << "Testing some map values:\n";
   1.103 -  cout << " 12: " << int(test[12]) << endl;
   1.104 -  cout << " 22: " << int(test[22]) << endl;
   1.105 -  cout << " 10: " << int(test[10]) << endl;
   1.106 -  cout << " 20: " << int(test[20]) << endl;
   1.107 -  cout << " 11: " << int(test[11]) << endl;
   1.108 -  cout << " 21: " << int(test[21]) << endl;
   1.109 -  cout << " 42: " << int(test[42]) << endl;
   1.110 +    cout << "Testing some map values:\n";
   1.111 +    cout << " 12: " << int(test[12]) << endl;
   1.112 +    cout << " 22: " << int(test[22]) << endl;
   1.113 +    cout << " 10: " << int(test[10]) << endl;
   1.114 +    cout << " 20: " << int(test[20]) << endl;
   1.115 +    cout << " 11: " << int(test[11]) << endl;
   1.116 +    cout << " 21: " << int(test[21]) << endl;
   1.117 +    cout << " 42: " << int(test[42]) << endl;
   1.118  
   1.119 -  cout << "Setting 20 to class 2...\n";
   1.120 -  test.set(20,2);
   1.121 -  print(test);
   1.122 +    cout << "Setting 20 to class 2...\n";
   1.123 +    test.set(20,2);
   1.124 +    print(test);
   1.125    
   1.126 -  cout << "Setting 10 to class 1...\n";
   1.127 -  test.set(10,1);
   1.128 -  print(test);
   1.129 +    cout << "Setting 10 to class 1...\n";
   1.130 +    test.set(10,1);
   1.131 +    print(test);
   1.132    
   1.133 -  cout << "Setting 11 to class 1...\n";
   1.134 -  test.set(11,1);
   1.135 -  print(test);
   1.136 +    cout << "Setting 11 to class 1...\n";
   1.137 +    test.set(11,1);
   1.138 +    print(test);
   1.139    
   1.140 -  cout << "Setting 12 to class 1...\n";
   1.141 -  test.set(12,1);
   1.142 -  print(test);
   1.143 +    cout << "Setting 12 to class 1...\n";
   1.144 +    test.set(12,1);
   1.145 +    print(test);
   1.146    
   1.147 -  cout << "Setting 21 to class 2...\n";
   1.148 -  test.set(21,2);
   1.149 -  print(test);
   1.150 +    cout << "Setting 21 to class 2...\n";
   1.151 +    test.set(21,2);
   1.152 +    print(test);
   1.153    
   1.154 -  cout << "Setting 22 to class 2...\n";
   1.155 -  test.set(22,2);
   1.156 -  print(test);
   1.157 +    cout << "Setting 22 to class 2...\n";
   1.158 +    test.set(22,2);
   1.159 +    print(test);
   1.160    
   1.161 -  cout << "Testing some map values:\n";
   1.162 -  cout << " 12: " << int(test[12]) << endl;
   1.163 -  cout << " 22: " << int(test[22]) << endl;
   1.164 -  cout << " 10: " << int(test[10]) << endl;
   1.165 -  cout << " 20: " << int(test[20]) << endl;
   1.166 -  cout << " 11: " << int(test[11]) << endl;
   1.167 -  cout << " 21: " << int(test[21]) << endl;
   1.168 -  cout << " 42: " << int(test[42]) << endl;
   1.169 +    cout << "Testing some map values:\n";
   1.170 +    cout << " 12: " << int(test[12]) << endl;
   1.171 +    cout << " 22: " << int(test[22]) << endl;
   1.172 +    cout << " 10: " << int(test[10]) << endl;
   1.173 +    cout << " 20: " << int(test[20]) << endl;
   1.174 +    cout << " 11: " << int(test[11]) << endl;
   1.175 +    cout << " 21: " << int(test[21]) << endl;
   1.176 +    cout << " 42: " << int(test[42]) << endl;
   1.177 +  }
   1.178  
   1.179 +  {
   1.180 +    cout << "Testing the IterableBoolMap...\n";
   1.181 +
   1.182 +    BaseMap base(344);
   1.183 +    TestBoolMap test(base);
   1.184 +
   1.185 +
   1.186 +    print(test,2);
   1.187 +
   1.188 +    cout << "Inserting 12 to class true...\n";
   1.189 +    test.insert(12,true);
   1.190 +    print(test,2);
   1.191 +
   1.192 +
   1.193 +    cout << "Inserting 22 to class true...\n";
   1.194 +    test.insert(22,true);
   1.195 +    print(test,2);
   1.196 +
   1.197 +    cout << "Testing some map values:\n";
   1.198 +    cout << " 12: " << test[12] << endl;
   1.199 +
   1.200 +    cout << "Inserting 10 to class false...\n";
   1.201 +    test.insert(10,false);
   1.202 +    print(test,2);
   1.203 +
   1.204 +    cout << "Testing some map values:\n";
   1.205 +    cout << " 12: " << test[12] << endl;
   1.206 +
   1.207 +    cout << "Inserting 11 to class false...\n";
   1.208 +    test.insert(11,false);
   1.209 +    print(test,2);
   1.210 +
   1.211 +    cout << "Testing some map values:\n";
   1.212 +    cout << " 12: " << test[12] << endl;
   1.213 +    cout << " 22: " << test[22] << endl;
   1.214 +    cout << " 10: " << test[10] << endl;
   1.215 +    cout << " 11: " << test[11] << endl;
   1.216 +    cout << " 42: " << test[42] << endl;
   1.217 +
   1.218 +    cout << "Inserting 21 to class 1...\n";
   1.219 +    test.insert(21,1);
   1.220 +    print(test,2);
   1.221 +
   1.222 +    cout << "Inserting 20 to class 1...\n";
   1.223 +    test.insert(20,0);
   1.224 +    print(test,2);
   1.225 +
   1.226 +    cout << "Testing some map values:\n";
   1.227 +    cout << " 12: " << test[12] << endl;
   1.228 +    cout << " 22: " << test[22] << endl;
   1.229 +    cout << " 10: " << test[10] << endl;
   1.230 +    cout << " 20: " << test[20] << endl;
   1.231 +    cout << " 11: " << test[11] << endl;
   1.232 +    cout << " 21: " << test[21] << endl;
   1.233 +    cout << " 42: " << test[42] << endl;
   1.234 +
   1.235 +    cout << "Setting 20 to class 2...\n";
   1.236 +    test.set(20,2);
   1.237 +    print(test,2);
   1.238 +  
   1.239 +    cout << "Setting 10 to class 1...\n";
   1.240 +    test.set(10,1);
   1.241 +    print(test,2);
   1.242 +  
   1.243 +    cout << "Setting 11 to class 1...\n";
   1.244 +    test.set(11,1);
   1.245 +    print(test,2);
   1.246 +  
   1.247 +    cout << "Setting 12 to class 1...\n";
   1.248 +    test.set(12,1);
   1.249 +    print(test,2);
   1.250 +  
   1.251 +    cout << "Setting 21 to class 2...\n";
   1.252 +    test.set(21,2);
   1.253 +    print(test,2);
   1.254 +  
   1.255 +    cout << "Setting 22 to class 2...\n";
   1.256 +    test.set(22,2);
   1.257 +    print(test,2);
   1.258 +  
   1.259 +    cout << "Testing some map values:\n";
   1.260 +    cout << " 12: " << test[12] << endl;
   1.261 +    cout << " 22: " << test[22] << endl;
   1.262 +    cout << " 10: " << test[10] << endl;
   1.263 +    cout << " 20: " << test[20] << endl;
   1.264 +    cout << " 11: " << test[11] << endl;
   1.265 +    cout << " 21: " << test[21] << endl;
   1.266 +    cout << " 42: " << test[42] << endl;
   1.267 +
   1.268 +  }
   1.269  }