test/map_test.h
author deba
Tue, 31 Jan 2006 19:33:48 +0000
changeset 1931 6abf67b02ff5
parent 1675 fa89ffb27a6d
child 1956 a055123339d5
permissions -rw-r--r--
New iterable map with comparable values
it uses linked lists and balanced binary tree

IterableBoolMap has ItemIt type as the other iterable maps

InvertableMap got ValueIterator
klao@946
     1
/* -*- C++ -*-
ladanyi@1435
     2
 * test/map_test.h - Part of LEMON, a generic C++ optimization library
klao@946
     3
 *
alpar@1875
     4
 * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     5
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
klao@946
     6
 *
klao@946
     7
 * Permission to use, modify and distribute this software is granted
klao@946
     8
 * provided that this copyright notice appears in all copies. For
klao@946
     9
 * precise terms see the accompanying LICENSE file.
klao@946
    10
 *
klao@946
    11
 * This software is provided "AS IS" with no warranty of any kind,
klao@946
    12
 * express or implied, and with no claim as to its suitability for any
klao@946
    13
 * purpose.
klao@946
    14
 *
klao@946
    15
 */
klao@946
    16
#ifndef LEMON_TEST_MAP_TEST_H
klao@946
    17
#define LEMON_TEST_MAP_TEST_H
klao@946
    18
klao@946
    19
klao@946
    20
#include <vector>
klao@946
    21
klao@946
    22
#include "test_tools.h"
klao@946
    23
klao@946
    24
klao@946
    25
//! \ingroup misc
klao@946
    26
//! \file
alpar@1041
    27
//! \brief Some utilities to test map classes.
klao@946
    28
klao@946
    29
namespace lemon {
klao@946
    30
klao@946
    31
klao@946
    32
  template <typename Graph>
klao@946
    33
  void checkGraphNodeMap() {
klao@946
    34
    Graph graph;
klao@946
    35
    const int num = 16;
klao@946
    36
    
klao@946
    37
    typedef typename Graph::Node Node;
klao@946
    38
klao@946
    39
    std::vector<Node> nodes;
klao@946
    40
    for (int i = 0; i < num; ++i) {
klao@946
    41
      nodes.push_back(graph.addNode());      
klao@946
    42
    }
klao@946
    43
    typedef typename Graph::template NodeMap<int> IntNodeMap;
klao@946
    44
    IntNodeMap map(graph, 42);
klao@946
    45
    for (int i = 0; i < (int)nodes.size(); ++i) {
klao@946
    46
      check(map[nodes[i]] == 42, "Wrong map constructor.");      
klao@946
    47
    }
klao@946
    48
    for (int i = 0; i < num; ++i) {
klao@946
    49
      nodes.push_back(graph.addNode());
klao@946
    50
      map[nodes.back()] = 23;
klao@946
    51
    }
deba@1675
    52
    map = constMap<Node>(12);
deba@1675
    53
    for (int i = 0; i < (int)nodes.size(); ++i) {
deba@1675
    54
      check(map[nodes[i]] == 12, "Wrong map constructor.");      
deba@1675
    55
    }    
klao@946
    56
    graph.clear();
klao@946
    57
    nodes.clear();
klao@946
    58
  }
klao@946
    59
klao@946
    60
  template <typename Graph>
klao@946
    61
  void checkGraphEdgeMap() {
klao@946
    62
    Graph graph;
klao@946
    63
    const int num = 16;
klao@946
    64
    
klao@946
    65
    typedef typename Graph::Node Node;
klao@946
    66
    typedef typename Graph::Edge Edge;
klao@946
    67
    
klao@946
    68
    std::vector<Node> nodes;
klao@946
    69
    for (int i = 0; i < num; ++i) {
klao@946
    70
      nodes.push_back(graph.addNode());
klao@946
    71
    }
klao@946
    72
    
klao@946
    73
    std::vector<Edge> edges;
klao@946
    74
    for (int i = 0; i < num; ++i) {
klao@946
    75
      for (int j = 0; j < i; ++j) {
klao@946
    76
	edges.push_back(graph.addEdge(nodes[i], nodes[j]));
klao@946
    77
      }
klao@946
    78
    }
klao@946
    79
    
klao@946
    80
    typedef typename Graph::template EdgeMap<int> IntEdgeMap;
klao@946
    81
    IntEdgeMap map(graph, 42);
klao@946
    82
    
klao@946
    83
    for (int i = 0; i < (int)edges.size(); ++i) {
klao@946
    84
      check(map[edges[i]] == 42, "Wrong map constructor.");      
klao@946
    85
    }
klao@946
    86
    
klao@946
    87
    for (int i = 0; i < num; ++i) {
klao@946
    88
      for (int j = i + 1; j < num; ++j) {
klao@946
    89
	edges.push_back(graph.addEdge(nodes[i], nodes[j]));
klao@946
    90
	map[edges.back()] = 23;
klao@946
    91
      }
klao@946
    92
    }
deba@1675
    93
    map = constMap<Edge>(12);
deba@1675
    94
    for (int i = 0; i < (int)edges.size(); ++i) {
deba@1675
    95
      check(map[edges[i]] == 12, "Wrong map constructor.");      
deba@1675
    96
    }    
klao@946
    97
    graph.clear();
klao@946
    98
    edges.clear();    
klao@946
    99
  }
klao@946
   100
klao@946
   101
}
klao@946
   102
klao@946
   103
#endif