[1956] | 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 | |
---|
[1041] | 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 {}; |
---|
[1675] | 30 | |
---|
| 31 | class F { |
---|
[1076] | 32 | public: |
---|
[1675] | 33 | typedef A argument_type; |
---|
| 34 | typedef B result_type; |
---|
| 35 | |
---|
[1375] | 36 | B operator()(const A &) const {return B();} |
---|
[1076] | 37 | }; |
---|
| 38 | |
---|
[1375] | 39 | int func(A) {return 3;} |
---|
[1041] | 40 | |
---|
[1675] | 41 | int binc(int, B) {return 4;} |
---|
| 42 | |
---|
[1041] | 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> >(); |
---|
[1070] | 59 | checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >(); |
---|
| 60 | checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >(); |
---|
[1041] | 61 | |
---|
| 62 | checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >(); |
---|
| 63 | |
---|
[1675] | 64 | checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >(); |
---|
[1076] | 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; |
---|
[1675] | 72 | b=functorMap(F())[A()]; |
---|
[1076] | 73 | |
---|
[1675] | 74 | a=functorMap(&func)[A()]; |
---|
[1076] | 75 | check(a==3,"Something is wrong with functorMap"); |
---|
| 76 | |
---|
[1675] | 77 | a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()]; |
---|
| 78 | check(a==4,"Something is wrong with combineMap"); |
---|
| 79 | |
---|
| 80 | |
---|
[1041] | 81 | std::cout << __FILE__ ": All tests passed.\n"; |
---|
| 82 | |
---|
| 83 | return 0; |
---|
| 84 | } |
---|