1.1 --- a/src/work/klao/iter_map_test.cc Sun Apr 17 18:57:22 2005 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,233 +0,0 @@
1.4 -#include <iter_map.h>
1.5 -#include <lemon/maps.h>
1.6 -
1.7 -#include <iostream>
1.8 -
1.9 -using namespace lemon;
1.10 -using namespace std;
1.11 -
1.12 -const int N = 3;
1.13 -
1.14 -typedef StdMap<int,int> BaseMap;
1.15 -typedef IterableMap<BaseMap, N> TestMap;
1.16 -typedef IterableBoolMap<BaseMap> TestBoolMap;
1.17 -
1.18 -
1.19 -template<typename TM>
1.20 -void print(TM const& m, int N = 3) {
1.21 - cout << "Size of the map: " << m.size() << endl;
1.22 - for(int i=0; i<N; ++i) {
1.23 - cout << " Class " << i << ". (size=" << m.size(i) << "): " << flush;
1.24 - cout << " ";
1.25 - for(typename TM::iterator j = m.begin(i); j!=m.end(i); ++j) {
1.26 - cout << " " << *j;
1.27 - }
1.28 - cout << endl;
1.29 - }
1.30 -}
1.31 -
1.32 -struct Int {
1.33 - int a;
1.34 -
1.35 - Int(int b = 5) : a(b) {}
1.36 - Int(Invalid) : a(-1) {}
1.37 -
1.38 - operator int() const { return a; }
1.39 -
1.40 - bool valid() { return a != -1; }
1.41 -};
1.42 -
1.43 -typedef StdMap<Int,int> BaseMap2;
1.44 -typedef IterableBoolMap<BaseMap2> TestBoolMap2;
1.45 -
1.46 -
1.47 -int main() {
1.48 -
1.49 - {
1.50 - BaseMap base(344);
1.51 - TestMap test(base);
1.52 -
1.53 -
1.54 - print(test);
1.55 -
1.56 - cout << "Inserting 12 to class 2...\n";
1.57 - test.insert(12,2);
1.58 - print(test);
1.59 -
1.60 -
1.61 - cout << "Inserting 22 to class 2...\n";
1.62 - test.insert(22,2);
1.63 - print(test);
1.64 -
1.65 - cout << "Testing some map values:\n";
1.66 - cout << " 12: " << int(test[12]) << endl;
1.67 -
1.68 - cout << "Inserting 10 to class 0...\n";
1.69 - test.insert(10,0);
1.70 - print(test);
1.71 -
1.72 - cout << "Testing some map values:\n";
1.73 - cout << " 12: " << int(test[12]) << endl;
1.74 -
1.75 - cout << "Inserting 11 to class 1...\n";
1.76 - test.insert(11,1);
1.77 - print(test);
1.78 -
1.79 - cout << "Testing some map values:\n";
1.80 - cout << " 12: " << int(test[12]) << endl;
1.81 - cout << " 22: " << int(test[22]) << endl;
1.82 - cout << " 10: " << int(test[10]) << endl;
1.83 - cout << " 11: " << int(test[11]) << endl;
1.84 - cout << " 42: " << int(test[42]) << endl;
1.85 -
1.86 - cout << "Inserting 21 to class 1...\n";
1.87 - test.insert(21,1);
1.88 - print(test);
1.89 -
1.90 - cout << "Inserting 20 to class 1...\n";
1.91 - test.insert(20,0);
1.92 - print(test);
1.93 -
1.94 - cout << "Testing some map values:\n";
1.95 - cout << " 12: " << int(test[12]) << endl;
1.96 - cout << " 22: " << int(test[22]) << endl;
1.97 - cout << " 10: " << int(test[10]) << endl;
1.98 - cout << " 20: " << int(test[20]) << endl;
1.99 - cout << " 11: " << int(test[11]) << endl;
1.100 - cout << " 21: " << int(test[21]) << endl;
1.101 - cout << " 42: " << int(test[42]) << endl;
1.102 -
1.103 - cout << "Setting 20 to class 2...\n";
1.104 - test.set(20,2);
1.105 - print(test);
1.106 -
1.107 - cout << "Setting 10 to class 1...\n";
1.108 - test.set(10,1);
1.109 - print(test);
1.110 -
1.111 - cout << "Setting 11 to class 1...\n";
1.112 - test.set(11,1);
1.113 - print(test);
1.114 -
1.115 - cout << "Setting 12 to class 1...\n";
1.116 - test.set(12,1);
1.117 - print(test);
1.118 -
1.119 - cout << "Setting 21 to class 2...\n";
1.120 - test.set(21,2);
1.121 - print(test);
1.122 -
1.123 - cout << "Setting 22 to class 2...\n";
1.124 - test.set(22,2);
1.125 - print(test);
1.126 -
1.127 - cout << "Testing some map values:\n";
1.128 - cout << " 12: " << int(test[12]) << endl;
1.129 - cout << " 22: " << int(test[22]) << endl;
1.130 - cout << " 10: " << int(test[10]) << endl;
1.131 - cout << " 20: " << int(test[20]) << endl;
1.132 - cout << " 11: " << int(test[11]) << endl;
1.133 - cout << " 21: " << int(test[21]) << endl;
1.134 - cout << " 42: " << int(test[42]) << endl;
1.135 - }
1.136 -
1.137 - {
1.138 - cout << "\n\n\nTesting the IterableBoolMap...\n";
1.139 -
1.140 - BaseMap base(344);
1.141 - TestBoolMap test(base,true);
1.142 -
1.143 -
1.144 - print(test,2);
1.145 -
1.146 - cout << "Inserting 12 to class true...\n";
1.147 - test.insert(12,true);
1.148 - print(test,2);
1.149 -
1.150 -
1.151 - cout << "Inserting 22 to class true...\n";
1.152 - test.insert(22,true);
1.153 - print(test,2);
1.154 -
1.155 - cout << "Testing some map values:\n";
1.156 - cout << " 12: " << test[12] << endl;
1.157 -
1.158 - cout << "Inserting 10 to class false...\n";
1.159 - test.insert(10,false);
1.160 - print(test,2);
1.161 -
1.162 - cout << "Testing some map values:\n";
1.163 - cout << " 12: " << test[12] << endl;
1.164 -
1.165 - cout << "Inserting 11 to class false...\n";
1.166 - test.insert(11,false);
1.167 - print(test,2);
1.168 -
1.169 - cout << "Testing some map values:\n";
1.170 - cout << " 12: " << test[12] << endl;
1.171 - cout << " 22: " << test[22] << endl;
1.172 - cout << " 10: " << test[10] << endl;
1.173 - cout << " 11: " << test[11] << endl;
1.174 - cout << " 42: " << test[42] << endl;
1.175 -
1.176 - cout << "Setting 10 to class true...\n";
1.177 - test.set(10,true);
1.178 - print(test,2);
1.179 -
1.180 - cout << "Setting 11 to class true...\n";
1.181 - test.set(11,1);
1.182 - print(test,2);
1.183 -
1.184 - cout << "Setting 12 to class false...\n";
1.185 - test.set(12,false);
1.186 - print(test,2);
1.187 -
1.188 - cout << "Setting 22 to class false...\n";
1.189 - test.set(22,false);
1.190 - print(test,2);
1.191 -
1.192 - cout << "Testing some map values:\n";
1.193 - cout << " 12: " << test[12] << endl;
1.194 - cout << " 22: " << test[22] << endl;
1.195 - cout << " 10: " << test[10] << endl;
1.196 - cout << " 11: " << test[11] << endl;
1.197 - cout << " 42: " << test[42] << endl;
1.198 -
1.199 - }
1.200 -
1.201 - {
1.202 - cout << "\n\n\nTest a masikfele iteralasra:\n";
1.203 -
1.204 - BaseMap2 base(344);
1.205 - TestBoolMap2 test(base,false);
1.206 -
1.207 - cout << "Inserting 12 to class true...\n";
1.208 - test.insert(12,true);
1.209 - print(test,2);
1.210 -
1.211 - cout << "Inserting 22 to class true...\n";
1.212 - test.insert(22,true);
1.213 - print(test,2);
1.214 -
1.215 - cout << "Inserting 10 to class false...\n";
1.216 - test.insert(10,false);
1.217 - print(test,2);
1.218 -
1.219 - cout << "Testing some map values:\n";
1.220 - cout << " 12: " << test[12] << endl;
1.221 - cout << " 22: " << test[22] << endl;
1.222 - cout << " 10: " << test[10] << endl;
1.223 - cout << " 42: " << test[42] << endl;
1.224 -
1.225 - cout << "The elements of the \"true\" class: ";
1.226 - Int a;
1.227 - for(test.first(a, true); a.valid(); test.next(a)) {
1.228 - cout << " " << a;
1.229 - }
1.230 - cout << endl;
1.231 -
1.232 - cout << "Removing 10 from the map...\n";
1.233 - test.remove(10);
1.234 - print(test,2);
1.235 - }
1.236 -}