klao@946
|
1 |
/* -*- C++ -*-
|
klao@946
|
2 |
* src/test/map_test.h - Part of LEMON, a generic C++ optimization library
|
klao@946
|
3 |
*
|
klao@946
|
4 |
* Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
klao@946
|
5 |
* (Egervary Combinatorial Optimization Research Group, 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
|
klao@946
|
27 |
//! \brief Some utility 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 |
}
|
klao@946
|
52 |
graph.clear();
|
klao@946
|
53 |
nodes.clear();
|
klao@946
|
54 |
}
|
klao@946
|
55 |
|
klao@946
|
56 |
template <typename Graph>
|
klao@946
|
57 |
void checkGraphEdgeMap() {
|
klao@946
|
58 |
Graph graph;
|
klao@946
|
59 |
const int num = 16;
|
klao@946
|
60 |
|
klao@946
|
61 |
typedef typename Graph::Node Node;
|
klao@946
|
62 |
typedef typename Graph::Edge Edge;
|
klao@946
|
63 |
|
klao@946
|
64 |
std::vector<Node> nodes;
|
klao@946
|
65 |
for (int i = 0; i < num; ++i) {
|
klao@946
|
66 |
nodes.push_back(graph.addNode());
|
klao@946
|
67 |
}
|
klao@946
|
68 |
|
klao@946
|
69 |
std::vector<Edge> edges;
|
klao@946
|
70 |
for (int i = 0; i < num; ++i) {
|
klao@946
|
71 |
for (int j = 0; j < i; ++j) {
|
klao@946
|
72 |
edges.push_back(graph.addEdge(nodes[i], nodes[j]));
|
klao@946
|
73 |
}
|
klao@946
|
74 |
}
|
klao@946
|
75 |
|
klao@946
|
76 |
typedef typename Graph::template EdgeMap<int> IntEdgeMap;
|
klao@946
|
77 |
IntEdgeMap map(graph, 42);
|
klao@946
|
78 |
|
klao@946
|
79 |
for (int i = 0; i < (int)edges.size(); ++i) {
|
klao@946
|
80 |
check(map[edges[i]] == 42, "Wrong map constructor.");
|
klao@946
|
81 |
}
|
klao@946
|
82 |
|
klao@946
|
83 |
for (int i = 0; i < num; ++i) {
|
klao@946
|
84 |
for (int j = i + 1; j < num; ++j) {
|
klao@946
|
85 |
edges.push_back(graph.addEdge(nodes[i], nodes[j]));
|
klao@946
|
86 |
map[edges.back()] = 23;
|
klao@946
|
87 |
}
|
klao@946
|
88 |
}
|
klao@946
|
89 |
graph.clear();
|
klao@946
|
90 |
edges.clear();
|
klao@946
|
91 |
}
|
klao@946
|
92 |
|
klao@946
|
93 |
}
|
klao@946
|
94 |
|
klao@946
|
95 |
#endif
|