src/test/undir_graph_test.cc
changeset 1160 d9c32f713cad
parent 1053 90f8696360b2
child 1307 d4acebef7276
equal deleted inserted replaced
4:61a55bfda356 5:0620796a91ba
    41   checkConcept<ExtendableUndirGraph, UndirSmartGraph>();
    41   checkConcept<ExtendableUndirGraph, UndirSmartGraph>();
    42 
    42 
    43   checkConcept<UndirGraph, UndirGraph>();
    43   checkConcept<UndirGraph, UndirGraph>();
    44 }
    44 }
    45 
    45 
    46 typedef UndirListGraph Graph;
    46 template <typename Graph>
    47 typedef Graph::Node Node;
       
    48 typedef Graph::UndirEdge UEdge;
       
    49 typedef Graph::Edge Edge;
       
    50 typedef Graph::NodeIt NodeIt;
       
    51 typedef Graph::UndirEdgeIt UEdgeIt;
       
    52 typedef Graph::EdgeIt EdgeIt;
       
    53 
       
    54 void check_item_counts(Graph &g, int n, int e) {
    47 void check_item_counts(Graph &g, int n, int e) {
    55   check(countNodes(g)==n, "Wrong node number.");
    48   check(countNodes(g)==n, "Wrong node number.");
    56   check(countEdges(g)==2*e, "Wrong edge number.");
    49   check(countEdges(g)==2*e, "Wrong edge number.");
    57 }
    50 }
    58 
    51 
       
    52 template <typename Graph>
    59 void print_items(Graph &g) {
    53 void print_items(Graph &g) {
       
    54 
       
    55   typedef typename Graph::NodeIt NodeIt;
       
    56   typedef typename Graph::UndirEdgeIt UEdgeIt;
       
    57   typedef typename Graph::EdgeIt EdgeIt;
       
    58 
    60   cout << "Nodes" << endl;
    59   cout << "Nodes" << endl;
    61   int i=0;
    60   int i=0;
    62   for(NodeIt it(g); it!=INVALID; ++it, ++i) {
    61   for(NodeIt it(g); it!=INVALID; ++it, ++i) {
    63     cout << "  " << i << ": " << g.id(it) << endl;
    62     cout << "  " << i << ": " << g.id(it) << endl;
    64   }
    63   }
    79 	 << ")" << endl;
    78 	 << ")" << endl;
    80   }
    79   }
    81 
    80 
    82 }
    81 }
    83 
    82 
    84 int main() {
    83 template <typename Graph>
    85   check_concepts();
    84 void check_graph() {
    86 
    85 
       
    86   typedef typename Graph::Node Node;
       
    87   typedef typename Graph::UndirEdge UEdge;
       
    88   typedef typename Graph::Edge Edge;
       
    89   typedef typename Graph::NodeIt NodeIt;
       
    90   typedef typename Graph::UndirEdgeIt UEdgeIt;
       
    91   typedef typename Graph::EdgeIt EdgeIt;
    87 
    92 
    88   Graph g;
    93   Graph g;
    89 
    94 
    90   check_item_counts(g,0,0);
    95   check_item_counts(g,0,0);
    91 
    96 
   100 
   105 
   101   // print_items(g);
   106   // print_items(g);
   102 
   107 
   103   check_item_counts(g,3,2);
   108   check_item_counts(g,3,2);
   104 
   109 
       
   110 
       
   111 }
       
   112 
       
   113 int main() {
       
   114   check_concepts();
       
   115 
       
   116   check_graph<UndirListGraph>();
       
   117   check_graph<UndirSmartGraph>();
       
   118 
   105   return 0;
   119   return 0;
   106 }
   120 }