COIN-OR::LEMON - Graph Library

source: lemon-main/test/unionfind_test.cc @ 395:0c5dd7ceda03

Last change on this file since 395:0c5dd7ceda03 was 209:765619b7cbb2, checked in by Alpar Juttner <alpar@…>, 16 years ago

Apply unify-sources.sh to the source tree

File size: 3.0 KB
RevLine 
[209]1/* -*- mode: C++; indent-tabs-mode: nil; -*-
[103]2 *
[209]3 * This file is a part of LEMON, a generic C++ optimization library.
[103]4 *
5 * Copyright (C) 2003-2008
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
[105]19#include <lemon/list_graph.h>
[103]20#include <lemon/maps.h>
21#include <lemon/unionfind.h>
22#include "test_tools.h"
23
24using namespace lemon;
25using namespace std;
26
[105]27typedef UnionFindEnum<ListGraph::NodeMap<int> > UFE;
[103]28
29int main() {
[105]30  ListGraph g;
31  ListGraph::NodeMap<int> base(g);
[103]32  UFE U(base);
[105]33  vector<ListGraph::Node> n;
[209]34
[105]35  for(int i=0;i<20;i++) n.push_back(g.addNode());
[103]36
[105]37  U.insert(n[1]);
38  U.insert(n[2]);
[103]39
[171]40  check(U.join(n[1],n[2]) != -1, "Something is wrong with UnionFindEnum");
[103]41
[105]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]);
[103]47
48
[171]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");
[103]52
53
[105]54  U.insert(n[8],U.find(n[5]));
[103]55
56
[171]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");
[103]61
62
[105]63  U.insert(n[9]);
64  U.insert(n[10],U.find(n[9]));
[103]65
66
[171]67  check(U.join(n[8],n[10])  != -1, "Something is wrong with UnionFindEnum");
[103]68
69
[171]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");
[103]72
[171]73  check(U.size(U.find(n[8])) == 5, "Something is wrong with UnionFindEnum");
[103]74
[105]75  U.erase(n[9]);
76  U.erase(n[1]);
[103]77
[171]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");
[103]80
[105]81  U.erase(n[6]);
82  U.split(U.find(n[8]));
[103]83
84
[171]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");
[103]88
89
[171]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");
[103]92
93
[171]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");
[103]97
[105]98  U.eraseClass(U.find(n[4]));
99  U.eraseClass(U.find(n[7]));
[103]100
101  return 0;
102}
Note: See TracBrowser for help on using the repository browser.