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@105: #include 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@105: typedef UnionFindEnum > UFE; alpar@103: alpar@103: int main() { alpar@105: ListGraph g; alpar@105: ListGraph::NodeMap base(g); alpar@103: UFE U(base); alpar@105: vector n; alpar@105: alpar@105: for(int i=0;i<20;i++) n.push_back(g.addNode()); alpar@103: alpar@105: U.insert(n[1]); alpar@105: U.insert(n[2]); alpar@103: kpeter@171: check(U.join(n[1],n[2]) != -1, "Something is wrong with UnionFindEnum"); alpar@103: alpar@105: U.insert(n[3]); alpar@105: U.insert(n[4]); alpar@105: U.insert(n[5]); alpar@105: U.insert(n[6]); alpar@105: U.insert(n[7]); alpar@103: alpar@103: kpeter@171: check(U.join(n[1],n[4]) != -1, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.join(n[3],n[5]) != -1, "Something is wrong with UnionFindEnum"); alpar@103: alpar@103: alpar@105: U.insert(n[8],U.find(n[5])); alpar@103: alpar@103: kpeter@171: check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.size(U.find(n[5])) == 3, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.size(U.find(n[6])) == 1, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum"); alpar@103: alpar@103: alpar@105: U.insert(n[9]); alpar@105: U.insert(n[10],U.find(n[9])); alpar@103: alpar@103: kpeter@171: check(U.join(n[8],n[10]) != -1, "Something is wrong with UnionFindEnum"); alpar@103: alpar@103: kpeter@171: check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.size(U.find(n[9])) == 5, "Something is wrong with UnionFindEnum"); alpar@103: kpeter@171: check(U.size(U.find(n[8])) == 5, "Something is wrong with UnionFindEnum"); alpar@103: alpar@105: U.erase(n[9]); alpar@105: U.erase(n[1]); alpar@103: kpeter@171: check(U.size(U.find(n[10])) == 4, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum"); alpar@103: alpar@105: U.erase(n[6]); alpar@105: U.split(U.find(n[8])); alpar@103: alpar@103: kpeter@171: check(U.size(U.find(n[4])) == 2, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.size(U.find(n[3])) == 1, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum"); alpar@103: alpar@103: kpeter@171: check(U.join(n[3],n[4]) != -1, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum"); alpar@103: alpar@103: kpeter@171: check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.size(U.find(n[3])) == 3, "Something is wrong with UnionFindEnum"); kpeter@171: check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum"); alpar@103: alpar@105: U.eraseClass(U.find(n[4])); alpar@105: U.eraseClass(U.find(n[7])); alpar@103: alpar@103: return 0; alpar@103: }