[Lemon-commits] Balazs Dezso: Reworking graph testing
Lemon HG
hg at lemon.cs.elte.hu
Mon Jul 21 19:38:03 CEST 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/b6732e0d38c5
changeset: 228:b6732e0d38c5
user: Balazs Dezso <deba [at] inf.elte.hu>
date: Mon Jul 21 16:30:28 2008 +0200
description:
Reworking graph testing
- The graph tests check more graph functionality.
- The petersen graph is too regular, therefore special graphs are
used.
- The graph_test.h contains just general tools to test graphs.
diffstat:
8 files changed, 429 insertions(+), 374 deletions(-)
test/Makefile.am | 1
test/bfs_test.cc | 64 +++++++--
test/dfs_test.cc | 54 ++++++--
test/digraph_test.cc | 79 +++++++++---
test/dijkstra_test.cc | 61 ++++++---
test/graph_maps_test.h | 144 ----------------------
test/graph_test.cc | 92 +++++++++++---
test/graph_test.h | 308 +++++++++++++++++++++++++-----------------------
diffs (truncated from 1134 to 300 lines):
diff -r 33f8d69e642a -r b6732e0d38c5 test/Makefile.am
--- a/test/Makefile.am Fri Jul 18 17:26:12 2008 +0100
+++ b/test/Makefile.am Mon Jul 21 16:30:28 2008 +0200
@@ -3,7 +3,6 @@
noinst_HEADERS += \
test/graph_test.h \
- test/graph_maps_test.h \
test/test_tools.h
check_PROGRAMS += \
diff -r 33f8d69e642a -r b6732e0d38c5 test/bfs_test.cc
--- a/test/bfs_test.cc Fri Jul 18 17:26:12 2008 +0100
+++ b/test/bfs_test.cc Mon Jul 21 16:30:28 2008 +0200
@@ -19,6 +19,7 @@
#include <lemon/concepts/digraph.h>
#include <lemon/smart_graph.h>
#include <lemon/list_graph.h>
+#include <lemon/lgf_reader.h>
#include <lemon/bfs.h>
#include <lemon/path.h>
@@ -26,6 +27,28 @@
#include "test_tools.h"
using namespace lemon;
+
+char test_lgf[] =
+ "@nodes\n"
+ "label\n"
+ "0\n"
+ "1\n"
+ "2\n"
+ "3\n"
+ "4\n"
+ "5\n"
+ "@arcs\n"
+ " label\n"
+ "0 1 0\n"
+ "1 2 1\n"
+ "2 3 2\n"
+ "3 4 3\n"
+ "0 3 4\n"
+ "0 3 5\n"
+ "5 2 6\n"
+ "@attributes\n"
+ "source 0\n"
+ "target 4\n";
void checkBfsCompile()
{
@@ -49,6 +72,7 @@
e = bfs_test.predArc(n);
n = bfs_test.predNode(n);
d = bfs_test.distMap();
+
p = bfs_test.predMap();
// pn = bfs_test.predNodeMap();
b = bfs_test.reached(n);
@@ -80,41 +104,45 @@
Digraph G;
Node s, t;
- PetStruct<Digraph> ps = addPetersen(G, 5);
- s=ps.outer[2];
- t=ps.inner[0];
+ std::istringstream input(test_lgf);
+ digraphReader(input, G).
+ node("source", s).
+ node("target", t).
+ run();
Bfs<Digraph> bfs_test(G);
bfs_test.run(s);
- check(bfs_test.dist(t)==3,"Bfs found a wrong path." << bfs_test.dist(t));
+ check(bfs_test.dist(t)==2,"Bfs found a wrong path." << bfs_test.dist(t));
Path<Digraph> p = bfs_test.path(t);
- check(p.length()==3,"path() found a wrong path.");
+ check(p.length()==2,"path() found a wrong path.");
check(checkPath(G, p),"path() found a wrong path.");
check(pathSource(G, p) == s,"path() found a wrong path.");
check(pathTarget(G, p) == t,"path() found a wrong path.");
- for(ArcIt e(G); e!=INVALID; ++e) {
- Node u=G.source(e);
- Node v=G.target(e);
+ for(ArcIt a(G); a!=INVALID; ++a) {
+ Node u=G.source(a);
+ Node v=G.target(a);
check( !bfs_test.reached(u) ||
(bfs_test.dist(v) <= bfs_test.dist(u)+1),
- "Wrong output.");
+ "Wrong output." << G.id(v) << ' ' << G.id(u));
}
for(NodeIt v(G); v!=INVALID; ++v) {
- check(bfs_test.reached(v),"Each node should be reached.");
- if ( bfs_test.predArc(v)!=INVALID ) {
- Arc e=bfs_test.predArc(v);
- Node u=G.source(e);
- check(u==bfs_test.predNode(v),"Wrong tree.");
- check(bfs_test.dist(v) - bfs_test.dist(u) == 1,
- "Wrong distance. Difference: "
- << std::abs(bfs_test.dist(v) - bfs_test.dist(u)
- - 1));
+ if (bfs_test.reached(v)) {
+ check(v==s || bfs_test.predArc(v)!=INVALID, "Wrong tree.");
+ if (bfs_test.predArc(v)!=INVALID ) {
+ Arc a=bfs_test.predArc(v);
+ Node u=G.source(a);
+ check(u==bfs_test.predNode(v),"Wrong tree.");
+ check(bfs_test.dist(v) - bfs_test.dist(u) == 1,
+ "Wrong distance. Difference: "
+ << std::abs(bfs_test.dist(v) - bfs_test.dist(u)
+ - 1));
+ }
}
}
}
diff -r 33f8d69e642a -r b6732e0d38c5 test/dfs_test.cc
--- a/test/dfs_test.cc Fri Jul 18 17:26:12 2008 +0100
+++ b/test/dfs_test.cc Mon Jul 21 16:30:28 2008 +0200
@@ -19,6 +19,8 @@
#include <lemon/concepts/digraph.h>
#include <lemon/smart_graph.h>
#include <lemon/list_graph.h>
+#include <lemon/lgf_reader.h>
+
#include <lemon/dfs.h>
#include <lemon/path.h>
@@ -26,6 +28,30 @@
#include "test_tools.h"
using namespace lemon;
+
+char test_lgf[] =
+ "@nodes\n"
+ "label\n"
+ "0\n"
+ "1\n"
+ "2\n"
+ "3\n"
+ "4\n"
+ "5\n"
+ "6\n"
+ "@arcs\n"
+ " label\n"
+ "0 1 0\n"
+ "1 2 1\n"
+ "2 3 2\n"
+ "1 4 3\n"
+ "4 2 4\n"
+ "4 5 5\n"
+ "5 0 6\n"
+ "6 3 7\n"
+ "@attributes\n"
+ "source 0\n"
+ "target 5\n";
void checkDfsCompile()
{
@@ -39,7 +65,6 @@
bool b;
DType::DistMap d(G);
DType::PredMap p(G);
- // DType::PredNodeMap pn(G);
DType dfs_test(G);
@@ -50,7 +75,6 @@
n = dfs_test.predNode(n);
d = dfs_test.distMap();
p = dfs_test.predMap();
- // pn = dfs_test.predNodeMap();
b = dfs_test.reached(n);
Path<Digraph> pp = dfs_test.path(n);
@@ -80,10 +104,12 @@
Digraph G;
Node s, t;
- PetStruct<Digraph> ps = addPetersen(G, 5);
- s=ps.outer[2];
- t=ps.inner[0];
+ std::istringstream input(test_lgf);
+ digraphReader(input, G).
+ node("source", s).
+ node("target", t).
+ run();
Dfs<Digraph> dfs_test(G);
dfs_test.run(s);
@@ -95,14 +121,16 @@
check(pathTarget(G, p) == t,"path() found a wrong path.");
for(NodeIt v(G); v!=INVALID; ++v) {
- check(dfs_test.reached(v),"Each node should be reached.");
- if ( dfs_test.predArc(v)!=INVALID ) {
- Arc e=dfs_test.predArc(v);
- Node u=G.source(e);
- check(u==dfs_test.predNode(v),"Wrong tree.");
- check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
- "Wrong distance. (" << dfs_test.dist(u) << "->"
- <<dfs_test.dist(v) << ')');
+ if (dfs_test.reached(v)) {
+ check(v==s || dfs_test.predArc(v)!=INVALID, "Wrong tree.");
+ if (dfs_test.predArc(v)!=INVALID ) {
+ Arc e=dfs_test.predArc(v);
+ Node u=G.source(e);
+ check(u==dfs_test.predNode(v),"Wrong tree.");
+ check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
+ "Wrong distance. (" << dfs_test.dist(u) << "->"
+ <<dfs_test.dist(v) << ')');
+ }
}
}
}
diff -r 33f8d69e642a -r b6732e0d38c5 test/digraph_test.cc
--- a/test/digraph_test.cc Fri Jul 18 17:26:12 2008 +0100
+++ b/test/digraph_test.cc Mon Jul 21 16:30:28 2008 +0200
@@ -24,12 +24,63 @@
#include "test_tools.h"
#include "graph_test.h"
-#include "graph_maps_test.h"
using namespace lemon;
using namespace lemon::concepts;
-void check_concepts() {
+template <class Digraph>
+void checkDigraph() {
+ TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
+ Digraph G;
+
+ checkGraphNodeList(G, 0);
+ checkGraphArcList(G, 0);
+
+ Node
+ n1 = G.addNode(),
+ n2 = G.addNode(),
+ n3 = G.addNode();
+ checkGraphNodeList(G, 3);
+ checkGraphArcList(G, 0);
+
+ Arc a1 = G.addArc(n1, n2);
+ check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc");
+ checkGraphNodeList(G, 3);
+ checkGraphArcList(G, 1);
+
+ checkGraphOutArcList(G, n1, 1);
+ checkGraphOutArcList(G, n2, 0);
+ checkGraphOutArcList(G, n3, 0);
+
+ checkGraphInArcList(G, n1, 0);
+ checkGraphInArcList(G, n2, 1);
+ checkGraphInArcList(G, n3, 0);
+
+ checkGraphConArcList(G, 1);
+
+ Arc a2 = G.addArc(n2, n1), a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
+ checkGraphNodeList(G, 3);
+ checkGraphArcList(G, 4);
+
+ checkGraphOutArcList(G, n1, 1);
+ checkGraphOutArcList(G, n2, 3);
+ checkGraphOutArcList(G, n3, 0);
+
+ checkGraphInArcList(G, n1, 1);
+ checkGraphInArcList(G, n2, 1);
+ checkGraphInArcList(G, n3, 2);
+
+ checkGraphConArcList(G, 4);
+
+ checkNodeIds(G);
+ checkArcIds(G);
+ checkGraphNodeMap(G);
+ checkGraphArcMap(G);
+
+}
+
+
+void checkConcepts() {
{ // Checking digraph components
checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
@@ -51,27 +102,23 @@
checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
checkConcept<ClearableDigraphComponent<>, ListDigraph>();
checkConcept<ErasableDigraphComponent<>, ListDigraph>();
- checkDigraphIterators<ListDigraph>();
}
{ // Checking SmartDigraph
checkConcept<Digraph, SmartDigraph>();
More information about the Lemon-commits
mailing list