test/map_test.h
author deba
Wed, 29 Nov 2006 15:01:13 +0000
changeset 2312 07e46cbb7d85
parent 1875 98698b69a902
child 2386 81b47fc5c444
permissions -rw-r--r--
modified _setColCoeff and _setRowCoeff parameters
const simplify() for expressions
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     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 
    23 #include <vector>
    24 
    25 #include "test_tools.h"
    26 
    27 
    28 //! \ingroup misc
    29 //! \file
    30 //! \brief Some utilities to test map classes.
    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);
    48     for (int i = 0; i < (int)nodes.size(); ++i) {
    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     }
    55     map = constMap<Node>(12);
    56     for (int i = 0; i < (int)nodes.size(); ++i) {
    57       check(map[nodes[i]] == 12, "Wrong map constructor.");      
    58     }    
    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     
    86     for (int i = 0; i < (int)edges.size(); ++i) {
    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     }
    96     map = constMap<Edge>(12);
    97     for (int i = 0; i < (int)edges.size(); ++i) {
    98       check(map[edges[i]] == 12, "Wrong map constructor.");      
    99     }    
   100     graph.clear();
   101     edges.clear();    
   102   }
   103 
   104 }
   105 
   106 #endif