test/digraph_test.cc
changeset 189 a63ed81c57ba
parent 107 31a2e6d28f61
child 209 765619b7cbb2
equal deleted inserted replaced
1:77b3599bee9e 2:c91e35ba2876
    14  * express or implied, and with no claim as to its suitability for any
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    15  * purpose.
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 #include <iostream>
       
    20 #include <vector>
       
    21 
       
    22 #include <lemon/concepts/digraph.h>
    19 #include <lemon/concepts/digraph.h>
    23 #include <lemon/list_graph.h>
    20 #include <lemon/list_graph.h>
    24 //#include <lemon/smart_graph.h>
    21 #include <lemon/smart_graph.h>
    25 //#include <lemon/full_graph.h>
    22 //#include <lemon/full_graph.h>
    26 //#include <lemon/hypercube_graph.h>
    23 //#include <lemon/hypercube_graph.h>
    27 
    24 
    28 #include "test_tools.h"
    25 #include "test_tools.h"
    29 #include "digraph_test.h"
    26 #include "graph_test.h"
    30 #include "map_test.h"
    27 #include "graph_maps_test.h"
    31 
       
    32 
    28 
    33 using namespace lemon;
    29 using namespace lemon;
    34 using namespace lemon::concepts;
    30 using namespace lemon::concepts;
    35 
    31 
    36 
    32 void check_concepts() {
    37 int main() {
    33   { // Checking digraph components
    38   { // checking digraph components
       
    39     checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
    34     checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
    40 
    35 
    41     checkConcept<IDableDigraphComponent<>, 
    36     checkConcept<IDableDigraphComponent<>, 
    42       IDableDigraphComponent<> >();
    37       IDableDigraphComponent<> >();
    43 
    38 
    44     checkConcept<IterableDigraphComponent<>, 
    39     checkConcept<IterableDigraphComponent<>, 
    45       IterableDigraphComponent<> >();
    40       IterableDigraphComponent<> >();
    46 
    41 
    47     checkConcept<MappableDigraphComponent<>, 
    42     checkConcept<MappableDigraphComponent<>, 
    48       MappableDigraphComponent<> >();
    43       MappableDigraphComponent<> >();
    49 
       
    50   }
    44   }
    51   { // checking skeleton digraphs
    45   { // Checking skeleton digraph
    52     checkConcept<Digraph, Digraph>();
    46     checkConcept<Digraph, Digraph>();
    53   }
    47   }
    54   { // checking list digraph
    48   { // Checking ListDigraph
    55     checkConcept<Digraph, ListDigraph >();
    49     checkConcept<Digraph, ListDigraph>();
    56     checkConcept<AlterableDigraphComponent<>, ListDigraph>();
    50     checkConcept<AlterableDigraphComponent<>, ListDigraph>();
    57     checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
    51     checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
    58     checkConcept<ClearableDigraphComponent<>, ListDigraph>();
    52     checkConcept<ClearableDigraphComponent<>, ListDigraph>();
    59     checkConcept<ErasableDigraphComponent<>, ListDigraph>();
    53     checkConcept<ErasableDigraphComponent<>, ListDigraph>();
       
    54     checkDigraphIterators<ListDigraph>();
       
    55   }
       
    56   { // Checking SmartDigraph
       
    57     checkConcept<Digraph, SmartDigraph>();
       
    58     checkConcept<AlterableDigraphComponent<>, SmartDigraph>();
       
    59     checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
       
    60     checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
       
    61     checkDigraphIterators<SmartDigraph>();
       
    62   }
       
    63 //  { // Checking FullDigraph
       
    64 //    checkConcept<Digraph, FullDigraph>();
       
    65 //    checkDigraphIterators<FullDigraph>();
       
    66 //  }
       
    67 //  { // Checking HyperCubeDigraph
       
    68 //    checkConcept<Digraph, HyperCubeDigraph>();
       
    69 //    checkDigraphIterators<HyperCubeDigraph>();
       
    70 //  }
       
    71 }
    60 
    72 
       
    73 template <typename Digraph>
       
    74 void check_graph_validity() {
       
    75   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
       
    76   Digraph g;
       
    77 
       
    78   Node
       
    79     n1 = g.addNode(),
       
    80     n2 = g.addNode(),
       
    81     n3 = g.addNode();
       
    82 
       
    83   Arc
       
    84     e1 = g.addArc(n1, n2),
       
    85     e2 = g.addArc(n2, n3);
       
    86 
       
    87   check(g.valid(n1), "Wrong validity check");
       
    88   check(g.valid(e1), "Wrong validity check");
       
    89 
       
    90   check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
       
    91   check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
       
    92 }
       
    93 
       
    94 template <typename Digraph>
       
    95 void check_graph_validity_erase() {
       
    96   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
       
    97   Digraph g;
       
    98 
       
    99   Node
       
   100     n1 = g.addNode(),
       
   101     n2 = g.addNode(),
       
   102     n3 = g.addNode();
       
   103 
       
   104   Arc
       
   105     e1 = g.addArc(n1, n2),
       
   106     e2 = g.addArc(n2, n3);
       
   107 
       
   108   check(g.valid(n1), "Wrong validity check");
       
   109   check(g.valid(e1), "Wrong validity check");
       
   110 
       
   111   g.erase(n1);
       
   112 
       
   113   check(!g.valid(n1), "Wrong validity check");
       
   114   check(g.valid(n2), "Wrong validity check");
       
   115   check(g.valid(n3), "Wrong validity check");
       
   116   check(!g.valid(e1), "Wrong validity check");
       
   117   check(g.valid(e2), "Wrong validity check");
       
   118 
       
   119   check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
       
   120   check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
       
   121 }
       
   122 
       
   123 void check_digraphs() {
       
   124   { // Checking ListDigraph
    61     checkDigraph<ListDigraph>();
   125     checkDigraph<ListDigraph>();
    62     checkGraphNodeMap<ListDigraph>();
   126     checkGraphNodeMap<ListDigraph>();
    63     checkGraphArcMap<ListDigraph>();
   127     checkGraphArcMap<ListDigraph>();
       
   128 
       
   129     check_graph_validity_erase<ListDigraph>();
    64   }
   130   }
    65 //   { // checking smart digraph
   131   { // Checking SmartDigraph
    66 //     checkConcept<Digraph, SmartDigraph >();
   132     checkDigraph<SmartDigraph>();
       
   133     checkGraphNodeMap<SmartDigraph>();
       
   134     checkGraphArcMap<SmartDigraph>();
    67 
   135 
    68 //     checkDigraph<SmartDigraph>();
   136     check_graph_validity<SmartDigraph>();
    69 //     checkDigraphNodeMap<SmartDigraph>();
   137   }
    70 //     checkDigraphArcMap<SmartDigraph>();
   138 }
    71 //   }
       
    72 //   { // checking full digraph
       
    73 //     checkConcept<Digraph, FullDigraph >();
       
    74 //   }
       
    75 //   { // checking full digraph
       
    76 //     checkConcept<Digraph, HyperCubeDigraph >();
       
    77 //   }
       
    78 
   139 
    79   std::cout << __FILE__ ": All tests passed.\n";
   140 int main() {
    80 
   141   check_concepts();
       
   142   check_digraphs();
    81   return 0;
   143   return 0;
    82 }
   144 }