test/graph_utils_test.cc
changeset 1728 eb8bb91ba9e2
parent 1568 f694f75de683
child 1729 06f939455cb1
equal deleted inserted replaced
2:aca35f221c86 3:998732f5dd80
    75   //check In/OutDegMap (and SnapShot feature)
    75   //check In/OutDegMap (and SnapShot feature)
    76 
    76 
    77   checkSnapDeg<ListGraph>();
    77   checkSnapDeg<ListGraph>();
    78   checkSnapDeg<SmartGraph>();
    78   checkSnapDeg<SmartGraph>();
    79   
    79   
       
    80   {
       
    81     const int nodeNum = 10;
       
    82     const int edgeNum = 100;
       
    83     ListGraph graph;
       
    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();
       
    88     }
       
    89     std::vector<ListGraph::Edge> edges(edgeNum);
       
    90     for (int i = 0; i < edgeNum; ++i) {
       
    91       edges[i] = 
       
    92 	graph.addEdge(nodes[urandom(nodeNum)], nodes[urandom(nodeNum)]);
       
    93     }
       
    94     for (int i = 0; i < nodeNum; ++i) {
       
    95       check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]), 
       
    96 	    "Wrong in degree map");
       
    97     }
       
    98     for (int i = 0; i < edgeNum; ++i) {
       
    99       graph.changeTarget(edges[i], nodes[urandom(nodeNum)]);
       
   100     }
       
   101     for (int i = 0; i < nodeNum; ++i) {
       
   102       check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]),
       
   103 	    "Wrong in degree map");
       
   104     }
       
   105     for (int i = 0; i < edgeNum; ++i) {
       
   106       graph.changeSource(edges[i], nodes[urandom(nodeNum)]);
       
   107     }
       
   108     for (int i = 0; i < nodeNum; ++i) {
       
   109       check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]), 
       
   110 	    "Wrong in degree map");
       
   111     }
       
   112     for (int i = 0; i < edgeNum; ++i) {
       
   113       graph.reverseEdge(edges[i]);
       
   114     }
       
   115     for (int i = 0; i < nodeNum; ++i) {
       
   116       check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]), 
       
   117 	    "Wrong in degree map");
       
   118     }
       
   119   }
    80 
   120 
    81   ///Everything is OK
   121   ///Everything is OK
    82   std::cout << __FILE__ ": All tests passed.\n";
   122   std::cout << __FILE__ ": All tests passed.\n";
    83 
   123 
    84   return 0;
   124   return 0;