Changeset 774:4297098d9677 in lemon-0.x for src/test/unionfind_test.cc
- Timestamp:
- 08/30/04 14:01:47 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1066
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/test/unionfind_test.cc
r542 r774 3 3 #include <hugo/maps.h> 4 4 #include <hugo/unionfind.h> 5 #include "test_tools.h" 5 6 6 7 using namespace hugo; 7 8 using namespace std; 8 9 bool passed = true;10 11 void check(bool rc) {12 passed = passed && rc;13 if(!rc) {14 cout << "Test failed!" << endl;15 }16 }17 9 18 10 template <typename T> … … 23 15 void print(UFE const &ufe) { 24 16 UFE::ClassIt cit; 25 cout << " printingthe classes of the structure:" << endl;17 cout << "Print the classes of the structure:" << endl; 26 18 int i = 1; 27 19 for (ufe.first(cit); ufe.valid(cit); ufe.next(cit)) { … … 42 34 UFE U(base); 43 35 44 print(U);36 // print(U); 45 37 46 cout << "Insert ing1..." << endl;38 cout << "Insert 1..." << endl; 47 39 U.insert(1); 48 print(U);40 // print(U); 49 41 50 cout << "Insert ing2..." << endl;42 cout << "Insert 2..." << endl; 51 43 U.insert(2); 52 print(U);44 // print(U); 53 45 54 cout << "Join ing1 and 2..." << endl;55 check(U.join(1,2) );56 print(U);46 cout << "Join 1 and 2..." << endl; 47 check(U.join(1,2),"Test failed."); 48 // print(U); 57 49 58 cout << "Insert ing3, 4, 5, 6, 7..." << endl;50 cout << "Insert 3, 4, 5, 6, 7..." << endl; 59 51 U.insert(3); 60 52 U.insert(4); … … 62 54 U.insert(6); 63 55 U.insert(7); 64 print (U);56 // print (U); 65 57 66 cout << "Join ing1 - 4, 2 - 4 and 3 - 5 ..." << endl;67 check(U.join(1,4) );68 check(!U.join(2,4) );69 check(U.join(3,5) );70 print(U);58 cout << "Join 1 - 4, 2 - 4 and 3 - 5 ..." << endl; 59 check(U.join(1,4),"Test failed."); 60 check(!U.join(2,4),"Test failed."); 61 check(U.join(3,5),"Test failed."); 62 // print(U); 71 63 72 cout << "Insert ing8 to the component of 5 ..." << endl;64 cout << "Insert 8 to the component of 5 ..." << endl; 73 65 U.insert(8,5); 74 print(U);66 // print(U); 75 67 76 cout << " size of the class of 4: " << U.size(4) << endl;77 check(U.size(4) == 3 );78 cout << " size of the class of 5: " << U.size(5) << endl;79 check(U.size(5) == 3 );80 cout << " size of the class of 6: " << U.size(6) << endl;81 check(U.size(6) == 1 );82 cout << " size of the class of 2: " << U.size(2) << endl;83 check(U.size(2) == 3 );68 cout << "Size of the class of 4: " << U.size(4) << endl; 69 check(U.size(4) == 3,"Test failed."); 70 cout << "Size of the class of 5: " << U.size(5) << endl; 71 check(U.size(5) == 3,"Test failed."); 72 cout << "Size of the class of 6: " << U.size(6) << endl; 73 check(U.size(6) == 1,"Test failed."); 74 cout << "Size of the class of 2: " << U.size(2) << endl; 75 check(U.size(2) == 3,"Test failed."); 84 76 85 cout << "Insert ing9 ..." << endl;77 cout << "Insert 9 ..." << endl; 86 78 U.insert(9); 87 print(U);88 cout << "Insert ing10 to the component of 9 ..." << endl;79 // print(U); 80 cout << "Insert 10 to the component of 9 ..." << endl; 89 81 U.insert(10,9); 90 print(U);82 // print(U); 91 83 92 cout << "Join ing8 and 10..." << endl;93 check(U.join(8,10) );94 print(U);84 cout << "Join 8 and 10..." << endl; 85 check(U.join(8,10),"Test failed."); 86 // print(U); 95 87 96 88 cout << "Move 9 to the class of 4 ..." << endl; 97 check(U.move(9,4) );98 print(U);89 check(U.move(9,4),"Test failed."); 90 // print(U); 99 91 100 92 cout << "Move 9 to the class of 2 ..." << endl; 101 check(!U.move(9,2) );102 print(U);93 check(!U.move(9,2),"Test failed."); 94 // print(U); 103 95 104 cout << " size of the class of 4: " << U.size(4) << endl;105 check(U.size(4) == 4 );106 cout << " size of the class of 9: " << U.size(9) << endl;107 check(U.size(9) == 4 );96 cout << "Size of the class of 4: " << U.size(4) << endl; 97 check(U.size(4) == 4,"Test failed."); 98 cout << "Size of the class of 9: " << U.size(9) << endl; 99 check(U.size(9) == 4,"Test failed."); 108 100 109 101 cout << "Move 5 to the class of 6 ..." << endl; 110 check(U.move(5,6) );111 print(U);102 check(U.move(5,6),"Test failed."); 103 // print(U); 112 104 113 cout << " size of the class of 5: " << U.size(5) << endl;114 check(U.size(5) == 2 );115 cout << " size of the class of 8: " << U.size(8) << endl;116 check(U.size(8) == 3 );105 cout << "Size of the class of 5: " << U.size(5) << endl; 106 check(U.size(5) == 2,"Test failed."); 107 cout << "Size of the class of 8: " << U.size(8) << endl; 108 check(U.size(8) == 3,"Test failed."); 117 109 118 110 cout << "Move 7 to the class of 10 ..." << endl; 119 check(U.move(7,10) );120 print(U);111 check(U.move(7,10),"Test failed."); 112 // print(U); 121 113 122 cout << " size of the class of 7: " << U.size(7) << endl;123 check(U.size(7) == 4 );114 cout << "Size of the class of 7: " << U.size(7) << endl; 115 check(U.size(7) == 4,"Test failed."); 124 116 125 cout <<" erase 9:" << endl;117 cout <<"Erase 9... " << endl; 126 118 U.erase(9); 127 print(U);119 // print(U); 128 120 129 cout <<" erase 1:" << endl;121 cout <<"Erase 1... " << endl; 130 122 U.erase(1); 131 print(U);123 // print(U); 132 124 133 cout << " size of the class of 4: " << U.size(4) << endl;134 check(U.size(4) == 2 );135 cout << " size of the class of 2: " << U.size(2) << endl;136 check(U.size(2) == 2 );125 cout << "Size of the class of 4: " << U.size(4) << endl; 126 check(U.size(4) == 2,"Test failed."); 127 cout << "Size of the class of 2: " << U.size(2) << endl; 128 check(U.size(2) == 2,"Test failed."); 137 129 138 130 139 cout <<" erase 1:" << endl;131 cout <<"Erase 1... " << endl; 140 132 U.erase(1); 141 print(U);133 // print(U); 142 134 143 cout <<" erase 6:" << endl;135 cout <<"Erase 6... " << endl; 144 136 U.erase(6); 145 print(U);137 // print(U); 146 138 147 cout << " split the class of 8:" << endl;139 cout << "Split the class of 8... " << endl; 148 140 U.split(8); 149 print(U);141 // print(U); 150 142 151 143 152 cout << " size of the class of 4: " << U.size(4) << endl;153 check(U.size(4) == 2 );154 cout << " size of the class of 3: " << U.size(3) << endl;155 check(U.size(3) == 1 );156 cout << " size of the class of 2: " << U.size(2) << endl;157 check(U.size(2) == 2 );144 cout << "Size of the class of 4: " << U.size(4) << endl; 145 check(U.size(4) == 2,"Test failed."); 146 cout << "Size of the class of 3: " << U.size(3) << endl; 147 check(U.size(3) == 1,"Test failed."); 148 cout << "Size of the class of 2: " << U.size(2) << endl; 149 check(U.size(2) == 2,"Test failed."); 158 150 159 151 160 cout << "Join ing3 - 4 and 2 - 4 ..." << endl;161 check(U.join(3,4) );162 check(!U.join(2,4) );163 print(U);152 cout << "Join 3 - 4 and 2 - 4 ..." << endl; 153 check(U.join(3,4),"Test failed."); 154 check(!U.join(2,4),"Test failed."); 155 // print(U); 164 156 165 157 166 cout << " size of the class of 4: " << U.size(4) << endl;167 check(U.size(4) == 3 );168 cout << " size of the class of 3: " << U.size(3) << endl;169 check(U.size(3) == 3 );170 cout << " size of the class of 2: " << U.size(2) << endl;171 check(U.size(2) == 3 );158 cout << "Size of the class of 4: " << U.size(4) << endl; 159 check(U.size(4) == 3,"Test failed."); 160 cout << "Size of the class of 3: " << U.size(3) << endl; 161 check(U.size(3) == 3,"Test failed."); 162 cout << "Size of the class of 2: " << U.size(2) << endl; 163 check(U.size(2) == 3,"Test failed."); 172 164 173 cout << "makeRep(4) " << endl;165 cout << "makeRep(4)..." << endl; 174 166 U.makeRep(4); 175 print(U);176 cout << "makeRep(3) " << endl;167 // print(U); 168 cout << "makeRep(3)..." << endl; 177 169 U.makeRep(3); 178 print(U);179 cout << "makeRep(2) " << endl;170 // print(U); 171 cout << "makeRep(2)..." << endl; 180 172 U.makeRep(2); 181 print(U);173 // print(U); 182 174 183 cout << " size of the class of 4: " << U.size(4) << endl;184 check(U.size(4) == 3 );185 cout << " size of the class of 3: " << U.size(3) << endl;186 check(U.size(3) == 3 );187 cout << " size of the class of 2: " << U.size(2) << endl;188 check(U.size(2) == 3 );175 cout << "Size of the class of 4: " << U.size(4) << endl; 176 check(U.size(4) == 3,"Test failed."); 177 cout << "Size of the class of 3: " << U.size(3) << endl; 178 check(U.size(3) == 3,"Test failed."); 179 cout << "Size of the class of 2: " << U.size(2) << endl; 180 check(U.size(2) == 3,"Test failed."); 189 181 190 182 191 183 cout << "eraseClass 4 ..." << endl; 192 184 U.eraseClass(4); 193 print(U);185 // print(U); 194 186 195 187 cout << "eraseClass 7 ..." << endl; 196 188 U.eraseClass(7); 197 print(U);189 // print(U); 198 190 199 cout << "done" << endl; 200 201 cout << (passed ? "All tests passed." : "Some of the tests failed!!!") 202 << endl; 203 204 return passed ? 0 : 1; 191 cout << "done." << endl; 205 192 }
Note: See TracChangeset
for help on using the changeset viewer.