test/matrix_maps_test.cc
author deba
Thu, 30 Mar 2006 08:38:41 +0000
changeset 2020 332245399dc6
parent 1751 a2a454f1232d
child 2039 dacc4ce9474d
permissions -rw-r--r--
Rewritten countItems and findEdges
     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 #include <iostream>
    20 #include <vector>
    21 
    22 #include <lemon/concept_check.h>
    23 
    24 #include <lemon/concept/matrix_maps.h>
    25 #include <lemon/concept/maps.h>
    26 #include <lemon/concept/graph.h>
    27 
    28 #include <lemon/matrix_maps.h>
    29 
    30 #include <lemon/smart_graph.h>
    31 
    32 #include "test_tools.h"
    33 #include "graph_test.h"
    34 #include "map_test.h"
    35 
    36 
    37 using namespace lemon;
    38 using namespace lemon::concept;
    39 
    40 int main() {
    41   typedef SmartGraph Graph;
    42   typedef Graph::Node Node;
    43 
    44   { // checking MatrixMap for int
    45     typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
    46     checkConcept<ReferenceMatrixMap<Node, Node, int, 
    47       IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
    48       IntMatrixMap>();
    49 
    50   }
    51 
    52   { // checking MatrixMap for bool
    53     typedef DynamicMatrixMap<Graph, Node, bool> BoolMatrixMap;
    54     checkConcept<ReferenceMatrixMap<Node, Node, bool, 
    55       BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
    56       BoolMatrixMap>();
    57 
    58   }
    59 
    60   {
    61     Graph graph;
    62     typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
    63     IntMatrixMap matrix(graph);
    64     for (int i = 0; i < 10; ++i) {
    65       graph.addNode();
    66     }
    67     for (Graph::NodeIt it(graph); it != INVALID; ++it) {
    68       for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
    69 	int val = urandom(100);
    70 	matrix.set(it, jt, val);
    71 	check(matrix(it, jt) == val, "Wrong assign");
    72 	check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
    73 	check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
    74       }
    75     }
    76     const IntMatrixMap& cm = matrix;
    77     for (Graph::NodeIt it(graph); it != INVALID; ++it) {
    78       for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
    79 	check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
    80 	check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
    81       }
    82     }
    83   }
    84 
    85   { // checking MatrixMap for int
    86     typedef DynamicSymMatrixMap<Graph, Node, int> IntMatrixMap;
    87     checkConcept<ReferenceMatrixMap<Node, Node, int, 
    88       IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
    89       IntMatrixMap>();
    90 
    91   }
    92 
    93   { // checking MatrixMap for bool
    94     typedef DynamicSymMatrixMap<Graph, Node, bool> BoolMatrixMap;
    95     checkConcept<ReferenceMatrixMap<Node, Node, bool, 
    96       BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
    97       BoolMatrixMap>();
    98 
    99   }
   100 
   101   {
   102     Graph graph;
   103     typedef DynamicSymMatrixMap<Graph, Node, int> IntMatrixMap;
   104     IntMatrixMap matrix(graph);
   105     for (int i = 0; i < 10; ++i) {
   106       graph.addNode();
   107     }
   108     for (Graph::NodeIt it(graph); it != INVALID; ++it) {
   109       for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
   110 	int val = urandom(100);
   111 	matrix.set(it, jt, val);
   112 	check(matrix(it, jt) == val, "Wrong assign");
   113 	check(matrix(jt, it) == val, "Wrong assign");
   114 	check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
   115 	check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
   116       }
   117     }
   118     const IntMatrixMap& cm = matrix;
   119     for (Graph::NodeIt it(graph); it != INVALID; ++it) {
   120       for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
   121 	check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
   122 	check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
   123       }
   124     }
   125   }
   126 
   127   std::cout << __FILE__ ": All tests passed.\n";
   128 
   129   return 0;
   130 }