test/matrix_maps_test.cc
changeset 1728 eb8bb91ba9e2
child 1751 a2a454f1232d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/matrix_maps_test.cc	Fri Oct 14 11:03:40 2005 +0000
     1.3 @@ -0,0 +1,114 @@
     1.4 +// -*- c++ -*-
     1.5 +
     1.6 +#include <iostream>
     1.7 +#include <vector>
     1.8 +
     1.9 +#include <lemon/concept_check.h>
    1.10 +
    1.11 +#include <lemon/concept/matrix_maps.h>
    1.12 +#include <lemon/concept/maps.h>
    1.13 +#include <lemon/concept/graph.h>
    1.14 +
    1.15 +#include <lemon/matrix_maps.h>
    1.16 +
    1.17 +#include <lemon/smart_graph.h>
    1.18 +
    1.19 +#include "test_tools.h"
    1.20 +#include "graph_test.h"
    1.21 +#include "map_test.h"
    1.22 +
    1.23 +
    1.24 +using namespace lemon;
    1.25 +using namespace lemon::concept;
    1.26 +
    1.27 +int main() {
    1.28 +  typedef SmartGraph Graph;
    1.29 +  typedef Graph::Node Node;
    1.30 +
    1.31 +  { // checking MatrixMap for int
    1.32 +    typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
    1.33 +    checkConcept<ReferenceMatrixMap<Node, Node, int, 
    1.34 +      IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
    1.35 +      IntMatrixMap>();
    1.36 +
    1.37 +  }
    1.38 +
    1.39 +  { // checking MatrixMap for bool
    1.40 +    typedef DynamicMatrixMap<Graph, Node, bool> BoolMatrixMap;
    1.41 +    checkConcept<ReferenceMatrixMap<Node, Node, bool, 
    1.42 +      BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
    1.43 +      BoolMatrixMap>();
    1.44 +
    1.45 +  }
    1.46 +
    1.47 +  {
    1.48 +    Graph graph;
    1.49 +    typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
    1.50 +    IntMatrixMap matrix(graph);
    1.51 +    for (int i = 0; i < 10; ++i) {
    1.52 +      graph.addNode();
    1.53 +    }
    1.54 +    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
    1.55 +      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
    1.56 +	int val = urandom(100);
    1.57 +	matrix.set(it, jt, val);
    1.58 +	check(matrix(it, jt) == val, "Wrong assign");
    1.59 +	check(matrix(it, jt) == matrixColMap(matrix, it)[jt], "Wrong colMap");
    1.60 +	check(matrix(it, jt) == matrixRowMap(matrix, jt)[it], "Wrong rowMap");
    1.61 +      }
    1.62 +    }
    1.63 +    const IntMatrixMap& cm = matrix;
    1.64 +    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
    1.65 +      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
    1.66 +	check(cm(it, jt) == matrixColMap(cm, it)[jt], "Wrong colMap");
    1.67 +	check(cm(it, jt) == matrixRowMap(cm, jt)[it], "Wrong rowMap");
    1.68 +      }
    1.69 +    }
    1.70 +  }
    1.71 +
    1.72 +  { // checking MatrixMap for int
    1.73 +    typedef DynamicSymMatrixMap<Graph, Node, int> IntMatrixMap;
    1.74 +    checkConcept<ReferenceMatrixMap<Node, Node, int, 
    1.75 +      IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
    1.76 +      IntMatrixMap>();
    1.77 +
    1.78 +  }
    1.79 +
    1.80 +  { // checking MatrixMap for bool
    1.81 +    typedef DynamicSymMatrixMap<Graph, Node, bool> BoolMatrixMap;
    1.82 +    checkConcept<ReferenceMatrixMap<Node, Node, bool, 
    1.83 +      BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
    1.84 +      BoolMatrixMap>();
    1.85 +
    1.86 +  }
    1.87 +
    1.88 +  {
    1.89 +    Graph graph;
    1.90 +    typedef DynamicSymMatrixMap<Graph, Node, int> IntMatrixMap;
    1.91 +    IntMatrixMap matrix(graph);
    1.92 +    for (int i = 0; i < 10; ++i) {
    1.93 +      graph.addNode();
    1.94 +    }
    1.95 +    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
    1.96 +      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
    1.97 +	int val = urandom(100);
    1.98 +	matrix.set(it, jt, val);
    1.99 +	check(matrix(it, jt) == val, "Wrong assign");
   1.100 +	check(matrix(jt, it) == val, "Wrong assign");
   1.101 +	check(matrix(it, jt) == matrixColMap(matrix, it)[jt], "Wrong colMap");
   1.102 +	check(matrix(it, jt) == matrixRowMap(matrix, jt)[it], "Wrong rowMap");
   1.103 +      }
   1.104 +    }
   1.105 +    const IntMatrixMap& cm = matrix;
   1.106 +    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
   1.107 +      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
   1.108 +	check(cm(it, jt) == matrixColMap(cm, it)[jt], "Wrong colMap");
   1.109 +	check(cm(it, jt) == matrixRowMap(cm, jt)[it], "Wrong rowMap");
   1.110 +      }
   1.111 +    }
   1.112 +  }
   1.113 +
   1.114 +  std::cout << __FILE__ ": All tests passed.\n";
   1.115 +
   1.116 +  return 0;
   1.117 +}