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