1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
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.
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
19 #include <lemon/concepts/digraph.h>
20 #include <lemon/list_graph.h>
21 #include <lemon/smart_graph.h>
22 #include <lemon/full_graph.h>
24 #include "test_tools.h"
25 #include "graph_test.h"
27 using namespace lemon;
28 using namespace lemon::concepts;
30 template <class Digraph>
32 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
35 checkGraphNodeList(G, 0);
36 checkGraphArcList(G, 0);
42 checkGraphNodeList(G, 3);
43 checkGraphArcList(G, 0);
45 Arc a1 = G.addArc(n1, n2);
46 check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc");
47 checkGraphNodeList(G, 3);
48 checkGraphArcList(G, 1);
50 checkGraphOutArcList(G, n1, 1);
51 checkGraphOutArcList(G, n2, 0);
52 checkGraphOutArcList(G, n3, 0);
54 checkGraphInArcList(G, n1, 0);
55 checkGraphInArcList(G, n2, 1);
56 checkGraphInArcList(G, n3, 0);
58 checkGraphConArcList(G, 1);
60 Arc a2 = G.addArc(n2, n1), a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
61 checkGraphNodeList(G, 3);
62 checkGraphArcList(G, 4);
64 checkGraphOutArcList(G, n1, 1);
65 checkGraphOutArcList(G, n2, 3);
66 checkGraphOutArcList(G, n3, 0);
68 checkGraphInArcList(G, n1, 1);
69 checkGraphInArcList(G, n2, 1);
70 checkGraphInArcList(G, n3, 2);
72 checkGraphConArcList(G, 4);
81 void checkFullDigraph(int num) {
82 typedef FullDigraph Digraph;
83 DIGRAPH_TYPEDEFS(Digraph);
86 checkGraphNodeList(G, num);
87 checkGraphArcList(G, num * num);
89 for (NodeIt n(G); n != INVALID; ++n) {
90 checkGraphOutArcList(G, n, num);
91 checkGraphInArcList(G, n, num);
94 checkGraphConArcList(G, num * num);
101 for (int i = 0; i < G.nodeNum(); ++i) {
102 check(G.index(G(i)) == i, "Wrong index");
105 for (NodeIt s(G); s != INVALID; ++s) {
106 for (NodeIt t(G); t != INVALID; ++t) {
108 check(G.source(a) == s && G.target(a) == t, "Wrong arc lookup");
114 void checkConcepts() {
115 { // Checking digraph components
116 checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
118 checkConcept<IDableDigraphComponent<>,
119 IDableDigraphComponent<> >();
121 checkConcept<IterableDigraphComponent<>,
122 IterableDigraphComponent<> >();
124 checkConcept<MappableDigraphComponent<>,
125 MappableDigraphComponent<> >();
127 { // Checking skeleton digraph
128 checkConcept<Digraph, Digraph>();
130 { // Checking ListDigraph
131 checkConcept<Digraph, ListDigraph>();
132 checkConcept<AlterableDigraphComponent<>, ListDigraph>();
133 checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
134 checkConcept<ClearableDigraphComponent<>, ListDigraph>();
135 checkConcept<ErasableDigraphComponent<>, ListDigraph>();
137 { // Checking SmartDigraph
138 checkConcept<Digraph, SmartDigraph>();
139 checkConcept<AlterableDigraphComponent<>, SmartDigraph>();
140 checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
141 checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
143 { // Checking FullDigraph
144 checkConcept<Digraph, FullDigraph>();
148 template <typename Digraph>
149 void checkDigraphValidity() {
150 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
159 e1 = g.addArc(n1, n2),
160 e2 = g.addArc(n2, n3);
162 check(g.valid(n1), "Wrong validity check");
163 check(g.valid(e1), "Wrong validity check");
165 check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
166 check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
169 template <typename Digraph>
170 void checkDigraphValidityErase() {
171 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
180 e1 = g.addArc(n1, n2),
181 e2 = g.addArc(n2, n3);
183 check(g.valid(n1), "Wrong validity check");
184 check(g.valid(e1), "Wrong validity check");
188 check(!g.valid(n1), "Wrong validity check");
189 check(g.valid(n2), "Wrong validity check");
190 check(g.valid(n3), "Wrong validity check");
191 check(!g.valid(e1), "Wrong validity check");
192 check(g.valid(e2), "Wrong validity check");
194 check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
195 check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
198 void checkDigraphs() {
199 { // Checking ListDigraph
200 checkDigraph<ListDigraph>();
201 checkDigraphValidityErase<ListDigraph>();
203 { // Checking SmartDigraph
204 checkDigraph<SmartDigraph>();
205 checkDigraphValidity<SmartDigraph>();
207 { // Checking FullDigraph