[209] | 1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
[57] | 2 | * |
---|
[209] | 3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
[57] | 4 | * |
---|
[107] | 5 | * Copyright (C) 2003-2008 |
---|
[57] | 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/concepts/digraph.h> |
---|
| 20 | #include <lemon/list_graph.h> |
---|
[171] | 21 | #include <lemon/smart_graph.h> |
---|
[57] | 22 | //#include <lemon/full_graph.h> |
---|
| 23 | //#include <lemon/hypercube_graph.h> |
---|
| 24 | |
---|
| 25 | #include "test_tools.h" |
---|
[171] | 26 | #include "graph_test.h" |
---|
| 27 | #include "graph_maps_test.h" |
---|
[57] | 28 | |
---|
| 29 | using namespace lemon; |
---|
| 30 | using namespace lemon::concepts; |
---|
| 31 | |
---|
[171] | 32 | void check_concepts() { |
---|
| 33 | { // Checking digraph components |
---|
[57] | 34 | checkConcept<BaseDigraphComponent, BaseDigraphComponent >(); |
---|
| 35 | |
---|
[209] | 36 | checkConcept<IDableDigraphComponent<>, |
---|
[57] | 37 | IDableDigraphComponent<> >(); |
---|
| 38 | |
---|
[209] | 39 | checkConcept<IterableDigraphComponent<>, |
---|
[57] | 40 | IterableDigraphComponent<> >(); |
---|
| 41 | |
---|
[209] | 42 | checkConcept<MappableDigraphComponent<>, |
---|
[57] | 43 | MappableDigraphComponent<> >(); |
---|
| 44 | } |
---|
[171] | 45 | { // Checking skeleton digraph |
---|
[57] | 46 | checkConcept<Digraph, Digraph>(); |
---|
| 47 | } |
---|
[171] | 48 | { // Checking ListDigraph |
---|
| 49 | checkConcept<Digraph, ListDigraph>(); |
---|
[57] | 50 | checkConcept<AlterableDigraphComponent<>, ListDigraph>(); |
---|
| 51 | checkConcept<ExtendableDigraphComponent<>, ListDigraph>(); |
---|
| 52 | checkConcept<ClearableDigraphComponent<>, ListDigraph>(); |
---|
| 53 | checkConcept<ErasableDigraphComponent<>, ListDigraph>(); |
---|
[171] | 54 | checkDigraphIterators<ListDigraph>(); |
---|
| 55 | } |
---|
| 56 | { // Checking SmartDigraph |
---|
| 57 | checkConcept<Digraph, SmartDigraph>(); |
---|
| 58 | checkConcept<AlterableDigraphComponent<>, SmartDigraph>(); |
---|
| 59 | checkConcept<ExtendableDigraphComponent<>, SmartDigraph>(); |
---|
| 60 | checkConcept<ClearableDigraphComponent<>, SmartDigraph>(); |
---|
| 61 | checkDigraphIterators<SmartDigraph>(); |
---|
| 62 | } |
---|
| 63 | // { // Checking FullDigraph |
---|
| 64 | // checkConcept<Digraph, FullDigraph>(); |
---|
| 65 | // checkDigraphIterators<FullDigraph>(); |
---|
| 66 | // } |
---|
| 67 | // { // Checking HyperCubeDigraph |
---|
| 68 | // checkConcept<Digraph, HyperCubeDigraph>(); |
---|
| 69 | // checkDigraphIterators<HyperCubeDigraph>(); |
---|
| 70 | // } |
---|
| 71 | } |
---|
[57] | 72 | |
---|
[171] | 73 | template <typename Digraph> |
---|
| 74 | void check_graph_validity() { |
---|
| 75 | TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
---|
| 76 | Digraph g; |
---|
| 77 | |
---|
| 78 | Node |
---|
| 79 | n1 = g.addNode(), |
---|
| 80 | n2 = g.addNode(), |
---|
| 81 | n3 = g.addNode(); |
---|
| 82 | |
---|
| 83 | Arc |
---|
| 84 | e1 = g.addArc(n1, n2), |
---|
| 85 | e2 = g.addArc(n2, n3); |
---|
| 86 | |
---|
| 87 | check(g.valid(n1), "Wrong validity check"); |
---|
| 88 | check(g.valid(e1), "Wrong validity check"); |
---|
| 89 | |
---|
| 90 | check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
---|
| 91 | check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | template <typename Digraph> |
---|
| 95 | void check_graph_validity_erase() { |
---|
| 96 | TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
---|
| 97 | Digraph g; |
---|
| 98 | |
---|
| 99 | Node |
---|
| 100 | n1 = g.addNode(), |
---|
| 101 | n2 = g.addNode(), |
---|
| 102 | n3 = g.addNode(); |
---|
| 103 | |
---|
| 104 | Arc |
---|
| 105 | e1 = g.addArc(n1, n2), |
---|
| 106 | e2 = g.addArc(n2, n3); |
---|
| 107 | |
---|
| 108 | check(g.valid(n1), "Wrong validity check"); |
---|
| 109 | check(g.valid(e1), "Wrong validity check"); |
---|
| 110 | |
---|
| 111 | g.erase(n1); |
---|
| 112 | |
---|
| 113 | check(!g.valid(n1), "Wrong validity check"); |
---|
| 114 | check(g.valid(n2), "Wrong validity check"); |
---|
| 115 | check(g.valid(n3), "Wrong validity check"); |
---|
| 116 | check(!g.valid(e1), "Wrong validity check"); |
---|
| 117 | check(g.valid(e2), "Wrong validity check"); |
---|
| 118 | |
---|
| 119 | check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
---|
| 120 | check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | void check_digraphs() { |
---|
| 124 | { // Checking ListDigraph |
---|
[57] | 125 | checkDigraph<ListDigraph>(); |
---|
| 126 | checkGraphNodeMap<ListDigraph>(); |
---|
| 127 | checkGraphArcMap<ListDigraph>(); |
---|
[171] | 128 | |
---|
| 129 | check_graph_validity_erase<ListDigraph>(); |
---|
[57] | 130 | } |
---|
[171] | 131 | { // Checking SmartDigraph |
---|
| 132 | checkDigraph<SmartDigraph>(); |
---|
| 133 | checkGraphNodeMap<SmartDigraph>(); |
---|
| 134 | checkGraphArcMap<SmartDigraph>(); |
---|
[57] | 135 | |
---|
[171] | 136 | check_graph_validity<SmartDigraph>(); |
---|
| 137 | } |
---|
| 138 | } |
---|
[57] | 139 | |
---|
[171] | 140 | int main() { |
---|
| 141 | check_concepts(); |
---|
| 142 | check_digraphs(); |
---|
[57] | 143 | return 0; |
---|
| 144 | } |
---|