test/graph_maps_test.h
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 13 Jul 2008 22:05:25 +0100
changeset 214 60eecd3fe37a
parent 171 02f4d5d9bfd7
permissions -rw-r--r--
Some cleanup in ArgParser API (ticket #116)
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     5  * Copyright (C) 2003-2008
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     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  */
    18 
    19 #ifndef LEMON_TEST_MAP_TEST_H
    20 #define LEMON_TEST_MAP_TEST_H
    21 
    22 #include <vector>
    23 #include <lemon/maps.h>
    24 
    25 #include "test_tools.h"
    26 
    27 namespace lemon {
    28 
    29   template <typename Graph>
    30   void checkGraphNodeMap() {
    31     Graph graph;
    32     const int num = 16;
    33 
    34     typedef typename Graph::Node Node;
    35 
    36     std::vector<Node> nodes;
    37     for (int i = 0; i < num; ++i) {
    38       nodes.push_back(graph.addNode());
    39     }
    40     typedef typename Graph::template NodeMap<int> IntNodeMap;
    41     IntNodeMap map(graph, 42);
    42     for (int i = 0; i < int(nodes.size()); ++i) {
    43       check(map[nodes[i]] == 42, "Wrong map constructor.");
    44     }
    45     for (int i = 0; i < num; ++i) {
    46       nodes.push_back(graph.addNode());
    47       map[nodes.back()] = 23;
    48       check(map[nodes.back()] == 23, "Wrong operator[].");
    49     }
    50     map = constMap<Node>(12);
    51     for (int i = 0; i < int(nodes.size()); ++i) {
    52       check(map[nodes[i]] == 12, "Wrong map constructor.");
    53     }
    54     graph.clear();
    55     nodes.clear();
    56   }
    57 
    58   template <typename Graph>
    59   void checkGraphArcMap() {
    60     Graph graph;
    61     const int num = 16;
    62 
    63     typedef typename Graph::Node Node;
    64     typedef typename Graph::Arc Arc;
    65 
    66     std::vector<Node> nodes;
    67     for (int i = 0; i < num; ++i) {
    68       nodes.push_back(graph.addNode());
    69     }
    70 
    71     std::vector<Arc> arcs;
    72     for (int i = 0; i < num; ++i) {
    73       for (int j = 0; j < i; ++j) {
    74         arcs.push_back(graph.addArc(nodes[i], nodes[j]));
    75       }
    76     }
    77 
    78     typedef typename Graph::template ArcMap<int> IntArcMap;
    79     IntArcMap map(graph, 42);
    80 
    81     for (int i = 0; i < int(arcs.size()); ++i) {
    82       check(map[arcs[i]] == 42, "Wrong map constructor.");
    83     }
    84 
    85     for (int i = 0; i < num; ++i) {
    86       for (int j = i + 1; j < num; ++j) {
    87         arcs.push_back(graph.addArc(nodes[i], nodes[j]));
    88         map[arcs.back()] = 23;
    89         check(map[arcs.back()] == 23, "Wrong operator[].");
    90       }
    91     }
    92     map = constMap<Arc>(12);
    93     for (int i = 0; i < int(arcs.size()); ++i) {
    94       check(map[arcs[i]] == 12, "Wrong map constructor.");
    95     }
    96     graph.clear();
    97     arcs.clear();
    98   }
    99 
   100   template <typename Graph>
   101   void checkGraphEdgeMap() {
   102     Graph graph;
   103     const int num = 16;
   104 
   105     typedef typename Graph::Node Node;
   106     typedef typename Graph::Edge Edge;
   107 
   108     std::vector<Node> nodes;
   109     for (int i = 0; i < num; ++i) {
   110       nodes.push_back(graph.addNode());
   111     }
   112 
   113     std::vector<Edge> edges;
   114     for (int i = 0; i < num; ++i) {
   115       for (int j = 0; j < i; ++j) {
   116         edges.push_back(graph.addEdge(nodes[i], nodes[j]));
   117       }
   118     }
   119 
   120     typedef typename Graph::template EdgeMap<int> IntEdgeMap;
   121     IntEdgeMap map(graph, 42);
   122 
   123     for (int i = 0; i < int(edges.size()); ++i) {
   124       check(map[edges[i]] == 42, "Wrong map constructor.");
   125     }
   126 
   127     for (int i = 0; i < num; ++i) {
   128       for (int j = i + 1; j < num; ++j) {
   129         edges.push_back(graph.addEdge(nodes[i], nodes[j]));
   130         map[edges.back()] = 23;
   131         check(map[edges.back()] == 23, "Wrong operator[].");
   132       }
   133     }
   134     map = constMap<Edge>(12);
   135     for (int i = 0; i < int(edges.size()); ++i) {
   136       check(map[edges[i]] == 12, "Wrong map constructor.");
   137     }
   138     graph.clear();
   139     edges.clear();
   140   }
   141 
   142 }
   143 
   144 #endif