[1041] | 1 | #include <lemon/concept_check.h> |
---|
| 2 | #include <lemon/concept/maps.h> |
---|
| 3 | #include <lemon/maps.h> |
---|
| 4 | |
---|
| 5 | #include "test_tools.h" |
---|
| 6 | |
---|
| 7 | using namespace lemon; |
---|
| 8 | using namespace lemon::concept; |
---|
| 9 | |
---|
| 10 | struct A {}; |
---|
| 11 | struct B {}; |
---|
[1675] | 12 | |
---|
| 13 | class F { |
---|
[1076] | 14 | public: |
---|
[1675] | 15 | typedef A argument_type; |
---|
| 16 | typedef B result_type; |
---|
| 17 | |
---|
[1375] | 18 | B operator()(const A &) const {return B();} |
---|
[1076] | 19 | }; |
---|
| 20 | |
---|
[1375] | 21 | int func(A) {return 3;} |
---|
[1041] | 22 | |
---|
[1675] | 23 | int binc(int, B) {return 4;} |
---|
| 24 | |
---|
[1041] | 25 | typedef ReadMap<A,double> DoubleMap; |
---|
| 26 | |
---|
| 27 | int main() |
---|
| 28 | { // checking graph components |
---|
| 29 | |
---|
| 30 | checkConcept<ReadMap<A,B>, ReadMap<A,B> >(); |
---|
| 31 | checkConcept<WriteMap<A,B>, WriteMap<A,B> >(); |
---|
| 32 | checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >(); |
---|
| 33 | checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >(); |
---|
| 34 | |
---|
| 35 | checkConcept<ReadMap<A,double>, AddMap<DoubleMap,DoubleMap> >(); |
---|
| 36 | checkConcept<ReadMap<A,double>, SubMap<DoubleMap,DoubleMap> >(); |
---|
| 37 | checkConcept<ReadMap<A,double>, MulMap<DoubleMap,DoubleMap> >(); |
---|
| 38 | checkConcept<ReadMap<A,double>, DivMap<DoubleMap,DoubleMap> >(); |
---|
| 39 | checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >(); |
---|
| 40 | checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >(); |
---|
[1070] | 41 | checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >(); |
---|
| 42 | checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >(); |
---|
[1041] | 43 | |
---|
| 44 | checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >(); |
---|
| 45 | |
---|
[1675] | 46 | checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >(); |
---|
[1076] | 47 | |
---|
| 48 | int a; |
---|
| 49 | |
---|
| 50 | a=mapFunctor(constMap<A,int>(2))(A()); |
---|
| 51 | check(a==2,"Something is wrong with mapFunctor"); |
---|
| 52 | |
---|
| 53 | B b; |
---|
[1675] | 54 | b=functorMap(F())[A()]; |
---|
[1076] | 55 | |
---|
[1675] | 56 | a=functorMap(&func)[A()]; |
---|
[1076] | 57 | check(a==3,"Something is wrong with functorMap"); |
---|
| 58 | |
---|
[1675] | 59 | a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()]; |
---|
| 60 | check(a==4,"Something is wrong with combineMap"); |
---|
| 61 | |
---|
| 62 | |
---|
[1041] | 63 | std::cout << __FILE__ ": All tests passed.\n"; |
---|
| 64 | |
---|
| 65 | return 0; |
---|
| 66 | } |
---|