/* -*- C++ -*- * test/unionfind_test.cc - Part of LEMON, a generic C++ optimization library * * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). * * Permission to use, modify and distribute this software is granted * provided that this copyright notice appears in all copies. For * precise terms see the accompanying LICENSE file. * * This software is provided "AS IS" with no warranty of any kind, * express or implied, and with no claim as to its suitability for any * purpose. * */ #include #include #include #include "test_tools.h" using namespace lemon; using namespace std; template class BaseMap : public StdMap {}; typedef UnionFindEnum UFE; void print(UFE const &ufe) { UFE::ClassIt cit; cout << "Print the classes of the structure:" << endl; int i = 1; for (ufe.first(cit); ufe.valid(cit); ufe.next(cit)) { cout << " " << i << " (" << cit << "):" << flush; UFE::ItemIt iit; for (ufe.first(iit, cit); ufe.valid(iit); ufe.next(iit)) { cout << " " << iit << flush; } cout << endl; i++; } cout << "done" << endl; } int main() { UFE::MapType base; UFE U(base); U.insert(1); U.insert(2); check(U.join(1,2),"Test failed."); U.insert(3); U.insert(4); U.insert(5); U.insert(6); U.insert(7); check(U.join(1,4),"Test failed."); check(!U.join(2,4),"Test failed."); check(U.join(3,5),"Test failed."); U.insert(8,5); check(U.size(4) == 3,"Test failed."); check(U.size(5) == 3,"Test failed."); check(U.size(6) == 1,"Test failed."); check(U.size(2) == 3,"Test failed."); U.insert(9); U.insert(10,9); check(U.join(8,10),"Test failed."); check(U.move(9,4),"Test failed."); check(!U.move(9,2),"Test failed."); check(U.size(4) == 4,"Test failed."); check(U.size(9) == 4,"Test failed."); check(U.move(5,6),"Test failed."); check(U.size(5) == 2,"Test failed."); check(U.size(8) == 3,"Test failed."); check(U.move(7,10),"Test failed."); check(U.size(7) == 4,"Test failed."); U.erase(9); U.erase(1); check(U.size(4) == 2,"Test failed."); check(U.size(2) == 2,"Test failed."); U.erase(1); U.erase(6); U.split(8); check(U.size(4) == 2,"Test failed."); check(U.size(3) == 1,"Test failed."); check(U.size(2) == 2,"Test failed."); check(U.join(3,4),"Test failed."); check(!U.join(2,4),"Test failed."); check(U.size(4) == 3,"Test failed."); check(U.size(3) == 3,"Test failed."); check(U.size(2) == 3,"Test failed."); U.makeRep(4); U.makeRep(3); U.makeRep(2); check(U.size(4) == 3,"Test failed."); check(U.size(3) == 3,"Test failed."); check(U.size(2) == 3,"Test failed."); U.eraseClass(4); U.eraseClass(7); }