alpar@1956: /* -*- C++ -*- alpar@1956: * alpar@1956: * This file is a part of LEMON, a generic C++ optimization library alpar@1956: * alpar@2553: * Copyright (C) 2003-2008 alpar@1956: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1956: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@1956: * alpar@1956: * Permission to use, modify and distribute this software is granted alpar@1956: * provided that this copyright notice appears in all copies. For alpar@1956: * precise terms see the accompanying LICENSE file. alpar@1956: * alpar@1956: * This software is provided "AS IS" with no warranty of any kind, alpar@1956: * express or implied, and with no claim as to its suitability for any alpar@1956: * purpose. alpar@1956: * alpar@1956: */ 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@1772: 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: } alpar@2236: AllEdgeLookUp el(fg); alpar@2236: for (FullGraph::NodeIt src(fg); src != INVALID; ++src) { alpar@2236: for (FullGraph::NodeIt trg(fg); trg != INVALID; ++trg) { alpar@2236: FullGraph::Edge con = el(src, trg); alpar@2236: check(con != INVALID, "There is no connecting edge."); alpar@2236: check(fg.source(con) == src, "Wrong source."); alpar@2236: check(fg.target(con) == trg, "Wrong target."); alpar@2236: check(el(src,trg,con) == INVALID, "There is more connecting edge."); alpar@2236: } alpar@2236: } klao@977: } klao@946: alpar@1772: //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@1729: OutDegMap outDeg(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@2242: graph.addEdge(nodes[rnd[nodeNum]], nodes[rnd[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 < nodeNum; ++i) { deba@1729: check(outDeg[nodes[i]] == countOutEdges(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: }