Changeset 171:02f4d5d9bfd7 in lemon for test/graph_test.cc
 Timestamp:
 06/15/08 22:05:23 (13 years ago)
 Branch:
 default
 Children:
 172:c94a80f38d7f, 173:b026e9779b28, 175:4eb8900a865c
 Phase:
 public
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

test/graph_test.cc
r149 r171 23 23 // #include <lemon/grid_graph.h> 24 24 25 #include <lemon/graph_utils.h>26 27 25 #include "test_tools.h" 28 26 #include "graph_test.h" 27 #include "graph_maps_test.h" 29 28 30 29 using namespace lemon; … … 32 31 33 32 void check_concepts() { 34 35 { // checking digraph components 33 { // Checking graph components 36 34 checkConcept<BaseGraphComponent, BaseGraphComponent >(); 37 35 … … 44 42 checkConcept<MappableGraphComponent<>, 45 43 MappableGraphComponent<> >(); 46 47 } 48 { 49 checkConcept<Graph, ListGraph>(); 50 checkConcept<Graph, SmartGraph>(); 51 // checkConcept<Graph, FullGraph>(); 52 // checkConcept<Graph, Graph>(); 53 // checkConcept<Graph, GridGraph>(); 54 } 44 } 45 { // Checking skeleton graph 46 checkConcept<Graph, Graph>(); 47 } 48 { // Checking ListGraph 49 checkConcept<Graph, ListGraph>(); 50 checkConcept<AlterableGraphComponent<>, ListGraph>(); 51 checkConcept<ExtendableGraphComponent<>, ListGraph>(); 52 checkConcept<ClearableGraphComponent<>, ListGraph>(); 53 checkConcept<ErasableGraphComponent<>, ListGraph>(); 54 checkGraphIterators<ListGraph>(); 55 } 56 { // Checking SmartGraph 57 checkConcept<Graph, SmartGraph>(); 58 checkConcept<AlterableGraphComponent<>, SmartGraph>(); 59 checkConcept<ExtendableGraphComponent<>, SmartGraph>(); 60 checkConcept<ClearableGraphComponent<>, SmartGraph>(); 61 checkGraphIterators<SmartGraph>(); 62 } 63 // { // Checking FullGraph 64 // checkConcept<Graph, FullGraph>(); 65 // checkGraphIterators<FullGraph>(); 66 // } 67 // { // Checking GridGraph 68 // checkConcept<Graph, GridGraph>(); 69 // checkGraphIterators<GridGraph>(); 70 // } 55 71 } 56 72 57 73 template <typename Graph> 58 void check_item_counts(Graph &g, int n, int e) { 59 int nn = 0; 60 for (typename Graph::NodeIt it(g); it != INVALID; ++it) { 61 ++nn; 62 } 63 64 check(nn == n, "Wrong node number."); 65 // check(countNodes(g) == n, "Wrong node number."); 66 67 int ee = 0; 68 for (typename Graph::ArcIt it(g); it != INVALID; ++it) { 69 ++ee; 70 } 71 72 check(ee == 2*e, "Wrong arc number."); 73 // check(countArcs(g) == 2*e, "Wrong arc number."); 74 75 int uee = 0; 76 for (typename Graph::EdgeIt it(g); it != INVALID; ++it) { 77 ++uee; 78 } 79 80 check(uee == e, "Wrong edge number."); 81 // check(countEdges(g) == e, "Wrong edge number."); 82 } 83 84 template <typename Graph> 85 void check_graph_counts() { 86 74 void check_graph_validity() { 87 75 TEMPLATE_GRAPH_TYPEDEFS(Graph); 88 76 Graph g; 89 90 check_item_counts(g,0,0);91 77 92 78 Node … … 99 85 e2 = g.addEdge(n2, n3); 100 86 101 check_item_counts(g,3,2); 87 check(g.valid(n1), "Wrong validity check"); 88 check(g.valid(e1), "Wrong validity check"); 89 check(g.valid(g.direct(e1, true)), "Wrong validity check"); 90 91 check(!g.valid(g.nodeFromId(1)), "Wrong validity check"); 92 check(!g.valid(g.edgeFromId(1)), "Wrong validity check"); 93 check(!g.valid(g.arcFromId(1)), "Wrong validity check"); 102 94 } 103 95 104 96 template <typename Graph> 105 void check_graph_validity() { 106 97 void check_graph_validity_erase() { 107 98 TEMPLATE_GRAPH_TYPEDEFS(Graph); 108 99 Graph g; 109 110 check_item_counts(g,0,0);111 100 112 101 Node … … 119 108 e2 = g.addEdge(n2, n3); 120 109 121 check(g.valid(n1), "Validity check"); 122 check(g.valid(e1), "Validity check"); 123 check(g.valid(g.direct(e1, true)), "Validity check"); 124 125 check(!g.valid(g.nodeFromId(1)), "Validity check"); 126 check(!g.valid(g.edgeFromId(1)), "Validity check"); 127 check(!g.valid(g.arcFromId(1)), "Validity check"); 128 129 } 130 131 template <typename Graph> 132 void check_graph_validity_erase() { 133 134 TEMPLATE_GRAPH_TYPEDEFS(Graph); 135 Graph g; 136 137 check_item_counts(g,0,0); 138 139 Node 140 n1 = g.addNode(), 141 n2 = g.addNode(), 142 n3 = g.addNode(); 143 144 Edge 145 e1 = g.addEdge(n1, n2), 146 e2 = g.addEdge(n2, n3); 147 148 check(g.valid(n1), "Validity check"); 149 check(g.valid(e1), "Validity check"); 150 check(g.valid(g.direct(e1, true)), "Validity check"); 110 check(g.valid(n1), "Wrong validity check"); 111 check(g.valid(e1), "Wrong validity check"); 112 check(g.valid(g.direct(e1, true)), "Wrong validity check"); 151 113 152 114 g.erase(n1); 153 115 154 check(!g.valid(n1), "Validity check"); 155 check(g.valid(n2), "Validity check"); 156 check(g.valid(n3), "Validity check"); 157 check(!g.valid(e1), "Validity check"); 158 check(g.valid(e2), "Validity check"); 159 160 check(!g.valid(g.nodeFromId(1)), "Validity check"); 161 check(!g.valid(g.edgeFromId(1)), "Validity check"); 162 check(!g.valid(g.arcFromId(1)), "Validity check"); 163 164 } 165 166 116 check(!g.valid(n1), "Wrong validity check"); 117 check(g.valid(n2), "Wrong validity check"); 118 check(g.valid(n3), "Wrong validity check"); 119 check(!g.valid(e1), "Wrong validity check"); 120 check(g.valid(e2), "Wrong validity check"); 121 122 check(!g.valid(g.nodeFromId(1)), "Wrong validity check"); 123 check(!g.valid(g.edgeFromId(1)), "Wrong validity check"); 124 check(!g.valid(g.arcFromId(1)), "Wrong validity check"); 125 } 167 126 168 127 // void checkGridGraph(const GridGraph& g, int w, int h) { … … 210 169 // } 211 170 171 void check_graphs() { 172 { // Checking ListGraph 173 checkGraph<ListGraph>(); 174 checkGraphNodeMap<ListGraph>(); 175 checkGraphEdgeMap<ListGraph>(); 176 177 check_graph_validity_erase<ListGraph>(); 178 } 179 { // Checking SmartGraph 180 checkGraph<SmartGraph>(); 181 checkGraphNodeMap<SmartGraph>(); 182 checkGraphEdgeMap<SmartGraph>(); 183 184 check_graph_validity<SmartGraph>(); 185 } 186 // { // Checking FullGraph 187 // FullGraph g(5); 188 // checkGraphNodeList(g, 5); 189 // checkGraphEdgeList(g, 10); 190 // } 191 // { // Checking GridGraph 192 // GridGraph g(5, 6); 193 // checkGraphNodeList(g, 30); 194 // checkGraphEdgeList(g, 49); 195 // checkGridGraph(g, 5, 6); 196 // } 197 } 198 212 199 int main() { 213 200 check_concepts(); 214 215 check_graph_counts<ListGraph>(); 216 check_graph_counts<SmartGraph>(); 217 218 check_graph_validity_erase<ListGraph>(); 219 check_graph_validity<SmartGraph>(); 220 221 // { 222 // FullGraph g(5); 223 // check_item_counts(g, 5, 10); 224 // } 225 226 // { 227 // GridGraph g(5, 6); 228 // check_item_counts(g, 30, 49); 229 // checkGridGraph(g, 5, 6); 230 // } 231 232 std::cout << __FILE__ ": All tests passed.\n"; 233 201 check_graphs(); 234 202 return 0; 235 203 }
Note: See TracChangeset
for help on using the changeset viewer.