diff -r a3bb30be417c -r d5544c9409e4 test/arborescence_test.cc --- a/test/arborescence_test.cc Mon Aug 14 15:18:09 2006 +0000 +++ b/test/arborescence_test.cc Mon Aug 14 16:08:28 2006 +0000 @@ -14,19 +14,45 @@ #include +#include "test_tools.h" + using namespace lemon; using namespace std; -int main(int argc, const char *argv[]) { +const int n = 10; +const int e = 22; + +int sourceNode = 0; + +int sources[e] = { + 1, 0, 2, 4, 4, 3, 9, 8, 9, 8, + 4, 2, 0, 6, 4, 1, 7, 2, 8, 6, + 1, 0 +}; + +int targets[e] = { + 8, 3, 1, 1, 4, 9, 8, 1, 8, 0, + 3, 2, 1, 3, 1, 1, 2, 6, 3, 9, + 1, 3 +}; + +double costs[e] = { + 107.444, 70.3069, 46.0496, 28.3962, 91.4325, + 76.9443, 61.986, 39.3754, 74.9575, 39.3153, + 45.7094, 34.6184, 100.156, 95.726, 22.3429, + 31.587, 51.6972, 29.6773, 115.038, 32.4137, + 60.0038, 40.1237 +}; + + + +int main() { srand(time(0)); typedef SmartGraph Graph; GRAPH_TYPEDEFS(Graph); typedef Graph::EdgeMap CostMap; - const int n = argc > 1 ? atoi(argv[1]) : 100; - const int e = argc > 2 ? atoi(argv[2]) : (int)(n * log(n)); - Graph graph; CostMap cost(graph); vector nodes; @@ -36,14 +62,11 @@ } for (int i = 0; i < e; ++i) { - int s = (int)(n * (double)rand() / (RAND_MAX + 1.0)); - int t = (int)(n * (double)rand() / (RAND_MAX + 1.0)); - double c = rand() / (1.0 + RAND_MAX) * 100.0 + 20.0; - Edge edge = graph.addEdge(nodes[s], nodes[t]); - cost[edge] = c; + Edge edge = graph.addEdge(nodes[sources[i]], nodes[targets[i]]); + cost[edge] = costs[i]; } - Node source = nodes[(int)(n * (double)rand() / (RAND_MAX + 1.0))]; + Node source = nodes[sourceNode]; MinCostArborescence mca(graph, cost); mca.run(source); @@ -72,20 +95,20 @@ } } if (mca.arborescence(it)) { - LEMON_ASSERT(!tolerance.less(sum, cost[it]), "INVALID DUAL"); + check(!tolerance.less(sum, cost[it]), "INVALID DUAL"); } - LEMON_ASSERT(!tolerance.less(cost[it], sum), "INVALID DUAL"); + check(!tolerance.less(cost[it], sum), "INVALID DUAL"); } } - LEMON_ASSERT(!tolerance.different(mca.dualValue(), mca.arborescenceValue()), + check(!tolerance.different(mca.dualValue(), mca.arborescenceValue()), "INVALID DUAL"); - LEMON_ASSERT(mca.reached(source), "INVALID ARBORESCENCE"); + check(mca.reached(source), "INVALID ARBORESCENCE"); for (EdgeIt it(graph); it != INVALID; ++it) { - LEMON_ASSERT(!mca.reached(graph.source(it)) || + check(!mca.reached(graph.source(it)) || mca.reached(graph.target(it)), "INVALID ARBORESCENCE"); } @@ -97,7 +120,7 @@ ++cnt; } } - LEMON_ASSERT((it == source ? cnt == 0 : cnt == 1), "INVALID ARBORESCENCE"); + check((it == source ? cnt == 0 : cnt == 1), "INVALID ARBORESCENCE"); } return 0;