test/matrix_maps_test.cc
author deba
Thu, 23 Feb 2006 08:55:54 +0000
changeset 1980 a954b780e3ab
parent 1751 a2a454f1232d
child 2039 dacc4ce9474d
permissions -rw-r--r--
Renaming to be convient to the naming of the adaptors
Concept checking of the ugraph adaptors
alpar@1956
     1
/* -*- C++ -*-
alpar@1956
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1956
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@1956
     8
 *
alpar@1956
     9
 * Permission to use, modify and distribute this software is granted
alpar@1956
    10
 * provided that this copyright notice appears in all copies. For
alpar@1956
    11
 * precise terms see the accompanying LICENSE file.
alpar@1956
    12
 *
alpar@1956
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@1956
    14
 * express or implied, and with no claim as to its suitability for any
alpar@1956
    15
 * purpose.
alpar@1956
    16
 *
alpar@1956
    17
 */
deba@1728
    18
deba@1728
    19
#include <iostream>
deba@1728
    20
#include <vector>
deba@1728
    21
deba@1728
    22
#include <lemon/concept_check.h>
deba@1728
    23
deba@1728
    24
#include <lemon/concept/matrix_maps.h>
deba@1728
    25
#include <lemon/concept/maps.h>
deba@1728
    26
#include <lemon/concept/graph.h>
deba@1728
    27
deba@1728
    28
#include <lemon/matrix_maps.h>
deba@1728
    29
deba@1728
    30
#include <lemon/smart_graph.h>
deba@1728
    31
deba@1728
    32
#include "test_tools.h"
deba@1728
    33
#include "graph_test.h"
deba@1728
    34
#include "map_test.h"
deba@1728
    35
deba@1728
    36
deba@1728
    37
using namespace lemon;
deba@1728
    38
using namespace lemon::concept;
deba@1728
    39
deba@1728
    40
int main() {
deba@1728
    41
  typedef SmartGraph Graph;
deba@1728
    42
  typedef Graph::Node Node;
deba@1728
    43
deba@1728
    44
  { // checking MatrixMap for int
deba@1728
    45
    typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
deba@1728
    46
    checkConcept<ReferenceMatrixMap<Node, Node, int, 
deba@1728
    47
      IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
deba@1728
    48
      IntMatrixMap>();
deba@1728
    49
deba@1728
    50
  }
deba@1728
    51
deba@1728
    52
  { // checking MatrixMap for bool
deba@1728
    53
    typedef DynamicMatrixMap<Graph, Node, bool> BoolMatrixMap;
deba@1728
    54
    checkConcept<ReferenceMatrixMap<Node, Node, bool, 
deba@1728
    55
      BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
deba@1728
    56
      BoolMatrixMap>();
deba@1728
    57
deba@1728
    58
  }
deba@1728
    59
deba@1728
    60
  {
deba@1728
    61
    Graph graph;
deba@1728
    62
    typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
deba@1728
    63
    IntMatrixMap matrix(graph);
deba@1728
    64
    for (int i = 0; i < 10; ++i) {
deba@1728
    65
      graph.addNode();
deba@1728
    66
    }
deba@1728
    67
    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
deba@1728
    68
      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
deba@1728
    69
	int val = urandom(100);
deba@1728
    70
	matrix.set(it, jt, val);
deba@1728
    71
	check(matrix(it, jt) == val, "Wrong assign");
deba@1751
    72
	check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
deba@1751
    73
	check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
deba@1728
    74
      }
deba@1728
    75
    }
deba@1728
    76
    const IntMatrixMap& cm = matrix;
deba@1728
    77
    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
deba@1728
    78
      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
deba@1751
    79
	check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
deba@1751
    80
	check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
deba@1728
    81
      }
deba@1728
    82
    }
deba@1728
    83
  }
deba@1728
    84
deba@1728
    85
  { // checking MatrixMap for int
deba@1728
    86
    typedef DynamicSymMatrixMap<Graph, Node, int> IntMatrixMap;
deba@1728
    87
    checkConcept<ReferenceMatrixMap<Node, Node, int, 
deba@1728
    88
      IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
deba@1728
    89
      IntMatrixMap>();
deba@1728
    90
deba@1728
    91
  }
deba@1728
    92
deba@1728
    93
  { // checking MatrixMap for bool
deba@1728
    94
    typedef DynamicSymMatrixMap<Graph, Node, bool> BoolMatrixMap;
deba@1728
    95
    checkConcept<ReferenceMatrixMap<Node, Node, bool, 
deba@1728
    96
      BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
deba@1728
    97
      BoolMatrixMap>();
deba@1728
    98
deba@1728
    99
  }
deba@1728
   100
deba@1728
   101
  {
deba@1728
   102
    Graph graph;
deba@1728
   103
    typedef DynamicSymMatrixMap<Graph, Node, int> IntMatrixMap;
deba@1728
   104
    IntMatrixMap matrix(graph);
deba@1728
   105
    for (int i = 0; i < 10; ++i) {
deba@1728
   106
      graph.addNode();
deba@1728
   107
    }
deba@1728
   108
    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
deba@1728
   109
      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
deba@1728
   110
	int val = urandom(100);
deba@1728
   111
	matrix.set(it, jt, val);
deba@1728
   112
	check(matrix(it, jt) == val, "Wrong assign");
deba@1728
   113
	check(matrix(jt, it) == val, "Wrong assign");
deba@1751
   114
	check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
deba@1751
   115
	check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
deba@1728
   116
      }
deba@1728
   117
    }
deba@1728
   118
    const IntMatrixMap& cm = matrix;
deba@1728
   119
    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
deba@1728
   120
      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
deba@1751
   121
	check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
deba@1751
   122
	check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
deba@1728
   123
      }
deba@1728
   124
    }
deba@1728
   125
  }
deba@1728
   126
deba@1728
   127
  std::cout << __FILE__ ": All tests passed.\n";
deba@1728
   128
deba@1728
   129
  return 0;
deba@1728
   130
}