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