COIN-OR::LEMON - Graph Library

source: lemon-0.x/test/matrix_maps_test.cc @ 1955:daca31868d70

Last change on this file since 1955:daca31868d70 was 1751:a2a454f1232d, checked in by Balazs Dezso, 18 years ago

Swap col and row map

File size: 3.2 KB
Line 
1// -*- c++ -*-
2
3#include <iostream>
4#include <vector>
5
6#include <lemon/concept_check.h>
7
8#include <lemon/concept/matrix_maps.h>
9#include <lemon/concept/maps.h>
10#include <lemon/concept/graph.h>
11
12#include <lemon/matrix_maps.h>
13
14#include <lemon/smart_graph.h>
15
16#include "test_tools.h"
17#include "graph_test.h"
18#include "map_test.h"
19
20
21using namespace lemon;
22using namespace lemon::concept;
23
24int main() {
25  typedef SmartGraph Graph;
26  typedef Graph::Node Node;
27
28  { // checking MatrixMap for int
29    typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
30    checkConcept<ReferenceMatrixMap<Node, Node, int,
31      IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
32      IntMatrixMap>();
33
34  }
35
36  { // checking MatrixMap for bool
37    typedef DynamicMatrixMap<Graph, Node, bool> BoolMatrixMap;
38    checkConcept<ReferenceMatrixMap<Node, Node, bool,
39      BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
40      BoolMatrixMap>();
41
42  }
43
44  {
45    Graph graph;
46    typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
47    IntMatrixMap matrix(graph);
48    for (int i = 0; i < 10; ++i) {
49      graph.addNode();
50    }
51    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
52      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
53        int val = urandom(100);
54        matrix.set(it, jt, val);
55        check(matrix(it, jt) == val, "Wrong assign");
56        check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
57        check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
58      }
59    }
60    const IntMatrixMap& cm = matrix;
61    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
62      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
63        check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
64        check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
65      }
66    }
67  }
68
69  { // checking MatrixMap for int
70    typedef DynamicSymMatrixMap<Graph, Node, int> IntMatrixMap;
71    checkConcept<ReferenceMatrixMap<Node, Node, int,
72      IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
73      IntMatrixMap>();
74
75  }
76
77  { // checking MatrixMap for bool
78    typedef DynamicSymMatrixMap<Graph, Node, bool> BoolMatrixMap;
79    checkConcept<ReferenceMatrixMap<Node, Node, bool,
80      BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
81      BoolMatrixMap>();
82
83  }
84
85  {
86    Graph graph;
87    typedef DynamicSymMatrixMap<Graph, Node, int> IntMatrixMap;
88    IntMatrixMap matrix(graph);
89    for (int i = 0; i < 10; ++i) {
90      graph.addNode();
91    }
92    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
93      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
94        int val = urandom(100);
95        matrix.set(it, jt, val);
96        check(matrix(it, jt) == val, "Wrong assign");
97        check(matrix(jt, it) == val, "Wrong assign");
98        check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
99        check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
100      }
101    }
102    const IntMatrixMap& cm = matrix;
103    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
104      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
105        check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
106        check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
107      }
108    }
109  }
110
111  std::cout << __FILE__ ": All tests passed.\n";
112
113  return 0;
114}
Note: See TracBrowser for help on using the repository browser.