test/maps_test.cc
author marci
Sun, 13 Nov 2005 20:01:17 +0000
changeset 1787 932b8490caf0
parent 1435 8e85e6bbefdf
child 1956 a055123339d5
permissions -rw-r--r--
bugfix in setCol, getting dual values
alpar@1041
     1
#include <lemon/concept_check.h>
alpar@1041
     2
#include <lemon/concept/maps.h>
alpar@1041
     3
#include <lemon/maps.h>
alpar@1041
     4
alpar@1041
     5
#include "test_tools.h"
alpar@1041
     6
alpar@1041
     7
using namespace lemon;
alpar@1041
     8
using namespace lemon::concept;
alpar@1041
     9
alpar@1041
    10
struct A {};
alpar@1041
    11
struct B {};
deba@1675
    12
deba@1675
    13
class F {
alpar@1076
    14
public:
deba@1675
    15
  typedef A argument_type;
deba@1675
    16
  typedef B result_type;
deba@1675
    17
alpar@1375
    18
  B operator()(const A &) const {return B();}
alpar@1076
    19
};
alpar@1076
    20
alpar@1375
    21
int func(A) {return 3;}
alpar@1041
    22
deba@1675
    23
int binc(int, B) {return 4;}
deba@1675
    24
alpar@1041
    25
typedef ReadMap<A,double> DoubleMap;
alpar@1041
    26
alpar@1041
    27
int main()
alpar@1041
    28
{ // checking graph components
alpar@1041
    29
  
alpar@1041
    30
  checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
alpar@1041
    31
  checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
alpar@1041
    32
  checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
alpar@1041
    33
  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
alpar@1041
    34
alpar@1041
    35
  checkConcept<ReadMap<A,double>, AddMap<DoubleMap,DoubleMap> >();
alpar@1041
    36
  checkConcept<ReadMap<A,double>, SubMap<DoubleMap,DoubleMap> >();
alpar@1041
    37
  checkConcept<ReadMap<A,double>, MulMap<DoubleMap,DoubleMap> >();
alpar@1041
    38
  checkConcept<ReadMap<A,double>, DivMap<DoubleMap,DoubleMap> >();
alpar@1041
    39
  checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >();
alpar@1041
    40
  checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >();
alpar@1070
    41
  checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
alpar@1070
    42
  checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
alpar@1041
    43
  
alpar@1041
    44
  checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
alpar@1041
    45
deba@1675
    46
  checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >();
alpar@1076
    47
alpar@1076
    48
  int a;
alpar@1076
    49
  
alpar@1076
    50
  a=mapFunctor(constMap<A,int>(2))(A());
alpar@1076
    51
  check(a==2,"Something is wrong with mapFunctor");
alpar@1076
    52
alpar@1076
    53
  B b;
deba@1675
    54
  b=functorMap(F())[A()];
alpar@1076
    55
deba@1675
    56
  a=functorMap(&func)[A()];
alpar@1076
    57
  check(a==3,"Something is wrong with functorMap");
alpar@1076
    58
deba@1675
    59
  a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()];
deba@1675
    60
  check(a==4,"Something is wrong with combineMap");
deba@1675
    61
  
deba@1675
    62
alpar@1041
    63
  std::cout << __FILE__ ": All tests passed.\n";
alpar@1041
    64
  
alpar@1041
    65
  return 0;
alpar@1041
    66
}