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