6 #include <lemon/graph_utils.h>
8 #include <lemon/list_graph.h>
9 #include <lemon/smart_graph.h>
10 #include <lemon/full_graph.h>
12 #include "test_tools.h"
13 #include "graph_utils_test.h"
16 using namespace lemon;
22 typename Graph::Node n1=g.addNode();
23 typename Graph::Node n2=g.addNode();
25 InDegMap<Graph> ind(g);
29 typename Graph::SnapShot snap(g);
31 OutDegMap<Graph> outd(g);
33 check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value.");
34 check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value.");
39 check(ind[n1]==1 && ind[n2]==2, "Wrong InDegMap value.");
40 check(outd[n1]==2 && outd[n2]==1, "Wrong OutDegMap value.");
44 check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value.");
45 check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value.");
51 { // checking list graph
52 checkGraphCounters<ListGraph>();
53 checkFindEdge<ListGraph>();
55 { // checking smart graph
56 checkGraphCounters<SmartGraph>();
57 checkFindEdge<SmartGraph>();
62 check(countNodes(fg) == num, "FullGraph: wrong node number.");
63 check(countEdges(fg) == num*num, "FullGraph: wrong edge number.");
64 for (FullGraph::NodeIt src(fg); src != INVALID; ++src) {
65 for (FullGraph::NodeIt trg(fg); trg != INVALID; ++trg) {
66 ConEdgeIt<FullGraph> con(fg, src, trg);
67 check(con != INVALID, "There is no connecting edge.");
68 check(fg.source(con) == src, "Wrong source.");
69 check(fg.target(con) == trg, "Wrong target.");
70 check(++con == INVALID, "There is more connecting edge.");
75 //check In/OutDegMap (and SnapShot feature)
77 checkSnapDeg<ListGraph>();
78 checkSnapDeg<SmartGraph>();
81 const int nodeNum = 10;
82 const int edgeNum = 100;
84 InDegMap<ListGraph> inDeg(graph);
85 std::vector<ListGraph::Node> nodes(nodeNum);
86 for (int i = 0; i < nodeNum; ++i) {
87 nodes[i] = graph.addNode();
89 std::vector<ListGraph::Edge> edges(edgeNum);
90 for (int i = 0; i < edgeNum; ++i) {
92 graph.addEdge(nodes[urandom(nodeNum)], nodes[urandom(nodeNum)]);
94 for (int i = 0; i < nodeNum; ++i) {
95 check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]),
96 "Wrong in degree map");
98 for (int i = 0; i < edgeNum; ++i) {
99 graph.changeTarget(edges[i], nodes[urandom(nodeNum)]);
101 for (int i = 0; i < nodeNum; ++i) {
102 check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]),
103 "Wrong in degree map");
105 for (int i = 0; i < edgeNum; ++i) {
106 graph.changeSource(edges[i], nodes[urandom(nodeNum)]);
108 for (int i = 0; i < nodeNum; ++i) {
109 check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]),
110 "Wrong in degree map");
112 for (int i = 0; i < edgeNum; ++i) {
113 graph.reverseEdge(edges[i]);
115 for (int i = 0; i < nodeNum; ++i) {
116 check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]),
117 "Wrong in degree map");
122 std::cout << __FILE__ ": All tests passed.\n";