alpar@209: /* -*- mode: C++; indent-tabs-mode: nil; -*- deba@57: * alpar@209: * This file is a part of LEMON, a generic C++ optimization library. deba@57: * alpar@107: * Copyright (C) 2003-2008 deba@57: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport deba@57: * (Egervary Research Group on Combinatorial Optimization, EGRES). deba@57: * deba@57: * Permission to use, modify and distribute this software is granted deba@57: * provided that this copyright notice appears in all copies. For deba@57: * precise terms see the accompanying LICENSE file. deba@57: * deba@57: * This software is provided "AS IS" with no warranty of any kind, deba@57: * express or implied, and with no claim as to its suitability for any deba@57: * purpose. deba@57: * deba@57: */ deba@57: deba@57: #include deba@57: #include kpeter@171: #include deba@353: #include deba@57: //#include deba@57: deba@57: #include "test_tools.h" kpeter@171: #include "graph_test.h" deba@57: deba@57: using namespace lemon; deba@57: using namespace lemon::concepts; deba@57: deba@228: template deba@228: void checkDigraph() { deba@228: TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); deba@228: Digraph G; deba@228: deba@228: checkGraphNodeList(G, 0); deba@228: checkGraphArcList(G, 0); deba@228: deba@228: Node deba@228: n1 = G.addNode(), deba@228: n2 = G.addNode(), deba@228: n3 = G.addNode(); deba@228: checkGraphNodeList(G, 3); deba@228: checkGraphArcList(G, 0); deba@228: deba@228: Arc a1 = G.addArc(n1, n2); deba@228: check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc"); deba@228: checkGraphNodeList(G, 3); deba@228: checkGraphArcList(G, 1); deba@228: deba@228: checkGraphOutArcList(G, n1, 1); deba@228: checkGraphOutArcList(G, n2, 0); deba@228: checkGraphOutArcList(G, n3, 0); deba@228: deba@228: checkGraphInArcList(G, n1, 0); deba@228: checkGraphInArcList(G, n2, 1); deba@228: checkGraphInArcList(G, n3, 0); deba@228: deba@228: checkGraphConArcList(G, 1); deba@228: deba@228: Arc a2 = G.addArc(n2, n1), a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3); deba@228: checkGraphNodeList(G, 3); deba@228: checkGraphArcList(G, 4); deba@228: deba@228: checkGraphOutArcList(G, n1, 1); deba@228: checkGraphOutArcList(G, n2, 3); deba@228: checkGraphOutArcList(G, n3, 0); deba@228: deba@228: checkGraphInArcList(G, n1, 1); deba@228: checkGraphInArcList(G, n2, 1); deba@228: checkGraphInArcList(G, n3, 2); deba@228: deba@228: checkGraphConArcList(G, 4); deba@228: deba@228: checkNodeIds(G); deba@228: checkArcIds(G); deba@228: checkGraphNodeMap(G); deba@228: checkGraphArcMap(G); deba@228: deba@228: } deba@228: deba@353: void checkFullDigraph(int num) { deba@353: typedef FullDigraph Digraph; deba@353: DIGRAPH_TYPEDEFS(Digraph); deba@353: Digraph G(num); deba@353: deba@353: checkGraphNodeList(G, num); deba@353: checkGraphArcList(G, num * num); deba@353: deba@353: for (NodeIt n(G); n != INVALID; ++n) { deba@353: checkGraphOutArcList(G, n, num); deba@353: checkGraphInArcList(G, n, num); deba@353: } deba@353: deba@353: checkGraphConArcList(G, num * num); deba@353: deba@353: checkNodeIds(G); deba@353: checkArcIds(G); deba@353: checkGraphNodeMap(G); deba@353: checkGraphArcMap(G); deba@353: deba@353: for (int i = 0; i < G.nodeNum(); ++i) { deba@353: check(G.index(G(i)) == i, "Wrong index"); deba@353: } deba@353: deba@353: for (NodeIt s(G); s != INVALID; ++s) { deba@353: for (NodeIt t(G); t != INVALID; ++t) { deba@353: Arc a = G.arc(s, t); deba@353: check(G.source(a) == s && G.target(a) == t, "Wrong arc lookup"); deba@353: } deba@353: } deba@353: deba@353: } deba@353: deba@228: deba@228: void checkConcepts() { kpeter@171: { // Checking digraph components deba@57: checkConcept(); deba@57: alpar@209: checkConcept, deba@57: IDableDigraphComponent<> >(); deba@57: alpar@209: checkConcept, deba@57: IterableDigraphComponent<> >(); deba@57: alpar@209: checkConcept, deba@57: MappableDigraphComponent<> >(); deba@57: } kpeter@171: { // Checking skeleton digraph deba@57: checkConcept(); deba@57: } kpeter@171: { // Checking ListDigraph kpeter@171: checkConcept(); deba@57: checkConcept, ListDigraph>(); deba@57: checkConcept, ListDigraph>(); deba@57: checkConcept, ListDigraph>(); deba@57: checkConcept, ListDigraph>(); kpeter@171: } kpeter@171: { // Checking SmartDigraph kpeter@171: checkConcept(); kpeter@171: checkConcept, SmartDigraph>(); kpeter@171: checkConcept, SmartDigraph>(); kpeter@171: checkConcept, SmartDigraph>(); kpeter@171: } kpeter@354: { // Checking FullDigraph kpeter@354: checkConcept(); kpeter@354: } kpeter@171: // { // Checking HyperCubeDigraph kpeter@171: // checkConcept(); kpeter@171: // } kpeter@171: } deba@57: kpeter@171: template deba@228: void checkDigraphValidity() { kpeter@171: TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); kpeter@171: Digraph g; kpeter@171: kpeter@171: Node kpeter@171: n1 = g.addNode(), kpeter@171: n2 = g.addNode(), kpeter@171: n3 = g.addNode(); kpeter@171: kpeter@171: Arc kpeter@171: e1 = g.addArc(n1, n2), kpeter@171: e2 = g.addArc(n2, n3); kpeter@171: kpeter@171: check(g.valid(n1), "Wrong validity check"); kpeter@171: check(g.valid(e1), "Wrong validity check"); kpeter@171: kpeter@171: check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); kpeter@171: check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); kpeter@171: } kpeter@171: kpeter@171: template deba@228: void checkDigraphValidityErase() { kpeter@171: TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); kpeter@171: Digraph g; kpeter@171: kpeter@171: Node kpeter@171: n1 = g.addNode(), kpeter@171: n2 = g.addNode(), kpeter@171: n3 = g.addNode(); kpeter@171: kpeter@171: Arc kpeter@171: e1 = g.addArc(n1, n2), kpeter@171: e2 = g.addArc(n2, n3); kpeter@171: kpeter@171: check(g.valid(n1), "Wrong validity check"); kpeter@171: check(g.valid(e1), "Wrong validity check"); kpeter@171: kpeter@171: g.erase(n1); kpeter@171: kpeter@171: check(!g.valid(n1), "Wrong validity check"); kpeter@171: check(g.valid(n2), "Wrong validity check"); kpeter@171: check(g.valid(n3), "Wrong validity check"); kpeter@171: check(!g.valid(e1), "Wrong validity check"); kpeter@171: check(g.valid(e2), "Wrong validity check"); kpeter@171: kpeter@171: check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); kpeter@171: check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); kpeter@171: } kpeter@171: deba@228: void checkDigraphs() { kpeter@171: { // Checking ListDigraph deba@57: checkDigraph(); deba@228: checkDigraphValidityErase(); deba@57: } kpeter@171: { // Checking SmartDigraph kpeter@171: checkDigraph(); deba@228: checkDigraphValidity(); kpeter@171: } deba@353: { // Checking FullDigraph deba@353: checkFullDigraph(8); deba@353: } kpeter@171: } deba@57: kpeter@171: int main() { deba@228: checkDigraphs(); deba@228: checkConcepts(); deba@57: return 0; deba@57: }