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