1.1 --- a/test/arborescence_test.cc Mon Aug 14 15:18:09 2006 +0000
1.2 +++ b/test/arborescence_test.cc Mon Aug 14 16:08:28 2006 +0000
1.3 @@ -14,19 +14,45 @@
1.4
1.5 #include <lemon/tolerance.h>
1.6
1.7 +#include "test_tools.h"
1.8 +
1.9 using namespace lemon;
1.10 using namespace std;
1.11
1.12 -int main(int argc, const char *argv[]) {
1.13 +const int n = 10;
1.14 +const int e = 22;
1.15 +
1.16 +int sourceNode = 0;
1.17 +
1.18 +int sources[e] = {
1.19 + 1, 0, 2, 4, 4, 3, 9, 8, 9, 8,
1.20 + 4, 2, 0, 6, 4, 1, 7, 2, 8, 6,
1.21 + 1, 0
1.22 +};
1.23 +
1.24 +int targets[e] = {
1.25 + 8, 3, 1, 1, 4, 9, 8, 1, 8, 0,
1.26 + 3, 2, 1, 3, 1, 1, 2, 6, 3, 9,
1.27 + 1, 3
1.28 +};
1.29 +
1.30 +double costs[e] = {
1.31 + 107.444, 70.3069, 46.0496, 28.3962, 91.4325,
1.32 + 76.9443, 61.986, 39.3754, 74.9575, 39.3153,
1.33 + 45.7094, 34.6184, 100.156, 95.726, 22.3429,
1.34 + 31.587, 51.6972, 29.6773, 115.038, 32.4137,
1.35 + 60.0038, 40.1237
1.36 +};
1.37 +
1.38 +
1.39 +
1.40 +int main() {
1.41 srand(time(0));
1.42 typedef SmartGraph Graph;
1.43 GRAPH_TYPEDEFS(Graph);
1.44
1.45 typedef Graph::EdgeMap<double> CostMap;
1.46
1.47 - const int n = argc > 1 ? atoi(argv[1]) : 100;
1.48 - const int e = argc > 2 ? atoi(argv[2]) : (int)(n * log(n));
1.49 -
1.50 Graph graph;
1.51 CostMap cost(graph);
1.52 vector<Node> nodes;
1.53 @@ -36,14 +62,11 @@
1.54 }
1.55
1.56 for (int i = 0; i < e; ++i) {
1.57 - int s = (int)(n * (double)rand() / (RAND_MAX + 1.0));
1.58 - int t = (int)(n * (double)rand() / (RAND_MAX + 1.0));
1.59 - double c = rand() / (1.0 + RAND_MAX) * 100.0 + 20.0;
1.60 - Edge edge = graph.addEdge(nodes[s], nodes[t]);
1.61 - cost[edge] = c;
1.62 + Edge edge = graph.addEdge(nodes[sources[i]], nodes[targets[i]]);
1.63 + cost[edge] = costs[i];
1.64 }
1.65
1.66 - Node source = nodes[(int)(n * (double)rand() / (RAND_MAX + 1.0))];
1.67 + Node source = nodes[sourceNode];
1.68
1.69 MinCostArborescence<Graph, CostMap> mca(graph, cost);
1.70 mca.run(source);
1.71 @@ -72,20 +95,20 @@
1.72 }
1.73 }
1.74 if (mca.arborescence(it)) {
1.75 - LEMON_ASSERT(!tolerance.less(sum, cost[it]), "INVALID DUAL");
1.76 + check(!tolerance.less(sum, cost[it]), "INVALID DUAL");
1.77 }
1.78 - LEMON_ASSERT(!tolerance.less(cost[it], sum), "INVALID DUAL");
1.79 + check(!tolerance.less(cost[it], sum), "INVALID DUAL");
1.80 }
1.81 }
1.82
1.83
1.84 - LEMON_ASSERT(!tolerance.different(mca.dualValue(), mca.arborescenceValue()),
1.85 + check(!tolerance.different(mca.dualValue(), mca.arborescenceValue()),
1.86 "INVALID DUAL");
1.87
1.88
1.89 - LEMON_ASSERT(mca.reached(source), "INVALID ARBORESCENCE");
1.90 + check(mca.reached(source), "INVALID ARBORESCENCE");
1.91 for (EdgeIt it(graph); it != INVALID; ++it) {
1.92 - LEMON_ASSERT(!mca.reached(graph.source(it)) ||
1.93 + check(!mca.reached(graph.source(it)) ||
1.94 mca.reached(graph.target(it)), "INVALID ARBORESCENCE");
1.95 }
1.96
1.97 @@ -97,7 +120,7 @@
1.98 ++cnt;
1.99 }
1.100 }
1.101 - LEMON_ASSERT((it == source ? cnt == 0 : cnt == 1), "INVALID ARBORESCENCE");
1.102 + check((it == source ? cnt == 0 : cnt == 1), "INVALID ARBORESCENCE");
1.103 }
1.104
1.105 return 0;