1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/map_test.h Sun Jan 20 20:43:48 2008 +0100
1.3 @@ -0,0 +1,149 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2003-2007
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#ifndef LEMON_TEST_MAP_TEST_H
1.23 +#define LEMON_TEST_MAP_TEST_H
1.24 +
1.25 +
1.26 +#include <vector>
1.27 +#include <lemon/maps.h>
1.28 +
1.29 +#include "test_tools.h"
1.30 +
1.31 +
1.32 +//! \ingroup misc
1.33 +//! \file
1.34 +//! \brief Some utilities to test map classes.
1.35 +
1.36 +namespace lemon {
1.37 +
1.38 +
1.39 +
1.40 + template <typename Graph>
1.41 + void checkGraphNodeMap() {
1.42 + Graph graph;
1.43 + const int num = 16;
1.44 +
1.45 + typedef typename Graph::Node Node;
1.46 +
1.47 + std::vector<Node> nodes;
1.48 + for (int i = 0; i < num; ++i) {
1.49 + nodes.push_back(graph.addNode());
1.50 + }
1.51 + typedef typename Graph::template NodeMap<int> IntNodeMap;
1.52 + IntNodeMap map(graph, 42);
1.53 + for (int i = 0; i < int(nodes.size()); ++i) {
1.54 + check(map[nodes[i]] == 42, "Wrong map constructor.");
1.55 + }
1.56 + for (int i = 0; i < num; ++i) {
1.57 + nodes.push_back(graph.addNode());
1.58 + map[nodes.back()] = 23;
1.59 + }
1.60 + map = constMap<Node>(12);
1.61 + for (int i = 0; i < int(nodes.size()); ++i) {
1.62 + check(map[nodes[i]] == 12, "Wrong map constructor.");
1.63 + }
1.64 + graph.clear();
1.65 + nodes.clear();
1.66 + }
1.67 +
1.68 + template <typename Graph>
1.69 + void checkGraphArcMap() {
1.70 + Graph graph;
1.71 + const int num = 16;
1.72 +
1.73 + typedef typename Graph::Node Node;
1.74 + typedef typename Graph::Arc Arc;
1.75 +
1.76 + std::vector<Node> nodes;
1.77 + for (int i = 0; i < num; ++i) {
1.78 + nodes.push_back(graph.addNode());
1.79 + }
1.80 +
1.81 + std::vector<Arc> edges;
1.82 + for (int i = 0; i < num; ++i) {
1.83 + for (int j = 0; j < i; ++j) {
1.84 + edges.push_back(graph.addArc(nodes[i], nodes[j]));
1.85 + }
1.86 + }
1.87 +
1.88 + typedef typename Graph::template ArcMap<int> IntArcMap;
1.89 + IntArcMap map(graph, 42);
1.90 +
1.91 + for (int i = 0; i < int(edges.size()); ++i) {
1.92 + check(map[edges[i]] == 42, "Wrong map constructor.");
1.93 + }
1.94 +
1.95 + for (int i = 0; i < num; ++i) {
1.96 + for (int j = i + 1; j < num; ++j) {
1.97 + edges.push_back(graph.addArc(nodes[i], nodes[j]));
1.98 + map[edges.back()] = 23;
1.99 + }
1.100 + }
1.101 + map = constMap<Arc>(12);
1.102 + for (int i = 0; i < int(edges.size()); ++i) {
1.103 + check(map[edges[i]] == 12, "Wrong map constructor.");
1.104 + }
1.105 + graph.clear();
1.106 + edges.clear();
1.107 + }
1.108 +
1.109 + template <typename Graph>
1.110 + void checkGraphEdgeMap() {
1.111 + Graph graph;
1.112 + const int num = 16;
1.113 +
1.114 + typedef typename Graph::Node Node;
1.115 + typedef typename Graph::Edge Edge;
1.116 +
1.117 + std::vector<Node> nodes;
1.118 + for (int i = 0; i < num; ++i) {
1.119 + nodes.push_back(graph.addNode());
1.120 + }
1.121 +
1.122 + std::vector<Edge> edges;
1.123 + for (int i = 0; i < num; ++i) {
1.124 + for (int j = 0; j < i; ++j) {
1.125 + edges.push_back(graph.addEdge(nodes[i], nodes[j]));
1.126 + }
1.127 + }
1.128 +
1.129 + typedef typename Graph::template EdgeMap<int> IntEdgeMap;
1.130 + IntEdgeMap map(graph, 42);
1.131 +
1.132 + for (int i = 0; i < int(edges.size()); ++i) {
1.133 + check(map[edges[i]] == 42, "Wrong map constructor.");
1.134 + }
1.135 +
1.136 + for (int i = 0; i < num; ++i) {
1.137 + for (int j = i + 1; j < num; ++j) {
1.138 + edges.push_back(graph.addEdge(nodes[i], nodes[j]));
1.139 + map[edges.back()] = 23;
1.140 + }
1.141 + }
1.142 + map = constMap<Edge>(12);
1.143 + for (int i = 0; i < int(edges.size()); ++i) {
1.144 + check(map[edges[i]] == 12, "Wrong map constructor.");
1.145 + }
1.146 + graph.clear();
1.147 + edges.clear();
1.148 + }
1.149 +
1.150 +}
1.151 +
1.152 +#endif