1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/test/kruskal_test.cc Mon Sep 06 17:12:00 2004 +0000
1.3 @@ -0,0 +1,94 @@
1.4 +#include <iostream>
1.5 +#include <vector>
1.6 +
1.7 +#include "test_tools.h"
1.8 +#include <hugo/maps.h>
1.9 +#include <hugo/kruskal.h>
1.10 +#include <hugo/list_graph.h>
1.11 +#include <hugo/skeletons/maps.h>
1.12 +#include <hugo/skeletons/graph.h>
1.13 +
1.14 +
1.15 +using namespace std;
1.16 +using namespace hugo;
1.17 +
1.18 +void checkCompileKruskal()
1.19 +{
1.20 + skeleton::WriteMap<skeleton::StaticGraphSkeleton::Edge,bool> w;
1.21 +
1.22 + kruskalEdgeMap(skeleton::StaticGraphSkeleton(),
1.23 + skeleton::ReadMap<skeleton::StaticGraphSkeleton::Edge,int>(),
1.24 + w);
1.25 +}
1.26 +
1.27 +int main() {
1.28 +
1.29 + typedef ListGraph::Node Node;
1.30 + typedef ListGraph::Edge Edge;
1.31 + typedef ListGraph::NodeIt NodeIt;
1.32 + typedef ListGraph::EdgeIt EdgeIt;
1.33 +
1.34 + ListGraph G;
1.35 +
1.36 + Node s=G.addNode();
1.37 + Node v1=G.addNode();
1.38 + Node v2=G.addNode();
1.39 + Node v3=G.addNode();
1.40 + Node v4=G.addNode();
1.41 + Node t=G.addNode();
1.42 +
1.43 + Edge e1 = G.addEdge(s, v1);
1.44 + Edge e2 = G.addEdge(s, v2);
1.45 + Edge e3 = G.addEdge(v1, v2);
1.46 + Edge e4 = G.addEdge(v2, v1);
1.47 + Edge e5 = G.addEdge(v1, v3);
1.48 + Edge e6 = G.addEdge(v3, v2);
1.49 + Edge e7 = G.addEdge(v2, v4);
1.50 + Edge e8 = G.addEdge(v4, v3);
1.51 + Edge e9 = G.addEdge(v3, t);
1.52 + Edge e10 = G.addEdge(v4, t);
1.53 +
1.54 + typedef ListGraph::EdgeMap<int> ECostMap;
1.55 + typedef ListGraph::EdgeMap<bool> EBoolMap;
1.56 +
1.57 + ECostMap edge_cost_map(G, 2);
1.58 + EBoolMap tree_map(G);
1.59 +
1.60 +
1.61 + //Test with const map.
1.62 + check(kruskalEdgeMap(G, ConstMap<ListGraph::Edge,int>(2), tree_map)==10,
1.63 + "Total cost should be 10");
1.64 + //Test with a edge map (filled with uniform costs).
1.65 + check(kruskalEdgeMap(G, edge_cost_map, tree_map)==10,
1.66 + "Total cost should be 10");
1.67 +
1.68 + edge_cost_map.set(e1, -10);
1.69 + edge_cost_map.set(e2, -9);
1.70 + edge_cost_map.set(e3, -8);
1.71 + edge_cost_map.set(e4, -7);
1.72 + edge_cost_map.set(e5, -6);
1.73 + edge_cost_map.set(e6, -5);
1.74 + edge_cost_map.set(e7, -4);
1.75 + edge_cost_map.set(e8, -3);
1.76 + edge_cost_map.set(e9, -2);
1.77 + edge_cost_map.set(e10, -1);
1.78 +
1.79 + vector<Edge> tree_edge_vec;
1.80 +
1.81 + //Test with a edge map and inserter.
1.82 + check(kruskalEdgeMap_IteratorOut(G, edge_cost_map,
1.83 + back_inserter(tree_edge_vec))
1.84 + ==-31,
1.85 + "Total cost should be -31.");
1.86 +
1.87 + check(tree_edge_vec.size()==5,"The tree should have 5 edges.");
1.88 +
1.89 + check(tree_edge_vec[0]==e1 &&
1.90 + tree_edge_vec[1]==e2 &&
1.91 + tree_edge_vec[2]==e5 &&
1.92 + tree_edge_vec[3]==e7 &&
1.93 + tree_edge_vec[4]==e9,
1.94 + "Wrong tree.");
1.95 +
1.96 + return 0;
1.97 +}