test/maps_test.cc
author deba
Fri, 24 Feb 2006 11:13:09 +0000
changeset 1984 d4cbd10e1256
parent 1675 fa89ffb27a6d
child 2032 18c08f9129e4
permissions -rw-r--r--
Bug fix
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #include <lemon/concept_check.h>
    20 #include <lemon/concept/maps.h>
    21 #include <lemon/maps.h>
    22 
    23 #include "test_tools.h"
    24 
    25 using namespace lemon;
    26 using namespace lemon::concept;
    27 
    28 struct A {};
    29 struct B {};
    30 
    31 class F {
    32 public:
    33   typedef A argument_type;
    34   typedef B result_type;
    35 
    36   B operator()(const A &) const {return B();}
    37 };
    38 
    39 int func(A) {return 3;}
    40 
    41 int binc(int, B) {return 4;}
    42 
    43 typedef ReadMap<A,double> DoubleMap;
    44 
    45 int main()
    46 { // checking graph components
    47   
    48   checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
    49   checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
    50   checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
    51   checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
    52 
    53   checkConcept<ReadMap<A,double>, AddMap<DoubleMap,DoubleMap> >();
    54   checkConcept<ReadMap<A,double>, SubMap<DoubleMap,DoubleMap> >();
    55   checkConcept<ReadMap<A,double>, MulMap<DoubleMap,DoubleMap> >();
    56   checkConcept<ReadMap<A,double>, DivMap<DoubleMap,DoubleMap> >();
    57   checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >();
    58   checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >();
    59   checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
    60   checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
    61   
    62   checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
    63 
    64   checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >();
    65 
    66   int a;
    67   
    68   a=mapFunctor(constMap<A,int>(2))(A());
    69   check(a==2,"Something is wrong with mapFunctor");
    70 
    71   B b;
    72   b=functorMap(F())[A()];
    73 
    74   a=functorMap(&func)[A()];
    75   check(a==3,"Something is wrong with functorMap");
    76 
    77   a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()];
    78   check(a==4,"Something is wrong with combineMap");
    79   
    80 
    81   std::cout << __FILE__ ": All tests passed.\n";
    82   
    83   return 0;
    84 }