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)
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@103
     2
 *
alpar@209
     3
 * This file is a part of LEMON, a generic C++ optimization library.
alpar@103
     4
 *
alpar@440
     5
 * Copyright (C) 2003-2009
alpar@103
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@103
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@103
     8
 *
alpar@103
     9
 * Permission to use, modify and distribute this software is granted
alpar@103
    10
 * provided that this copyright notice appears in all copies. For
alpar@103
    11
 * precise terms see the accompanying LICENSE file.
alpar@103
    12
 *
alpar@103
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@103
    14
 * express or implied, and with no claim as to its suitability for any
alpar@103
    15
 * purpose.
alpar@103
    16
 *
alpar@103
    17
 */
alpar@103
    18
alpar@105
    19
#include <lemon/list_graph.h>
alpar@103
    20
#include <lemon/maps.h>
alpar@103
    21
#include <lemon/unionfind.h>
alpar@103
    22
#include "test_tools.h"
alpar@103
    23
alpar@103
    24
using namespace lemon;
alpar@103
    25
using namespace std;
alpar@103
    26
alpar@105
    27
typedef UnionFindEnum<ListGraph::NodeMap<int> > UFE;
alpar@103
    28
alpar@103
    29
int main() {
alpar@105
    30
  ListGraph g;
alpar@105
    31
  ListGraph::NodeMap<int> base(g);
alpar@103
    32
  UFE U(base);
alpar@105
    33
  vector<ListGraph::Node> n;
alpar@209
    34
alpar@105
    35
  for(int i=0;i<20;i++) n.push_back(g.addNode());
alpar@103
    36
alpar@105
    37
  U.insert(n[1]);
alpar@105
    38
  U.insert(n[2]);
alpar@103
    39
kpeter@171
    40
  check(U.join(n[1],n[2]) != -1, "Something is wrong with UnionFindEnum");
alpar@103
    41
alpar@105
    42
  U.insert(n[3]);
alpar@105
    43
  U.insert(n[4]);
alpar@105
    44
  U.insert(n[5]);
alpar@105
    45
  U.insert(n[6]);
alpar@105
    46
  U.insert(n[7]);
alpar@103
    47
alpar@103
    48
kpeter@171
    49
  check(U.join(n[1],n[4]) != -1, "Something is wrong with UnionFindEnum");
kpeter@171
    50
  check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum");
kpeter@171
    51
  check(U.join(n[3],n[5]) != -1, "Something is wrong with UnionFindEnum");
alpar@103
    52
alpar@103
    53
alpar@105
    54
  U.insert(n[8],U.find(n[5]));
alpar@103
    55
alpar@103
    56
kpeter@171
    57
  check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum");
kpeter@171
    58
  check(U.size(U.find(n[5])) == 3, "Something is wrong with UnionFindEnum");
kpeter@171
    59
  check(U.size(U.find(n[6])) == 1, "Something is wrong with UnionFindEnum");
kpeter@171
    60
  check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum");
alpar@103
    61
alpar@103
    62
alpar@105
    63
  U.insert(n[9]);
alpar@105
    64
  U.insert(n[10],U.find(n[9]));
alpar@103
    65
alpar@103
    66
kpeter@171
    67
  check(U.join(n[8],n[10])  != -1, "Something is wrong with UnionFindEnum");
alpar@103
    68
alpar@103
    69
kpeter@171
    70
  check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum");
kpeter@171
    71
  check(U.size(U.find(n[9])) == 5, "Something is wrong with UnionFindEnum");
alpar@103
    72
kpeter@171
    73
  check(U.size(U.find(n[8])) == 5, "Something is wrong with UnionFindEnum");
alpar@103
    74
alpar@105
    75
  U.erase(n[9]);
alpar@105
    76
  U.erase(n[1]);
alpar@103
    77
kpeter@171
    78
  check(U.size(U.find(n[10])) == 4, "Something is wrong with UnionFindEnum");
kpeter@171
    79
  check(U.size(U.find(n[2]))  == 2, "Something is wrong with UnionFindEnum");
alpar@103
    80
alpar@105
    81
  U.erase(n[6]);
alpar@105
    82
  U.split(U.find(n[8]));
alpar@103
    83
alpar@103
    84
kpeter@171
    85
  check(U.size(U.find(n[4])) == 2, "Something is wrong with UnionFindEnum");
kpeter@171
    86
  check(U.size(U.find(n[3])) == 1, "Something is wrong with UnionFindEnum");
kpeter@171
    87
  check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum");
alpar@103
    88
alpar@103
    89
kpeter@171
    90
  check(U.join(n[3],n[4]) != -1, "Something is wrong with UnionFindEnum");
kpeter@171
    91
  check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum");
alpar@103
    92
alpar@103
    93
kpeter@171
    94
  check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum");
kpeter@171
    95
  check(U.size(U.find(n[3])) == 3, "Something is wrong with UnionFindEnum");
kpeter@171
    96
  check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum");
alpar@103
    97
alpar@105
    98
  U.eraseClass(U.find(n[4]));
alpar@105
    99
  U.eraseClass(U.find(n[7]));
alpar@103
   100
alpar@103
   101
  return 0;
alpar@103
   102
}