COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/klao/iter_map_test.cc @ 392:b8d635e1672d

Last change on this file since 392:b8d635e1672d was 367:825647d4eca7, checked in by Mihaly Barasz, 20 years ago

Remove function and some todos.

File size: 5.4 KB
RevLine 
[347]1#include <iter_map.h>
2#include <maps.h>
3
4#include <iostream>
5
6using namespace hugo;
7using namespace std;
8
9const int N = 3;
10
11typedef StdMap<int,int> BaseMap;
12typedef IterableMap<BaseMap, N> TestMap;
[361]13typedef IterableBoolMap<BaseMap> TestBoolMap;
[347]14
15
[361]16template<typename TM>
17void print(TM const& m, int N = 3) {
[347]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 << "    ";
[361]22    for(typename TM::iterator j = m.begin(i); j!=m.end(i); ++j) {
[347]23      cout << " " << *j;
24    }
25    cout << endl;
26  }
27}
28
[366]29struct Int {
30  int a;
31
32  Int(int b = 5) : a(b) {}
33  Int(Invalid) : a(-1) {}
34
35  operator int() const { return a; }
36
37  bool valid() { return a != -1; }
38};
39
40typedef StdMap<Int,int> BaseMap2;
41typedef IterableBoolMap<BaseMap2> TestBoolMap2;
42
43
[347]44int main() {
45
[361]46  {
47    BaseMap base(344);
48    TestMap test(base);
[347]49
50
[361]51    print(test);
[347]52
[361]53    cout << "Inserting 12 to class 2...\n";
54    test.insert(12,2);
55    print(test);
[347]56
57
[361]58    cout << "Inserting 22 to class 2...\n";
59    test.insert(22,2);
60    print(test);
[347]61
[361]62    cout << "Testing some map values:\n";
63    cout << " 12: " << int(test[12]) << endl;
[347]64
[361]65    cout << "Inserting 10 to class 0...\n";
66    test.insert(10,0);
67    print(test);
[347]68
[361]69    cout << "Testing some map values:\n";
70    cout << " 12: " << int(test[12]) << endl;
[347]71
[361]72    cout << "Inserting 11 to class 1...\n";
73    test.insert(11,1);
74    print(test);
[347]75
[361]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 << " 11: " << int(test[11]) << endl;
81    cout << " 42: " << int(test[42]) << endl;
[347]82
[361]83    cout << "Inserting 21 to class 1...\n";
84    test.insert(21,1);
85    print(test);
[347]86
[361]87    cout << "Inserting 20 to class 1...\n";
88    test.insert(20,0);
89    print(test);
[347]90
[361]91    cout << "Testing some map values:\n";
92    cout << " 12: " << int(test[12]) << endl;
93    cout << " 22: " << int(test[22]) << endl;
94    cout << " 10: " << int(test[10]) << endl;
95    cout << " 20: " << int(test[20]) << endl;
96    cout << " 11: " << int(test[11]) << endl;
97    cout << " 21: " << int(test[21]) << endl;
98    cout << " 42: " << int(test[42]) << endl;
[347]99
[361]100    cout << "Setting 20 to class 2...\n";
101    test.set(20,2);
102    print(test);
[347]103 
[361]104    cout << "Setting 10 to class 1...\n";
105    test.set(10,1);
106    print(test);
[347]107 
[361]108    cout << "Setting 11 to class 1...\n";
109    test.set(11,1);
110    print(test);
[347]111 
[361]112    cout << "Setting 12 to class 1...\n";
113    test.set(12,1);
114    print(test);
[347]115 
[361]116    cout << "Setting 21 to class 2...\n";
117    test.set(21,2);
118    print(test);
[347]119 
[361]120    cout << "Setting 22 to class 2...\n";
121    test.set(22,2);
122    print(test);
[347]123 
[361]124    cout << "Testing some map values:\n";
125    cout << " 12: " << int(test[12]) << endl;
126    cout << " 22: " << int(test[22]) << endl;
127    cout << " 10: " << int(test[10]) << endl;
128    cout << " 20: " << int(test[20]) << endl;
129    cout << " 11: " << int(test[11]) << endl;
130    cout << " 21: " << int(test[21]) << endl;
131    cout << " 42: " << int(test[42]) << endl;
132  }
[347]133
[361]134  {
[362]135    cout << "\n\n\nTesting the IterableBoolMap...\n";
[361]136
137    BaseMap base(344);
[362]138    TestBoolMap test(base,true);
[361]139
140
141    print(test,2);
142
143    cout << "Inserting 12 to class true...\n";
144    test.insert(12,true);
145    print(test,2);
146
147
148    cout << "Inserting 22 to class true...\n";
149    test.insert(22,true);
150    print(test,2);
151
152    cout << "Testing some map values:\n";
153    cout << " 12: " << test[12] << endl;
154
155    cout << "Inserting 10 to class false...\n";
156    test.insert(10,false);
157    print(test,2);
158
159    cout << "Testing some map values:\n";
160    cout << " 12: " << test[12] << endl;
161
162    cout << "Inserting 11 to class false...\n";
163    test.insert(11,false);
164    print(test,2);
165
166    cout << "Testing some map values:\n";
167    cout << " 12: " << test[12] << endl;
168    cout << " 22: " << test[22] << endl;
169    cout << " 10: " << test[10] << endl;
170    cout << " 11: " << test[11] << endl;
171    cout << " 42: " << test[42] << endl;
172
[362]173    cout << "Setting 10 to class true...\n";
174    test.set(10,true);
[361]175    print(test,2);
176 
[362]177    cout << "Setting 11 to class true...\n";
[361]178    test.set(11,1);
179    print(test,2);
180 
[362]181    cout << "Setting 12 to class false...\n";
182    test.set(12,false);
[361]183    print(test,2);
184 
[362]185    cout << "Setting 22 to class false...\n";
186    test.set(22,false);
[361]187    print(test,2);
188 
189    cout << "Testing some map values:\n";
190    cout << " 12: " << test[12] << endl;
191    cout << " 22: " << test[22] << endl;
192    cout << " 10: " << test[10] << endl;
193    cout << " 11: " << test[11] << endl;
194    cout << " 42: " << test[42] << endl;
195
196  }
[366]197
198  {
199    cout << "\n\n\nTest a masikfele iteralasra:\n";
200
201    BaseMap2 base(344);
202    TestBoolMap2 test(base,false);
203
204    cout << "Inserting 12 to class true...\n";
205    test.insert(12,true);
206    print(test,2);
207
208    cout << "Inserting 22 to class true...\n";
209    test.insert(22,true);
210    print(test,2);
211
212    cout << "Inserting 10 to class false...\n";
213    test.insert(10,false);
214    print(test,2);
215
216    cout << "Testing some map values:\n";
217    cout << " 12: " << test[12] << endl;
218    cout << " 22: " << test[22] << endl;
219    cout << " 10: " << test[10] << endl;
220    cout << " 42: " << test[42] << endl;
221
222    cout << "The elements of the \"true\" class: ";
223    Int a;
224    for(test.first(a, true); a.valid(); test.next(a)) {
225      cout << " " << a;
226    }
227    cout << endl;
[367]228
229    cout << "Removing 10 from the map...\n";
230    test.remove(10);
231    print(test,2);
[366]232  }
[347]233}
Note: See TracBrowser for help on using the repository browser.