COIN-OR::LEMON - Graph Library

source: lemon-main/test/unionfind_test.cc @ 193:65cba1032f90

Last change on this file since 193:65cba1032f90 was 171:02f4d5d9bfd7, checked in by Peter Kovacs <kpeter@…>, 16 years ago

Improve and redesign test programs + unify their output (ticket #25)

  • Move graph related utilities form test_tools.h to graph_test.h.
  • Move the contents of graph_utils_test.h to graph_utils_test.cc.
  • Rename map_test.h -> graph_maps_test.h.
  • Rename digraph_test.h -> graph_test.h.
  • Many improvements in the following files:
    • digraph_test.cc
    • graph_test.cc
    • graph_test.h
    • graph_maps_test.h
    • graph_utils_test.cc
    • bfs_test.cc
    • dfs_test.cc
    • counter_test.cc
  • Test programs print messages only if it really seems necessary.
  • Remove \file commands form .cc test files.
File size: 3.0 KB
RevLine 
[103]1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
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;
34 
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.