test/map_test.h
author hegyi
Mon, 21 Nov 2005 18:03:20 +0000
changeset 1823 cb082cdf3667
parent 1435 8e85e6bbefdf
child 1875 98698b69a902
permissions -rw-r--r--
NewMapWin has become Dialog instead of Window. Therefore it is created dynamically, when there is need for it, instead of keeping one instance in memory. This solution is slower, but more correct than before.
     1 /* -*- C++ -*-
     2  * 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     map = constMap<Node>(12);
    53     for (int i = 0; i < (int)nodes.size(); ++i) {
    54       check(map[nodes[i]] == 12, "Wrong map constructor.");      
    55     }    
    56     graph.clear();
    57     nodes.clear();
    58   }
    59 
    60   template <typename Graph>
    61   void checkGraphEdgeMap() {
    62     Graph graph;
    63     const int num = 16;
    64     
    65     typedef typename Graph::Node Node;
    66     typedef typename Graph::Edge Edge;
    67     
    68     std::vector<Node> nodes;
    69     for (int i = 0; i < num; ++i) {
    70       nodes.push_back(graph.addNode());
    71     }
    72     
    73     std::vector<Edge> edges;
    74     for (int i = 0; i < num; ++i) {
    75       for (int j = 0; j < i; ++j) {
    76 	edges.push_back(graph.addEdge(nodes[i], nodes[j]));
    77       }
    78     }
    79     
    80     typedef typename Graph::template EdgeMap<int> IntEdgeMap;
    81     IntEdgeMap map(graph, 42);
    82     
    83     for (int i = 0; i < (int)edges.size(); ++i) {
    84       check(map[edges[i]] == 42, "Wrong map constructor.");      
    85     }
    86     
    87     for (int i = 0; i < num; ++i) {
    88       for (int j = i + 1; j < num; ++j) {
    89 	edges.push_back(graph.addEdge(nodes[i], nodes[j]));
    90 	map[edges.back()] = 23;
    91       }
    92     }
    93     map = constMap<Edge>(12);
    94     for (int i = 0; i < (int)edges.size(); ++i) {
    95       check(map[edges[i]] == 12, "Wrong map constructor.");      
    96     }    
    97     graph.clear();
    98     edges.clear();    
    99   }
   100 
   101 }
   102 
   103 #endif