test/graph_utils_test.cc
changeset 1758 4bfe670710e0
parent 1728 eb8bb91ba9e2
child 1772 dd1e0c442fe0
equal deleted inserted replaced
3:998732f5dd80 4:8eee35ffa4d4
    80   {
    80   {
    81     const int nodeNum = 10;
    81     const int nodeNum = 10;
    82     const int edgeNum = 100;
    82     const int edgeNum = 100;
    83     ListGraph graph;
    83     ListGraph graph;
    84     InDegMap<ListGraph> inDeg(graph);
    84     InDegMap<ListGraph> inDeg(graph);
       
    85     OutDegMap<ListGraph> outDeg(graph);
    85     std::vector<ListGraph::Node> nodes(nodeNum);
    86     std::vector<ListGraph::Node> nodes(nodeNum);
    86     for (int i = 0; i < nodeNum; ++i) {
    87     for (int i = 0; i < nodeNum; ++i) {
    87       nodes[i] = graph.addNode();
    88       nodes[i] = graph.addNode();
    88     }
    89     }
    89     std::vector<ListGraph::Edge> edges(edgeNum);
    90     std::vector<ListGraph::Edge> edges(edgeNum);
    93     }
    94     }
    94     for (int i = 0; i < nodeNum; ++i) {
    95     for (int i = 0; i < nodeNum; ++i) {
    95       check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]), 
    96       check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]), 
    96 	    "Wrong in degree map");
    97 	    "Wrong in degree map");
    97     }
    98     }
    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) {
    99     for (int i = 0; i < nodeNum; ++i) {
   102       check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]),
   100       check(outDeg[nodes[i]] == countOutEdges(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");
   101 	    "Wrong in degree map");
   118     }
   102     }
   119   }
   103   }
   120 
   104 
   121   ///Everything is OK
   105   ///Everything is OK