diff --git a/test/maps_test.cc b/test/maps_test.cc --- a/test/maps_test.cc +++ b/test/maps_test.cc @@ -37,72 +37,232 @@ typedef A argument_type; typedef B result_type; - B operator()(const A &) const {return B();} + B operator()(const A&) const { return B(); } +private: + F& operator=(const F&); }; -int func(A) {return 3;} +int func(A) { return 3; } -int binc(int, B) {return 4;} +int binc(int a, B) { return a+1; } -typedef ReadMap DoubleMap; -typedef ReadWriteMap WriteDoubleMap; +typedef ReadMap DoubleMap; +typedef ReadWriteMap DoubleWriteMap; +typedef ReferenceMap DoubleRefMap; -typedef ReadMap BoolMap; +typedef ReadMap BoolMap; typedef ReadWriteMap BoolWriteMap; +typedef ReferenceMap BoolRefMap; int main() -{ // checking graph components - +{ + // Map concepts checkConcept, ReadMap >(); checkConcept, WriteMap >(); checkConcept, ReadWriteMap >(); checkConcept, ReferenceMap >(); - checkConcept, AddMap >(); - checkConcept, SubMap >(); - checkConcept, MulMap >(); - checkConcept, DivMap >(); - checkConcept, NegMap >(); - checkConcept, NegWriteMap >(); - checkConcept, AbsMap >(); - checkConcept, ShiftMap >(); - checkConcept, ShiftWriteMap >(); - checkConcept, ScaleMap >(); - checkConcept, ScaleWriteMap >(); - checkConcept, ForkMap >(); - checkConcept, - ForkWriteMap >(); + // NullMap + { + checkConcept, NullMap >(); + NullMap map1; + NullMap map2 = map1; + map1 = nullMap(); + } + + // ConstMap + { + checkConcept, ConstMap >(); + ConstMap map1; + ConstMap map2(B()); + ConstMap map3 = map1; + map1 = constMap(B()); + map1.setAll(B()); + + checkConcept, ConstMap >(); + check(constMap(10)[A()] == 10, "Something is wrong with ConstMap"); + + checkConcept, ConstMap > >(); + ConstMap > map4; + ConstMap > map5 = map4; + map4 = map5; + check(map4[A()] == 10 && map5[A()] == 10, "Something is wrong with ConstMap"); + } + + // IdentityMap + { + checkConcept, IdentityMap >(); + IdentityMap map1; + IdentityMap map2 = map1; + map1 = identityMap(); + + checkConcept, IdentityMap >(); + check(identityMap()[1.0] == 1.0 && identityMap()[3.14] == 3.14, + "Something is wrong with IdentityMap"); + } + + // RangeMap + { + checkConcept, RangeMap >(); + RangeMap map1; + RangeMap map2(10); + RangeMap map3(10,B()); + RangeMap map4 = map1; + RangeMap map5 = rangeMap(); + RangeMap map6 = rangeMap(10); + RangeMap map7 = rangeMap(10,B()); + + checkConcept< ReferenceMap, + RangeMap >(); + std::vector v(10, 0); + v[5] = 100; + RangeMap map8(v); + RangeMap map9 = rangeMap(v); + check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100, + "Something is wrong with RangeMap"); + } + + // SparseMap + { + checkConcept, SparseMap >(); + SparseMap map1; + SparseMap map2(B()); + SparseMap map3 = sparseMap(); + SparseMap map4 = sparseMap(B()); + + checkConcept< ReferenceMap, + SparseMap >(); + std::map m; + SparseMap map5(m); + SparseMap map6(m,10); + SparseMap map7 = sparseMap(m); + SparseMap map8 = sparseMap(m,10); + + check(map5[1.0] == 0 && map5[3.14] == 0 && map6[1.0] == 10 && map6[3.14] == 10, + "Something is wrong with SparseMap"); + map5[1.0] = map6[3.14] = 100; + check(map5[1.0] == 100 && map5[3.14] == 0 && map6[1.0] == 10 && map6[3.14] == 100, + "Something is wrong with SparseMap"); + } + + // ComposeMap + { + typedef ComposeMap > CompMap; + checkConcept, CompMap>(); + CompMap map1(DoubleMap(),ReadMap()); + CompMap map2 = composeMap(DoubleMap(), ReadMap()); + + SparseMap m1(false); m1[3.14] = true; + RangeMap m2(2); m2[0] = 3.0; m2[1] = 3.14; + check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], "Something is wrong with ComposeMap") + } + + // CombineMap + { + typedef CombineMap > CombMap; + checkConcept, CombMap>(); + CombMap map1(DoubleMap(), DoubleMap()); + CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus()); + + check(combineMap(constMap(), identityMap(), &binc)[B()] == 3, + "Something is wrong with CombineMap"); + } + + // FunctorToMap, MapToFunctor + { + checkConcept, FunctorToMap >(); + checkConcept, FunctorToMap >(); + FunctorToMap map1; + FunctorToMap map2(F()); + B b = functorToMap(F())[A()]; + + checkConcept, MapToFunctor > >(); + MapToFunctor > map(ReadMap()); + + check(functorToMap(&func)[A()] == 3, "Something is wrong with FunctorToMap"); + check(mapToFunctor(constMap(2))(A()) == 2, "Something is wrong with MapToFunctor"); + check(mapToFunctor(functorToMap(&func))(A()) == 3 && mapToFunctor(functorToMap(&func))[A()] == 3, + "Something is wrong with FunctorToMap or MapToFunctor"); + check(functorToMap(mapToFunctor(constMap(2)))[A()] == 2, + "Something is wrong with FunctorToMap or MapToFunctor"); + } + + // ConvertMap + { + checkConcept, ConvertMap, double> >(); + ConvertMap, int> map1(rangeMap(1, true)); + ConvertMap, int> map2 = convertMap(rangeMap(2, false)); + } + + // ForkMap + { + checkConcept >(); + + typedef RangeMap RM; + typedef SparseMap SM; + RM m1(10, -1); + SM m2(-1); + checkConcept, ForkMap >(); + checkConcept, ForkMap >(); + ForkMap map1(m1,m2); + ForkMap map2 = forkMap(m2,m1); + map2.set(5, 10); + check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && m2[5] == 10 && map2[1] == -1 && map2[5] == 10, + "Something is wrong with ForkMap"); + } - checkConcept, ComposeMap > >(); + // Arithmetic maps: + // - AddMap, SubMap, MulMap, DivMap + // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap + // - NegMap, NegWriteMap, AbsMap + { + checkConcept >(); + checkConcept >(); + checkConcept >(); + checkConcept >(); + + ConstMap c1(1.0), c2(3.14); + IdentityMap im; + ConvertMap, double> id(im); + check(addMap(c1,id)[0] == 1.0 && addMap(c1,id)[10] == 11.0, "Something is wrong with AddMap"); + check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0, "Something is wrong with SubMap"); + check(mulMap(id,c2)[0] == 0 && mulMap(id,c2)[2] == 6.28, "Something is wrong with MulMap"); + check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2] == 1.57, "Something is wrong with DivMap"); + + checkConcept >(); + checkConcept >(); + checkConcept >(); + checkConcept >(); + checkConcept >(); + checkConcept >(); + checkConcept >(); - checkConcept, FunctorMap >(); + check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0, + "Something is wrong with ShiftMap"); + check(shiftWriteMap(id, 2.0)[1] == 3.0 && shiftWriteMap(id, 2.0)[10] == 12.0, + "Something is wrong with ShiftWriteMap"); + check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0, + "Something is wrong with ScaleMap"); + check(scaleWriteMap(id, 2.0)[1] == 2.0 && scaleWriteMap(id, 2.0)[10] == 20.0, + "Something is wrong with ScaleWriteMap"); + check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0, + "Something is wrong with NegMap"); + check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0, + "Something is wrong with NegWriteMap"); + check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0, + "Something is wrong with AbsMap"); + } + + // Logical maps + { + checkConcept >(); + checkConcept >(); + + RangeMap rm(2); + rm[0] = true; rm[1] = false; + check(!(notMap(rm)[0]) && notMap(rm)[1], "Something is wrong with NotMap"); + check(!(notWriteMap(rm)[0]) && notWriteMap(rm)[1], "Something is wrong with NotWriteMap"); + } - checkConcept, NotMap >(); - checkConcept, NotWriteMap >(); - - checkConcept, StoreBoolMap >(); - checkConcept, BackInserterBoolMap > >(); - checkConcept, FrontInserterBoolMap > >(); - checkConcept, InserterBoolMap > >(); - checkConcept, FillBoolMap > >(); - checkConcept, SettingOrderBoolMap > >(); - - int a; - - a=mapFunctor(constMap(2))(A()); - check(a==2,"Something is wrong with mapFunctor"); - - B b; - b=functorMap(F())[A()]; - - a=functorMap(&func)[A()]; - check(a==3,"Something is wrong with functorMap"); - - a=combineMap(constMap(), identityMap(), &binc)[B()]; - check(a==4,"Something is wrong with combineMap"); - - - std::cout << __FILE__ ": All tests passed.\n"; - return 0; }