2 * test/unionfind_test.cc - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
19 #include <lemon/maps.h>
20 #include <lemon/unionfind.h>
21 #include "test_tools.h"
23 using namespace lemon;
27 class BaseMap : public StdMap<int,T> {};
29 typedef UnionFindEnum<int, BaseMap> UFE;
31 void print(UFE const &ufe) {
33 cout << "Print the classes of the structure:" << endl;
35 for (ufe.first(cit); ufe.valid(cit); ufe.next(cit)) {
36 cout << " " << i << " (" << cit << "):" << flush;
38 for (ufe.first(iit, cit); ufe.valid(iit); ufe.next(iit)) {
39 cout << " " << iit << flush;
44 cout << "done" << endl;
55 check(U.join(1,2),"Test failed.");
63 check(U.join(1,4),"Test failed.");
64 check(!U.join(2,4),"Test failed.");
65 check(U.join(3,5),"Test failed.");
69 check(U.size(4) == 3,"Test failed.");
70 check(U.size(5) == 3,"Test failed.");
71 check(U.size(6) == 1,"Test failed.");
72 check(U.size(2) == 3,"Test failed.");
76 check(U.join(8,10),"Test failed.");
78 check(U.move(9,4),"Test failed.");
79 check(!U.move(9,2),"Test failed.");
81 check(U.size(4) == 4,"Test failed.");
82 check(U.size(9) == 4,"Test failed.");
84 check(U.move(5,6),"Test failed.");
86 check(U.size(5) == 2,"Test failed.");
87 check(U.size(8) == 3,"Test failed.");
89 check(U.move(7,10),"Test failed.");
90 check(U.size(7) == 4,"Test failed.");
95 check(U.size(4) == 2,"Test failed.");
96 check(U.size(2) == 2,"Test failed.");
102 check(U.size(4) == 2,"Test failed.");
103 check(U.size(3) == 1,"Test failed.");
104 check(U.size(2) == 2,"Test failed.");
106 check(U.join(3,4),"Test failed.");
107 check(!U.join(2,4),"Test failed.");
109 check(U.size(4) == 3,"Test failed.");
110 check(U.size(3) == 3,"Test failed.");
111 check(U.size(2) == 3,"Test failed.");
117 check(U.size(4) == 3,"Test failed.");
118 check(U.size(3) == 3,"Test failed.");
119 check(U.size(2) == 3,"Test failed.");