test/map_test.h
author Peter Kovacs <kpeter@inf.elte.hu>
Tue, 18 Mar 2008 13:57:15 +0100
changeset 94 a4688e4138ec
child 107 31a2e6d28f61
permissions -rw-r--r--
Fixes in the map concepts

- Now Value type needn't be default constructible.
- Extend the test file to check this.
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2007
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #ifndef LEMON_TEST_MAP_TEST_H
    20 #define LEMON_TEST_MAP_TEST_H
    21 
    22 
    23 #include <vector>
    24 #include <lemon/maps.h>
    25 
    26 #include "test_tools.h"
    27 
    28 
    29 //! \ingroup misc
    30 //! \file
    31 //! \brief Some utilities to test map classes.
    32 
    33 namespace lemon {
    34 
    35 
    36 
    37   template <typename Graph>
    38   void checkGraphNodeMap() {
    39     Graph graph;
    40     const int num = 16;
    41     
    42     typedef typename Graph::Node Node;
    43 
    44     std::vector<Node> nodes;
    45     for (int i = 0; i < num; ++i) {
    46       nodes.push_back(graph.addNode());      
    47     }
    48     typedef typename Graph::template NodeMap<int> IntNodeMap;
    49     IntNodeMap map(graph, 42);
    50     for (int i = 0; i < int(nodes.size()); ++i) {
    51       check(map[nodes[i]] == 42, "Wrong map constructor.");      
    52     }
    53     for (int i = 0; i < num; ++i) {
    54       nodes.push_back(graph.addNode());
    55       map[nodes.back()] = 23;
    56     }
    57     map = constMap<Node>(12);
    58     for (int i = 0; i < int(nodes.size()); ++i) {
    59       check(map[nodes[i]] == 12, "Wrong map constructor.");      
    60     }    
    61     graph.clear();
    62     nodes.clear();
    63   }
    64 
    65   template <typename Graph>
    66   void checkGraphArcMap() {
    67     Graph graph;
    68     const int num = 16;
    69     
    70     typedef typename Graph::Node Node;
    71     typedef typename Graph::Arc Arc;
    72     
    73     std::vector<Node> nodes;
    74     for (int i = 0; i < num; ++i) {
    75       nodes.push_back(graph.addNode());
    76     }
    77     
    78     std::vector<Arc> edges;
    79     for (int i = 0; i < num; ++i) {
    80       for (int j = 0; j < i; ++j) {
    81 	edges.push_back(graph.addArc(nodes[i], nodes[j]));
    82       }
    83     }
    84     
    85     typedef typename Graph::template ArcMap<int> IntArcMap;
    86     IntArcMap map(graph, 42);
    87     
    88     for (int i = 0; i < int(edges.size()); ++i) {
    89       check(map[edges[i]] == 42, "Wrong map constructor.");      
    90     }
    91     
    92     for (int i = 0; i < num; ++i) {
    93       for (int j = i + 1; j < num; ++j) {
    94 	edges.push_back(graph.addArc(nodes[i], nodes[j]));
    95 	map[edges.back()] = 23;
    96       }
    97     }
    98     map = constMap<Arc>(12);
    99     for (int i = 0; i < int(edges.size()); ++i) {
   100       check(map[edges[i]] == 12, "Wrong map constructor.");      
   101     }    
   102     graph.clear();
   103     edges.clear();    
   104   }
   105 
   106   template <typename Graph>
   107   void checkGraphEdgeMap() {
   108     Graph graph;
   109     const int num = 16;
   110     
   111     typedef typename Graph::Node Node;
   112     typedef typename Graph::Edge Edge;
   113     
   114     std::vector<Node> nodes;
   115     for (int i = 0; i < num; ++i) {
   116       nodes.push_back(graph.addNode());
   117     }
   118     
   119     std::vector<Edge> edges;
   120     for (int i = 0; i < num; ++i) {
   121       for (int j = 0; j < i; ++j) {
   122 	edges.push_back(graph.addEdge(nodes[i], nodes[j]));
   123       }
   124     }
   125     
   126     typedef typename Graph::template EdgeMap<int> IntEdgeMap;
   127     IntEdgeMap map(graph, 42);
   128     
   129     for (int i = 0; i < int(edges.size()); ++i) {
   130       check(map[edges[i]] == 42, "Wrong map constructor.");      
   131     }
   132     
   133     for (int i = 0; i < num; ++i) {
   134       for (int j = i + 1; j < num; ++j) {
   135 	edges.push_back(graph.addEdge(nodes[i], nodes[j]));
   136 	map[edges.back()] = 23;
   137       }
   138     }
   139     map = constMap<Edge>(12);
   140     for (int i = 0; i < int(edges.size()); ++i) {
   141       check(map[edges[i]] == 12, "Wrong map constructor.");      
   142     }    
   143     graph.clear();
   144     edges.clear();    
   145   }
   146 
   147 }
   148 
   149 #endif