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