1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/test/map_test.h Wed Oct 27 22:38:50 2004 +0000
1.3 @@ -0,0 +1,95 @@
1.4 +/* -*- C++ -*-
1.5 + * src/test/map_test.h - Part of LEMON, a generic C++ optimization library
1.6 + *
1.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
1.9 + *
1.10 + * Permission to use, modify and distribute this software is granted
1.11 + * provided that this copyright notice appears in all copies. For
1.12 + * precise terms see the accompanying LICENSE file.
1.13 + *
1.14 + * This software is provided "AS IS" with no warranty of any kind,
1.15 + * express or implied, and with no claim as to its suitability for any
1.16 + * purpose.
1.17 + *
1.18 + */
1.19 +#ifndef LEMON_TEST_MAP_TEST_H
1.20 +#define LEMON_TEST_MAP_TEST_H
1.21 +
1.22 +
1.23 +#include <vector>
1.24 +
1.25 +#include "test_tools.h"
1.26 +
1.27 +
1.28 +//! \ingroup misc
1.29 +//! \file
1.30 +//! \brief Some utility to test map classes.
1.31 +
1.32 +namespace lemon {
1.33 +
1.34 +
1.35 + template <typename Graph>
1.36 + void checkGraphNodeMap() {
1.37 + Graph graph;
1.38 + const int num = 16;
1.39 +
1.40 + typedef typename Graph::Node Node;
1.41 +
1.42 + std::vector<Node> nodes;
1.43 + for (int i = 0; i < num; ++i) {
1.44 + nodes.push_back(graph.addNode());
1.45 + }
1.46 + typedef typename Graph::template NodeMap<int> IntNodeMap;
1.47 + IntNodeMap map(graph, 42);
1.48 + for (int i = 0; i < (int)nodes.size(); ++i) {
1.49 + check(map[nodes[i]] == 42, "Wrong map constructor.");
1.50 + }
1.51 + for (int i = 0; i < num; ++i) {
1.52 + nodes.push_back(graph.addNode());
1.53 + map[nodes.back()] = 23;
1.54 + }
1.55 + graph.clear();
1.56 + nodes.clear();
1.57 + }
1.58 +
1.59 + template <typename Graph>
1.60 + void checkGraphEdgeMap() {
1.61 + Graph graph;
1.62 + const int num = 16;
1.63 +
1.64 + typedef typename Graph::Node Node;
1.65 + typedef typename Graph::Edge Edge;
1.66 +
1.67 + std::vector<Node> nodes;
1.68 + for (int i = 0; i < num; ++i) {
1.69 + nodes.push_back(graph.addNode());
1.70 + }
1.71 +
1.72 + std::vector<Edge> edges;
1.73 + for (int i = 0; i < num; ++i) {
1.74 + for (int j = 0; j < i; ++j) {
1.75 + edges.push_back(graph.addEdge(nodes[i], nodes[j]));
1.76 + }
1.77 + }
1.78 +
1.79 + typedef typename Graph::template EdgeMap<int> IntEdgeMap;
1.80 + IntEdgeMap map(graph, 42);
1.81 +
1.82 + for (int i = 0; i < (int)edges.size(); ++i) {
1.83 + check(map[edges[i]] == 42, "Wrong map constructor.");
1.84 + }
1.85 +
1.86 + for (int i = 0; i < num; ++i) {
1.87 + for (int j = i + 1; j < num; ++j) {
1.88 + edges.push_back(graph.addEdge(nodes[i], nodes[j]));
1.89 + map[edges.back()] = 23;
1.90 + }
1.91 + }
1.92 + graph.clear();
1.93 + edges.clear();
1.94 + }
1.95 +
1.96 +}
1.97 +
1.98 +#endif