diff --git a/test/graph_test.cc b/test/graph_test.cc --- a/test/graph_test.cc +++ b/test/graph_test.cc @@ -22,17 +22,15 @@ // #include // #include -#include - #include "test_tools.h" - +#include "graph_test.h" +#include "graph_maps_test.h" using namespace lemon; using namespace lemon::concepts; void check_concepts() { - - { // checking digraph components + { // Checking graph components checkConcept(); checkConcept, @@ -43,52 +41,40 @@ checkConcept, MappableGraphComponent<> >(); - } - { - checkConcept(); - checkConcept(); -// checkConcept(); -// checkConcept(); -// checkConcept(); + { // Checking skeleton graph + checkConcept(); } + { // Checking ListGraph + checkConcept(); + checkConcept, ListGraph>(); + checkConcept, ListGraph>(); + checkConcept, ListGraph>(); + checkConcept, ListGraph>(); + checkGraphIterators(); + } + { // Checking SmartGraph + checkConcept(); + checkConcept, SmartGraph>(); + checkConcept, SmartGraph>(); + checkConcept, SmartGraph>(); + checkGraphIterators(); + } +// { // Checking FullGraph +// checkConcept(); +// checkGraphIterators(); +// } +// { // Checking GridGraph +// checkConcept(); +// checkGraphIterators(); +// } } template -void check_item_counts(Graph &g, int n, int e) { - int nn = 0; - for (typename Graph::NodeIt it(g); it != INVALID; ++it) { - ++nn; - } - - check(nn == n, "Wrong node number."); - // check(countNodes(g) == n, "Wrong node number."); - - int ee = 0; - for (typename Graph::ArcIt it(g); it != INVALID; ++it) { - ++ee; - } - - check(ee == 2*e, "Wrong arc number."); - // check(countArcs(g) == 2*e, "Wrong arc number."); - - int uee = 0; - for (typename Graph::EdgeIt it(g); it != INVALID; ++it) { - ++uee; - } - - check(uee == e, "Wrong edge number."); - // check(countEdges(g) == e, "Wrong edge number."); -} - -template -void check_graph_counts() { - +void check_graph_validity() { TEMPLATE_GRAPH_TYPEDEFS(Graph); Graph g; - check_item_counts(g,0,0); - Node n1 = g.addNode(), n2 = g.addNode(), @@ -98,17 +84,20 @@ e1 = g.addEdge(n1, n2), e2 = g.addEdge(n2, n3); - check_item_counts(g,3,2); + check(g.valid(n1), "Wrong validity check"); + check(g.valid(e1), "Wrong validity check"); + check(g.valid(g.direct(e1, true)), "Wrong validity check"); + + check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); + check(!g.valid(g.edgeFromId(-1)), "Wrong validity check"); + check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); } template -void check_graph_validity() { - +void check_graph_validity_erase() { TEMPLATE_GRAPH_TYPEDEFS(Graph); Graph g; - check_item_counts(g,0,0); - Node n1 = g.addNode(), n2 = g.addNode(), @@ -118,53 +107,23 @@ e1 = g.addEdge(n1, n2), e2 = g.addEdge(n2, n3); - check(g.valid(n1), "Validity check"); - check(g.valid(e1), "Validity check"); - check(g.valid(g.direct(e1, true)), "Validity check"); - - check(!g.valid(g.nodeFromId(-1)), "Validity check"); - check(!g.valid(g.edgeFromId(-1)), "Validity check"); - check(!g.valid(g.arcFromId(-1)), "Validity check"); - -} - -template -void check_graph_validity_erase() { - - TEMPLATE_GRAPH_TYPEDEFS(Graph); - Graph g; - - check_item_counts(g,0,0); - - Node - n1 = g.addNode(), - n2 = g.addNode(), - n3 = g.addNode(); - - Edge - e1 = g.addEdge(n1, n2), - e2 = g.addEdge(n2, n3); - - check(g.valid(n1), "Validity check"); - check(g.valid(e1), "Validity check"); - check(g.valid(g.direct(e1, true)), "Validity check"); + check(g.valid(n1), "Wrong validity check"); + check(g.valid(e1), "Wrong validity check"); + check(g.valid(g.direct(e1, true)), "Wrong validity check"); g.erase(n1); - check(!g.valid(n1), "Validity check"); - check(g.valid(n2), "Validity check"); - check(g.valid(n3), "Validity check"); - check(!g.valid(e1), "Validity check"); - check(g.valid(e2), "Validity check"); + check(!g.valid(n1), "Wrong validity check"); + check(g.valid(n2), "Wrong validity check"); + check(g.valid(n3), "Wrong validity check"); + check(!g.valid(e1), "Wrong validity check"); + check(g.valid(e2), "Wrong validity check"); - check(!g.valid(g.nodeFromId(-1)), "Validity check"); - check(!g.valid(g.edgeFromId(-1)), "Validity check"); - check(!g.valid(g.arcFromId(-1)), "Validity check"); - + check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); + check(!g.valid(g.edgeFromId(-1)), "Wrong validity check"); + check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); } - - // void checkGridGraph(const GridGraph& g, int w, int h) { // check(g.width() == w, "Wrong width"); // check(g.height() == h, "Wrong height"); @@ -209,27 +168,36 @@ // } // } +void check_graphs() { + { // Checking ListGraph + checkGraph(); + checkGraphNodeMap(); + checkGraphEdgeMap(); + + check_graph_validity_erase(); + } + { // Checking SmartGraph + checkGraph(); + checkGraphNodeMap(); + checkGraphEdgeMap(); + + check_graph_validity(); + } +// { // Checking FullGraph +// FullGraph g(5); +// checkGraphNodeList(g, 5); +// checkGraphEdgeList(g, 10); +// } +// { // Checking GridGraph +// GridGraph g(5, 6); +// checkGraphNodeList(g, 30); +// checkGraphEdgeList(g, 49); +// checkGridGraph(g, 5, 6); +// } +} + int main() { check_concepts(); - - check_graph_counts(); - check_graph_counts(); - - check_graph_validity_erase(); - check_graph_validity(); - -// { -// FullGraph g(5); -// check_item_counts(g, 5, 10); -// } - -// { -// GridGraph g(5, 6); -// check_item_counts(g, 30, 49); -// checkGridGraph(g, 5, 6); -// } - - std::cout << __FILE__ ": All tests passed.\n"; - + check_graphs(); return 0; }