test/maps_test.cc
changeset 1745 d356e54bdafc
parent 1435 8e85e6bbefdf
child 1956 a055123339d5
equal deleted inserted replaced
0:6342fb78c52e 1:dac6f55dfd09
     7 using namespace lemon;
     7 using namespace lemon;
     8 using namespace lemon::concept;
     8 using namespace lemon::concept;
     9 
     9 
    10 struct A {};
    10 struct A {};
    11 struct B {};
    11 struct B {};
    12 class F
    12 
    13 {
    13 class F {
    14 public:
    14 public:
       
    15   typedef A argument_type;
       
    16   typedef B result_type;
       
    17 
    15   B operator()(const A &) const {return B();}
    18   B operator()(const A &) const {return B();}
    16 };
    19 };
    17 
    20 
    18 int func(A) {return 3;}
    21 int func(A) {return 3;}
       
    22 
       
    23 int binc(int, B) {return 4;}
    19 
    24 
    20 typedef ReadMap<A,double> DoubleMap;
    25 typedef ReadMap<A,double> DoubleMap;
    21 
    26 
    22 int main()
    27 int main()
    23 { // checking graph components
    28 { // checking graph components
    36   checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
    41   checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
    37   checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
    42   checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
    38   
    43   
    39   checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
    44   checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
    40 
    45 
    41   checkConcept<ReadMap<A,B>, FunctorMap<A,B,F> >();
    46   checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >();
    42 
    47 
    43   int a;
    48   int a;
    44   
    49   
    45   a=mapFunctor(constMap<A,int>(2))(A());
    50   a=mapFunctor(constMap<A,int>(2))(A());
    46   check(a==2,"Something is wrong with mapFunctor");
    51   check(a==2,"Something is wrong with mapFunctor");
    47 
    52 
    48   B b;
    53   B b;
    49   b=functorMap<A,B>(F())[A()];
    54   b=functorMap(F())[A()];
    50 
    55 
    51   a=functorMap<A,int>(&func)[A()];
    56   a=functorMap(&func)[A()];
    52   check(a==3,"Something is wrong with functorMap");
    57   check(a==3,"Something is wrong with functorMap");
       
    58 
       
    59   a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()];
       
    60   check(a==4,"Something is wrong with combineMap");
       
    61   
    53 
    62 
    54   std::cout << __FILE__ ": All tests passed.\n";
    63   std::cout << __FILE__ ": All tests passed.\n";
    55   
    64   
    56   return 0;
    65   return 0;
    57 }
    66 }