Changeset 149:2f7ae34e1333 in lemon1.0 for test/graph_test.cc
 Timestamp:
 04/24/08 14:53:09 (13 years ago)
 Branch:
 default
 Phase:
 public
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

test/graph_test.cc
r109 r149 23 23 // #include <lemon/grid_graph.h> 24 24 25 //#include <lemon/graph_utils.h>25 #include <lemon/graph_utils.h> 26 26 27 27 #include "test_tools.h" … … 83 83 84 84 template <typename Graph> 85 void print_items(Graph &g) { 86 87 typedef typename Graph::NodeIt NodeIt; 88 typedef typename Graph::EdgeIt EdgeIt; 89 typedef typename Graph::ArcIt ArcIt; 90 91 std::cout << "Nodes" << std::endl; 92 int i=0; 93 for(NodeIt it(g); it!=INVALID; ++it, ++i) { 94 std::cout << " " << i << ": " << g.id(it) << std::endl; 95 } 96 97 std::cout << "Edge" << std::endl; 98 i=0; 99 for(EdgeIt it(g); it!=INVALID; ++it, ++i) { 100 std::cout << " " << i << ": " << g.id(it) 101 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 102 << ")" << std::endl; 103 } 104 105 std::cout << "Arc" << std::endl; 106 i=0; 107 for(ArcIt it(g); it!=INVALID; ++it, ++i) { 108 std::cout << " " << i << ": " << g.id(it) 109 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 110 << ")" << std::endl; 111 } 112 113 } 114 115 template <typename Graph> 116 void check_graph() { 117 118 typedef typename Graph::Node Node; 119 typedef typename Graph::Edge Edge; 120 typedef typename Graph::Arc Arc; 121 typedef typename Graph::NodeIt NodeIt; 122 typedef typename Graph::EdgeIt EdgeIt; 123 typedef typename Graph::ArcIt ArcIt; 124 85 void check_graph_counts() { 86 87 TEMPLATE_GRAPH_TYPEDEFS(Graph); 125 88 Graph g; 126 89 … … 136 99 e2 = g.addEdge(n2, n3); 137 100 138 // print_items(g);139 140 101 check_item_counts(g,3,2); 141 102 } 103 104 template <typename Graph> 105 void check_graph_validity() { 106 107 TEMPLATE_GRAPH_TYPEDEFS(Graph); 108 Graph g; 109 110 check_item_counts(g,0,0); 111 112 Node 113 n1 = g.addNode(), 114 n2 = g.addNode(), 115 n3 = g.addNode(); 116 117 Edge 118 e1 = g.addEdge(n1, n2), 119 e2 = g.addEdge(n2, n3); 120 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"); 151 152 g.erase(n1); 153 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 142 167 143 168 // void checkGridGraph(const GridGraph& g, int w, int h) { … … 188 213 check_concepts(); 189 214 190 check_graph<ListGraph>(); 191 check_graph<SmartGraph>(); 215 check_graph_counts<ListGraph>(); 216 check_graph_counts<SmartGraph>(); 217 218 check_graph_validity_erase<ListGraph>(); 219 check_graph_validity<SmartGraph>(); 192 220 193 221 // {
Note: See TracChangeset
for help on using the changeset viewer.