test/maps_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Thu, 07 Feb 2008 22:25:42 +0000
changeset 68 a315a588a20d
parent 25 751cd8f9bb1c
child 80 15968e25ca08
permissions -rw-r--r--
Some usefull math constants

lemon/math.h also includes the standard cmath, so one should prefer using
just lemon/math.h instead of cmath.
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2008
     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 <deque>
    20 #include <set>
    21 
    22 #include <lemon/concept_check.h>
    23 #include <lemon/concepts/maps.h>
    24 #include <lemon/maps.h>
    25 
    26 #include "test_tools.h"
    27 
    28 using namespace lemon;
    29 using namespace lemon::concepts;
    30 
    31 struct A {};
    32 inline bool operator<(A, A) { return true; }
    33 struct B {};
    34 
    35 class F {
    36 public:
    37   typedef A argument_type;
    38   typedef B result_type;
    39 
    40   B operator()(const A &) const {return B();}
    41 };
    42 
    43 int func(A) {return 3;}
    44 
    45 int binc(int, B) {return 4;}
    46 
    47 typedef ReadMap<A,double> DoubleMap;
    48 typedef ReadWriteMap<A, double> WriteDoubleMap;
    49 
    50 typedef ReadMap<A,bool> BoolMap;
    51 typedef ReadWriteMap<A, bool> BoolWriteMap;
    52 
    53 int main()
    54 { // checking graph components
    55   
    56   checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
    57   checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
    58   checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
    59   checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
    60 
    61   checkConcept<ReadMap<A,double>, AddMap<DoubleMap,DoubleMap> >();
    62   checkConcept<ReadMap<A,double>, SubMap<DoubleMap,DoubleMap> >();
    63   checkConcept<ReadMap<A,double>, MulMap<DoubleMap,DoubleMap> >();
    64   checkConcept<ReadMap<A,double>, DivMap<DoubleMap,DoubleMap> >();
    65   checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >();
    66   checkConcept<ReadWriteMap<A,double>, NegWriteMap<WriteDoubleMap> >();
    67   checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >();
    68   checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
    69   checkConcept<ReadWriteMap<A,double>, ShiftWriteMap<WriteDoubleMap> >();
    70   checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
    71   checkConcept<ReadWriteMap<A,double>, ScaleWriteMap<WriteDoubleMap> >();
    72   checkConcept<ReadMap<A,double>, ForkMap<DoubleMap, DoubleMap> >();
    73   checkConcept<ReadWriteMap<A,double>, 
    74     ForkWriteMap<WriteDoubleMap, WriteDoubleMap> >();
    75   
    76   checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
    77 
    78   checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >();
    79 
    80   checkConcept<ReadMap<A, bool>, NotMap<BoolMap> >();
    81   checkConcept<ReadWriteMap<A, bool>, NotWriteMap<BoolWriteMap> >();
    82 
    83   checkConcept<WriteMap<A, bool>, StoreBoolMap<A*> >();
    84   checkConcept<WriteMap<A, bool>, BackInserterBoolMap<std::deque<A> > >();
    85   checkConcept<WriteMap<A, bool>, FrontInserterBoolMap<std::deque<A> > >();
    86   checkConcept<WriteMap<A, bool>, InserterBoolMap<std::set<A> > >();
    87   checkConcept<WriteMap<A, bool>, FillBoolMap<WriteMap<A, B> > >();
    88   checkConcept<WriteMap<A, bool>, SettingOrderBoolMap<WriteMap<A, int> > >();
    89 
    90   int a;
    91   
    92   a=mapFunctor(constMap<A,int>(2))(A());
    93   check(a==2,"Something is wrong with mapFunctor");
    94 
    95   B b;
    96   b=functorMap(F())[A()];
    97 
    98   a=functorMap(&func)[A()];
    99   check(a==3,"Something is wrong with functorMap");
   100 
   101   a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()];
   102   check(a==4,"Something is wrong with combineMap");
   103   
   104 
   105   std::cout << __FILE__ ": All tests passed.\n";
   106   
   107   return 0;
   108 }