test/unionfind_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 25 Aug 2010 21:34:58 +0200
changeset 742 16d466589b54
parent 209 765619b7cbb2
permissions -rw-r--r--
Backport the CMAKE related changesets from the main branch

[e20fecd1945f] Add check target for CMake (#388)
[e74b5db4f2c6] Put the output of chg-len.py in the version string (#389)
[7d166b8b8018] Safer call of ./scripts/chg-len.py on Windows (#389)
[659ba4805a48] Make CMAKE config more consistent with configure.ac (#390)
[63e4468c680e] Add 'Maintainer' CMAKE build type (#388, #390)
[a725503acfe9] Allow CPACK configuration on all platforms
[10242c611190] Create and install lemon.pc (#393)
[48e29534cf03] The deafult target doesn't build lp_test and mip_test (#388)
[0fbbdd578c06] Full path for DoxygenLayout.xml in Doxyfile.in (#395)
[481496e6d71f] SOURCE_BROWSER Doxygen switch is configurable from CMAKE (#395)
[09282720100b] update-external-tags CMAKE target (#395)
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     5  * Copyright (C) 2003-2009
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #include <lemon/list_graph.h>
    20 #include <lemon/maps.h>
    21 #include <lemon/unionfind.h>
    22 #include "test_tools.h"
    23 
    24 using namespace lemon;
    25 using namespace std;
    26 
    27 typedef UnionFindEnum<ListGraph::NodeMap<int> > UFE;
    28 
    29 int main() {
    30   ListGraph g;
    31   ListGraph::NodeMap<int> base(g);
    32   UFE U(base);
    33   vector<ListGraph::Node> n;
    34 
    35   for(int i=0;i<20;i++) n.push_back(g.addNode());
    36 
    37   U.insert(n[1]);
    38   U.insert(n[2]);
    39 
    40   check(U.join(n[1],n[2]) != -1, "Something is wrong with UnionFindEnum");
    41 
    42   U.insert(n[3]);
    43   U.insert(n[4]);
    44   U.insert(n[5]);
    45   U.insert(n[6]);
    46   U.insert(n[7]);
    47 
    48 
    49   check(U.join(n[1],n[4]) != -1, "Something is wrong with UnionFindEnum");
    50   check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum");
    51   check(U.join(n[3],n[5]) != -1, "Something is wrong with UnionFindEnum");
    52 
    53 
    54   U.insert(n[8],U.find(n[5]));
    55 
    56 
    57   check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum");
    58   check(U.size(U.find(n[5])) == 3, "Something is wrong with UnionFindEnum");
    59   check(U.size(U.find(n[6])) == 1, "Something is wrong with UnionFindEnum");
    60   check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum");
    61 
    62 
    63   U.insert(n[9]);
    64   U.insert(n[10],U.find(n[9]));
    65 
    66 
    67   check(U.join(n[8],n[10])  != -1, "Something is wrong with UnionFindEnum");
    68 
    69 
    70   check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum");
    71   check(U.size(U.find(n[9])) == 5, "Something is wrong with UnionFindEnum");
    72 
    73   check(U.size(U.find(n[8])) == 5, "Something is wrong with UnionFindEnum");
    74 
    75   U.erase(n[9]);
    76   U.erase(n[1]);
    77 
    78   check(U.size(U.find(n[10])) == 4, "Something is wrong with UnionFindEnum");
    79   check(U.size(U.find(n[2]))  == 2, "Something is wrong with UnionFindEnum");
    80 
    81   U.erase(n[6]);
    82   U.split(U.find(n[8]));
    83 
    84 
    85   check(U.size(U.find(n[4])) == 2, "Something is wrong with UnionFindEnum");
    86   check(U.size(U.find(n[3])) == 1, "Something is wrong with UnionFindEnum");
    87   check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum");
    88 
    89 
    90   check(U.join(n[3],n[4]) != -1, "Something is wrong with UnionFindEnum");
    91   check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum");
    92 
    93 
    94   check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum");
    95   check(U.size(U.find(n[3])) == 3, "Something is wrong with UnionFindEnum");
    96   check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum");
    97 
    98   U.eraseClass(U.find(n[4]));
    99   U.eraseClass(U.find(n[7]));
   100 
   101   return 0;
   102 }