diff --git a/test/graph_test.cc b/test/graph_test.cc --- a/test/graph_test.cc +++ b/test/graph_test.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include "test_tools.h" #include "graph_test.h" @@ -104,9 +105,9 @@ checkGraphEdgeList(G, num * (num - 1) / 2); for (NodeIt n(G); n != INVALID; ++n) { - checkGraphOutArcList(G, n, num - 1); - checkGraphInArcList(G, n, num - 1); - checkGraphIncEdgeList(G, n, num - 1); + checkGraphOutArcList(G, n, num - 1); + checkGraphInArcList(G, n, num - 1); + checkGraphIncEdgeList(G, n, num - 1); } checkGraphConArcList(G, num * (num - 1)); @@ -121,7 +122,7 @@ checkGraphArcMap(G); checkGraphEdgeMap(G); - + for (int i = 0; i < G.nodeNum(); ++i) { check(G.index(G(i)) == i, "Wrong index"); } @@ -177,6 +178,9 @@ { // Checking GridGraph checkConcept(); } + { // Checking HypercubeGraph + checkConcept(); + } } template @@ -312,6 +316,54 @@ } +void checkHypercubeGraph(int dim) { + GRAPH_TYPEDEFS(HypercubeGraph); + + HypercubeGraph G(dim); + checkGraphNodeList(G, 1 << dim); + checkGraphEdgeList(G, dim * (1 << dim-1)); + checkGraphArcList(G, dim * (1 << dim)); + + Node n = G.nodeFromId(dim); + + for (NodeIt n(G); n != INVALID; ++n) { + checkGraphIncEdgeList(G, n, dim); + for (IncEdgeIt e(G, n); e != INVALID; ++e) { + check( (G.u(e) == n && + G.id(G.v(e)) == G.id(n) ^ (1 << G.dimension(e))) || + (G.v(e) == n && + G.id(G.u(e)) == G.id(n) ^ (1 << G.dimension(e))), + "Wrong edge or wrong dimension"); + } + + checkGraphOutArcList(G, n, dim); + for (OutArcIt a(G, n); a != INVALID; ++a) { + check(G.source(a) == n && + G.id(G.target(a)) == G.id(n) ^ (1 << G.dimension(a)), + "Wrong arc or wrong dimension"); + } + + checkGraphInArcList(G, n, dim); + for (InArcIt a(G, n); a != INVALID; ++a) { + check(G.target(a) == n && + G.id(G.source(a)) == G.id(n) ^ (1 << G.dimension(a)), + "Wrong arc or wrong dimension"); + } + } + + checkGraphConArcList(G, (1 << dim) * dim); + checkGraphConEdgeList(G, dim * (1 << dim-1)); + + checkArcDirections(G); + + checkNodeIds(G); + checkArcIds(G); + checkEdgeIds(G); + checkGraphNodeMap(G); + checkGraphArcMap(G); + checkGraphEdgeMap(G); +} + void checkGraphs() { { // Checking ListGraph checkGraph(); @@ -321,7 +373,7 @@ checkGraph(); checkGraphValidity(); } - { // Checking FullGraph + { // Checking FullGraph checkFullGraph(7); checkFullGraph(8); } @@ -332,6 +384,12 @@ checkGridGraph(0, 0); checkGridGraph(1, 1); } + { // Checking HypercubeGraph + checkHypercubeGraph(1); + checkHypercubeGraph(2); + checkHypercubeGraph(3); + checkHypercubeGraph(4); + } } int main() {