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