klao@946: // -*- c++ -*- klao@946: klao@946: #include klao@946: #include klao@946: klao@977: #include klao@977: klao@946: #include klao@946: #include klao@946: #include klao@946: klao@946: #include "test_tools.h" klao@946: #include "graph_utils_test.h" klao@946: klao@946: klao@946: using namespace lemon; klao@946: alpar@1459: template alpar@1459: void checkSnapDeg() alpar@1459: { alpar@1459: Graph g; alpar@1459: typename Graph::Node n1=g.addNode(); alpar@1459: typename Graph::Node n2=g.addNode(); alpar@1459: alpar@1459: InDegMap ind(g); alpar@1459: alpar@1459: g.addEdge(n1,n2); alpar@1459: alpar@1459: typename Graph::SnapShot snap(g); alpar@1459: alpar@1459: OutDegMap outd(g); alpar@1459: alpar@1459: check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value."); alpar@1459: check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value."); alpar@1459: alpar@1459: g.addEdge(n1,n2); alpar@1459: g.addEdge(n2,n1); alpar@1459: alpar@1459: check(ind[n1]==1 && ind[n2]==2, "Wrong InDegMap value."); alpar@1459: check(outd[n1]==2 && outd[n2]==1, "Wrong OutDegMap value."); alpar@1459: alpar@1459: snap.restore(); alpar@1459: alpar@1459: check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value."); alpar@1459: check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value."); alpar@1459: alpar@1459: } klao@946: klao@946: int main() { klao@946: ///\file klao@946: { // checking list graph klao@946: checkGraphCounters(); deba@1568: checkFindEdge(); klao@946: } klao@946: { // checking smart graph klao@946: checkGraphCounters(); deba@1568: checkFindEdge(); klao@946: } klao@977: { klao@977: int num = 5; klao@977: FullGraph fg(num); klao@977: check(countNodes(fg) == num, "FullGraph: wrong node number."); deba@1568: check(countEdges(fg) == num*num, "FullGraph: wrong edge number."); deba@1568: for (FullGraph::NodeIt src(fg); src != INVALID; ++src) { deba@1568: for (FullGraph::NodeIt trg(fg); trg != INVALID; ++trg) { deba@1568: ConEdgeIt con(fg, src, trg); deba@1568: check(con != INVALID, "There is no connecting edge."); deba@1568: check(fg.source(con) == src, "Wrong source."); deba@1568: check(fg.target(con) == trg, "Wrong target."); deba@1568: check(++con == INVALID, "There is more connecting edge."); deba@1568: } deba@1568: } klao@977: } klao@946: alpar@1459: //check In/OutDegMap (and SnapShot feature) alpar@1459: alpar@1459: checkSnapDeg(); alpar@1459: checkSnapDeg(); alpar@1459: deba@1728: { deba@1728: const int nodeNum = 10; deba@1728: const int edgeNum = 100; deba@1728: ListGraph graph; deba@1728: InDegMap inDeg(graph); deba@1728: std::vector nodes(nodeNum); deba@1728: for (int i = 0; i < nodeNum; ++i) { deba@1728: nodes[i] = graph.addNode(); deba@1728: } deba@1728: std::vector edges(edgeNum); deba@1728: for (int i = 0; i < edgeNum; ++i) { deba@1728: edges[i] = deba@1728: graph.addEdge(nodes[urandom(nodeNum)], nodes[urandom(nodeNum)]); deba@1728: } deba@1728: for (int i = 0; i < nodeNum; ++i) { deba@1728: check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]), deba@1728: "Wrong in degree map"); deba@1728: } deba@1728: for (int i = 0; i < edgeNum; ++i) { deba@1728: graph.changeTarget(edges[i], nodes[urandom(nodeNum)]); deba@1728: } deba@1728: for (int i = 0; i < nodeNum; ++i) { deba@1728: check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]), deba@1728: "Wrong in degree map"); deba@1728: } deba@1728: for (int i = 0; i < edgeNum; ++i) { deba@1728: graph.changeSource(edges[i], nodes[urandom(nodeNum)]); deba@1728: } deba@1728: for (int i = 0; i < nodeNum; ++i) { deba@1728: check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]), deba@1728: "Wrong in degree map"); deba@1728: } deba@1728: for (int i = 0; i < edgeNum; ++i) { deba@1728: graph.reverseEdge(edges[i]); deba@1728: } deba@1728: for (int i = 0; i < nodeNum; ++i) { deba@1728: check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]), deba@1728: "Wrong in degree map"); deba@1728: } deba@1728: } alpar@1459: alpar@1459: ///Everything is OK klao@946: std::cout << __FILE__ ": All tests passed.\n"; klao@946: klao@946: return 0; klao@946: }