test/digraph_test.cc
changeset 261 1c2ac7deb5d8
parent 209 765619b7cbb2
child 338 49d9a36b3b84
equal deleted inserted replaced
3:da48e14e9222 4:db88099cfdc8
    22 //#include <lemon/full_graph.h>
    22 //#include <lemon/full_graph.h>
    23 //#include <lemon/hypercube_graph.h>
    23 //#include <lemon/hypercube_graph.h>
    24 
    24 
    25 #include "test_tools.h"
    25 #include "test_tools.h"
    26 #include "graph_test.h"
    26 #include "graph_test.h"
    27 #include "graph_maps_test.h"
       
    28 
    27 
    29 using namespace lemon;
    28 using namespace lemon;
    30 using namespace lemon::concepts;
    29 using namespace lemon::concepts;
    31 
    30 
    32 void check_concepts() {
    31 template <class Digraph>
       
    32 void checkDigraph() {
       
    33   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
       
    34   Digraph G;
       
    35 
       
    36   checkGraphNodeList(G, 0);
       
    37   checkGraphArcList(G, 0);
       
    38 
       
    39   Node
       
    40     n1 = G.addNode(),
       
    41     n2 = G.addNode(),
       
    42     n3 = G.addNode();
       
    43   checkGraphNodeList(G, 3);
       
    44   checkGraphArcList(G, 0);
       
    45 
       
    46   Arc a1 = G.addArc(n1, n2);
       
    47   check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc");
       
    48   checkGraphNodeList(G, 3);
       
    49   checkGraphArcList(G, 1);
       
    50 
       
    51   checkGraphOutArcList(G, n1, 1);
       
    52   checkGraphOutArcList(G, n2, 0);
       
    53   checkGraphOutArcList(G, n3, 0);
       
    54 
       
    55   checkGraphInArcList(G, n1, 0);
       
    56   checkGraphInArcList(G, n2, 1);
       
    57   checkGraphInArcList(G, n3, 0);
       
    58 
       
    59   checkGraphConArcList(G, 1);
       
    60 
       
    61   Arc a2 = G.addArc(n2, n1), a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
       
    62   checkGraphNodeList(G, 3);
       
    63   checkGraphArcList(G, 4);
       
    64 
       
    65   checkGraphOutArcList(G, n1, 1);
       
    66   checkGraphOutArcList(G, n2, 3);
       
    67   checkGraphOutArcList(G, n3, 0);
       
    68 
       
    69   checkGraphInArcList(G, n1, 1);
       
    70   checkGraphInArcList(G, n2, 1);
       
    71   checkGraphInArcList(G, n3, 2);
       
    72 
       
    73   checkGraphConArcList(G, 4);
       
    74 
       
    75   checkNodeIds(G);
       
    76   checkArcIds(G);
       
    77   checkGraphNodeMap(G);
       
    78   checkGraphArcMap(G);
       
    79 
       
    80 }
       
    81 
       
    82 
       
    83 void checkConcepts() {
    33   { // Checking digraph components
    84   { // Checking digraph components
    34     checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
    85     checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
    35 
    86 
    36     checkConcept<IDableDigraphComponent<>,
    87     checkConcept<IDableDigraphComponent<>,
    37       IDableDigraphComponent<> >();
    88       IDableDigraphComponent<> >();
    49     checkConcept<Digraph, ListDigraph>();
   100     checkConcept<Digraph, ListDigraph>();
    50     checkConcept<AlterableDigraphComponent<>, ListDigraph>();
   101     checkConcept<AlterableDigraphComponent<>, ListDigraph>();
    51     checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
   102     checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
    52     checkConcept<ClearableDigraphComponent<>, ListDigraph>();
   103     checkConcept<ClearableDigraphComponent<>, ListDigraph>();
    53     checkConcept<ErasableDigraphComponent<>, ListDigraph>();
   104     checkConcept<ErasableDigraphComponent<>, ListDigraph>();
    54     checkDigraphIterators<ListDigraph>();
       
    55   }
   105   }
    56   { // Checking SmartDigraph
   106   { // Checking SmartDigraph
    57     checkConcept<Digraph, SmartDigraph>();
   107     checkConcept<Digraph, SmartDigraph>();
    58     checkConcept<AlterableDigraphComponent<>, SmartDigraph>();
   108     checkConcept<AlterableDigraphComponent<>, SmartDigraph>();
    59     checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
   109     checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
    60     checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
   110     checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
    61     checkDigraphIterators<SmartDigraph>();
       
    62   }
   111   }
    63 //  { // Checking FullDigraph
   112 //  { // Checking FullDigraph
    64 //    checkConcept<Digraph, FullDigraph>();
   113 //    checkConcept<Digraph, FullDigraph>();
    65 //    checkDigraphIterators<FullDigraph>();
       
    66 //  }
   114 //  }
    67 //  { // Checking HyperCubeDigraph
   115 //  { // Checking HyperCubeDigraph
    68 //    checkConcept<Digraph, HyperCubeDigraph>();
   116 //    checkConcept<Digraph, HyperCubeDigraph>();
    69 //    checkDigraphIterators<HyperCubeDigraph>();
       
    70 //  }
   117 //  }
    71 }
   118 }
    72 
   119 
    73 template <typename Digraph>
   120 template <typename Digraph>
    74 void check_graph_validity() {
   121 void checkDigraphValidity() {
    75   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
   122   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    76   Digraph g;
   123   Digraph g;
    77 
   124 
    78   Node
   125   Node
    79     n1 = g.addNode(),
   126     n1 = g.addNode(),
    90   check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
   137   check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
    91   check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
   138   check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
    92 }
   139 }
    93 
   140 
    94 template <typename Digraph>
   141 template <typename Digraph>
    95 void check_graph_validity_erase() {
   142 void checkDigraphValidityErase() {
    96   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
   143   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    97   Digraph g;
   144   Digraph g;
    98 
   145 
    99   Node
   146   Node
   100     n1 = g.addNode(),
   147     n1 = g.addNode(),
   118 
   165 
   119   check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
   166   check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
   120   check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
   167   check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
   121 }
   168 }
   122 
   169 
   123 void check_digraphs() {
   170 void checkDigraphs() {
   124   { // Checking ListDigraph
   171   { // Checking ListDigraph
   125     checkDigraph<ListDigraph>();
   172     checkDigraph<ListDigraph>();
   126     checkGraphNodeMap<ListDigraph>();
   173     checkDigraphValidityErase<ListDigraph>();
   127     checkGraphArcMap<ListDigraph>();
       
   128 
       
   129     check_graph_validity_erase<ListDigraph>();
       
   130   }
   174   }
   131   { // Checking SmartDigraph
   175   { // Checking SmartDigraph
   132     checkDigraph<SmartDigraph>();
   176     checkDigraph<SmartDigraph>();
   133     checkGraphNodeMap<SmartDigraph>();
   177     checkDigraphValidity<SmartDigraph>();
   134     checkGraphArcMap<SmartDigraph>();
       
   135 
       
   136     check_graph_validity<SmartDigraph>();
       
   137   }
   178   }
   138 }
   179 }
   139 
   180 
   140 int main() {
   181 int main() {
   141   check_concepts();
   182   checkDigraphs();
   142   check_digraphs();
   183   checkConcepts();
   143   return 0;
   184   return 0;
   144 }
   185 }