1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/maps_test.cc Fri Jan 04 21:45:55 2008 +0100
1.3 @@ -0,0 +1,108 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2003-2007
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#include <deque>
1.23 +#include <set>
1.24 +
1.25 +#include <lemon/concept_check.h>
1.26 +#include <lemon/concepts/maps.h>
1.27 +#include <lemon/maps.h>
1.28 +
1.29 +#include "test_tools.h"
1.30 +
1.31 +using namespace lemon;
1.32 +using namespace lemon::concepts;
1.33 +
1.34 +struct A {};
1.35 +inline bool operator<(A, A) { return true; }
1.36 +struct B {};
1.37 +
1.38 +class F {
1.39 +public:
1.40 + typedef A argument_type;
1.41 + typedef B result_type;
1.42 +
1.43 + B operator()(const A &) const {return B();}
1.44 +};
1.45 +
1.46 +int func(A) {return 3;}
1.47 +
1.48 +int binc(int, B) {return 4;}
1.49 +
1.50 +typedef ReadMap<A,double> DoubleMap;
1.51 +typedef ReadWriteMap<A, double> WriteDoubleMap;
1.52 +
1.53 +typedef ReadMap<A,bool> BoolMap;
1.54 +typedef ReadWriteMap<A, bool> BoolWriteMap;
1.55 +
1.56 +int main()
1.57 +{ // checking graph components
1.58 +
1.59 + checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
1.60 + checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
1.61 + checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
1.62 + checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
1.63 +
1.64 + checkConcept<ReadMap<A,double>, AddMap<DoubleMap,DoubleMap> >();
1.65 + checkConcept<ReadMap<A,double>, SubMap<DoubleMap,DoubleMap> >();
1.66 + checkConcept<ReadMap<A,double>, MulMap<DoubleMap,DoubleMap> >();
1.67 + checkConcept<ReadMap<A,double>, DivMap<DoubleMap,DoubleMap> >();
1.68 + checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >();
1.69 + checkConcept<ReadWriteMap<A,double>, NegWriteMap<WriteDoubleMap> >();
1.70 + checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >();
1.71 + checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
1.72 + checkConcept<ReadWriteMap<A,double>, ShiftWriteMap<WriteDoubleMap> >();
1.73 + checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
1.74 + checkConcept<ReadWriteMap<A,double>, ScaleWriteMap<WriteDoubleMap> >();
1.75 + checkConcept<ReadMap<A,double>, ForkMap<DoubleMap, DoubleMap> >();
1.76 + checkConcept<ReadWriteMap<A,double>,
1.77 + ForkWriteMap<WriteDoubleMap, WriteDoubleMap> >();
1.78 +
1.79 + checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
1.80 +
1.81 + checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >();
1.82 +
1.83 + checkConcept<ReadMap<A, bool>, NotMap<BoolMap> >();
1.84 + checkConcept<ReadWriteMap<A, bool>, NotWriteMap<BoolWriteMap> >();
1.85 +
1.86 + checkConcept<WriteMap<A, bool>, StoreBoolMap<A*> >();
1.87 + checkConcept<WriteMap<A, bool>, BackInserterBoolMap<std::deque<A> > >();
1.88 + checkConcept<WriteMap<A, bool>, FrontInserterBoolMap<std::deque<A> > >();
1.89 + checkConcept<WriteMap<A, bool>, InserterBoolMap<std::set<A> > >();
1.90 + checkConcept<WriteMap<A, bool>, FillBoolMap<WriteMap<A, B> > >();
1.91 + checkConcept<WriteMap<A, bool>, SettingOrderBoolMap<WriteMap<A, int> > >();
1.92 +
1.93 + int a;
1.94 +
1.95 + a=mapFunctor(constMap<A,int>(2))(A());
1.96 + check(a==2,"Something is wrong with mapFunctor");
1.97 +
1.98 + B b;
1.99 + b=functorMap(F())[A()];
1.100 +
1.101 + a=functorMap(&func)[A()];
1.102 + check(a==3,"Something is wrong with functorMap");
1.103 +
1.104 + a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()];
1.105 + check(a==4,"Something is wrong with combineMap");
1.106 +
1.107 +
1.108 + std::cout << __FILE__ ": All tests passed.\n";
1.109 +
1.110 + return 0;
1.111 +}