/* -*- C++ -*- * * This file is a part of LEMON, a generic C++ optimization library * * Copyright (C) 2003-2006 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). * * Permission to use, modify and distribute this software is granted * provided that this copyright notice appears in all copies. For * precise terms see the accompanying LICENSE file. * * This software is provided "AS IS" with no warranty of any kind, * express or implied, and with no claim as to its suitability for any * purpose. * */ #include #include #include #include #include #include #include "test_tools.h" #include "graph_utils_test.h" using namespace lemon; template void checkSnapDeg() { Graph g; typename Graph::Node n1=g.addNode(); typename Graph::Node n2=g.addNode(); InDegMap ind(g); g.addEdge(n1,n2); typename Graph::Snapshot snap(g); OutDegMap outd(g); check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value."); check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value."); g.addEdge(n1,n2); g.addEdge(n2,n1); check(ind[n1]==1 && ind[n2]==2, "Wrong InDegMap value."); check(outd[n1]==2 && outd[n2]==1, "Wrong OutDegMap value."); snap.restore(); check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value."); check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value."); } int main() { ///\file { // checking list graph checkGraphCounters(); checkFindEdge(); } { // checking smart graph checkGraphCounters(); checkFindEdge(); } { int num = 5; FullGraph fg(num); check(countNodes(fg) == num, "FullGraph: wrong node number."); check(countEdges(fg) == num*num, "FullGraph: wrong edge number."); for (FullGraph::NodeIt src(fg); src != INVALID; ++src) { for (FullGraph::NodeIt trg(fg); trg != INVALID; ++trg) { ConEdgeIt con(fg, src, trg); check(con != INVALID, "There is no connecting edge."); check(fg.source(con) == src, "Wrong source."); check(fg.target(con) == trg, "Wrong target."); check(++con == INVALID, "There is more connecting edge."); } } } //check In/OutDegMap (and Snapshot feature) checkSnapDeg(); checkSnapDeg(); { const int nodeNum = 10; const int edgeNum = 100; ListGraph graph; InDegMap inDeg(graph); OutDegMap outDeg(graph); std::vector nodes(nodeNum); for (int i = 0; i < nodeNum; ++i) { nodes[i] = graph.addNode(); } std::vector edges(edgeNum); for (int i = 0; i < edgeNum; ++i) { edges[i] = graph.addEdge(nodes[urandom(nodeNum)], nodes[urandom(nodeNum)]); } for (int i = 0; i < nodeNum; ++i) { check(inDeg[nodes[i]] == countInEdges(graph, nodes[i]), "Wrong in degree map"); } for (int i = 0; i < nodeNum; ++i) { check(outDeg[nodes[i]] == countOutEdges(graph, nodes[i]), "Wrong in degree map"); } } ///Everything is OK std::cout << __FILE__ ": All tests passed.\n"; return 0; }