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