test/maps_test.cc
branch1.1
changeset 1274 249467c099fd
parent 1158 8d2e55fac752
parent 1257 3e711ee55d31
equal deleted inserted replaced
30:87e405c8d764 35:acb9e4761a68
    78   // NullMap
    78   // NullMap
    79   {
    79   {
    80     checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
    80     checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
    81     NullMap<A,B> map1;
    81     NullMap<A,B> map1;
    82     NullMap<A,B> map2 = map1;
    82     NullMap<A,B> map2 = map1;
    83     ignore_unused_variable_warning(map2);
    83     ::lemon::ignore_unused_variable_warning(map2);
    84     map1 = nullMap<A,B>();
    84     map1 = nullMap<A,B>();
    85   }
    85   }
    86 
    86 
    87   // ConstMap
    87   // ConstMap
    88   {
    88   {
    89     checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
    89     checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
    90     checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
    90     checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
    91     ConstMap<A,B> map1;
    91     ConstMap<A,B> map1;
    92     ConstMap<A,B> map2 = B();
    92     ConstMap<A,B> map2 = B();
    93     ConstMap<A,B> map3 = map1;
    93     ConstMap<A,B> map3 = map1;
    94     ignore_unused_variable_warning(map2,map3);
    94     ::lemon::ignore_unused_variable_warning(map2,map3);
    95 
    95 
    96     map1 = constMap<A>(B());
    96     map1 = constMap<A>(B());
    97     map1 = constMap<A,B>();
    97     map1 = constMap<A,B>();
    98     map1.setAll(B());
    98     map1.setAll(B());
    99     ConstMap<A,C> map4(C(1));
    99     ConstMap<A,C> map4(C(1));
   100     ConstMap<A,C> map5 = map4;
   100     ConstMap<A,C> map5 = map4;
   101     ignore_unused_variable_warning(map5);
   101     ::lemon::ignore_unused_variable_warning(map5);
   102 
   102 
   103     map4 = constMap<A>(C(2));
   103     map4 = constMap<A>(C(2));
   104     map4.setAll(C(3));
   104     map4.setAll(C(3));
   105 
   105 
   106     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
   106     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
   118   // IdentityMap
   118   // IdentityMap
   119   {
   119   {
   120     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
   120     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
   121     IdentityMap<A> map1;
   121     IdentityMap<A> map1;
   122     IdentityMap<A> map2 = map1;
   122     IdentityMap<A> map2 = map1;
   123     ignore_unused_variable_warning(map2);
   123     ::lemon::ignore_unused_variable_warning(map2);
   124 
   124 
   125     map1 = identityMap<A>();
   125     map1 = identityMap<A>();
   126 
   126 
   127     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
   127     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
   128     check(identityMap<double>()[1.0] == 1.0 &&
   128     check(identityMap<double>()[1.0] == 1.0 &&
   179   // ComposeMap
   179   // ComposeMap
   180   {
   180   {
   181     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
   181     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
   182     checkConcept<ReadMap<B,double>, CompMap>();
   182     checkConcept<ReadMap<B,double>, CompMap>();
   183     CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
   183     CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
   184     ignore_unused_variable_warning(map1);
   184     ::lemon::ignore_unused_variable_warning(map1);
   185     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
   185     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
   186     ignore_unused_variable_warning(map2);
   186     ::lemon::ignore_unused_variable_warning(map2);
   187 
   187 
   188     SparseMap<double, bool> m1(false); m1[3.14] = true;
   188     SparseMap<double, bool> m1(false); m1[3.14] = true;
   189     RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
   189     RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
   190     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
   190     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
   191           "Something is wrong with ComposeMap")
   191           "Something is wrong with ComposeMap")
   194   // CombineMap
   194   // CombineMap
   195   {
   195   {
   196     typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
   196     typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
   197     checkConcept<ReadMap<A,double>, CombMap>();
   197     checkConcept<ReadMap<A,double>, CombMap>();
   198     CombMap map1 = CombMap(DoubleMap(), DoubleMap());
   198     CombMap map1 = CombMap(DoubleMap(), DoubleMap());
   199     ignore_unused_variable_warning(map1);
   199     ::lemon::ignore_unused_variable_warning(map1);
   200     CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
   200     CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
   201     ignore_unused_variable_warning(map2);
   201     ::lemon::ignore_unused_variable_warning(map2);
   202 
   202 
   203     check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
   203     check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
   204           "Something is wrong with CombineMap");
   204           "Something is wrong with CombineMap");
   205   }
   205   }
   206 
   206 
   208   {
   208   {
   209     checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
   209     checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
   210     checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
   210     checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
   211     FunctorToMap<F> map1;
   211     FunctorToMap<F> map1;
   212     FunctorToMap<F> map2 = FunctorToMap<F>(F());
   212     FunctorToMap<F> map2 = FunctorToMap<F>(F());
   213     ignore_unused_variable_warning(map2);
   213     ::lemon::ignore_unused_variable_warning(map2);
   214 
   214 
   215     B b = functorToMap(F())[A()];
   215     B b = functorToMap(F())[A()];
   216     ignore_unused_variable_warning(b);
   216     ::lemon::ignore_unused_variable_warning(b);
   217 
   217 
   218     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
   218     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
   219     MapToFunctor<ReadMap<A,B> > map =
   219     MapToFunctor<ReadMap<A,B> > map =
   220       MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
   220       MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
   221     ignore_unused_variable_warning(map);
   221     ::lemon::ignore_unused_variable_warning(map);
   222 
   222 
   223     check(functorToMap(&func)[A()] == 3,
   223     check(functorToMap(&func)[A()] == 3,
   224           "Something is wrong with FunctorToMap");
   224           "Something is wrong with FunctorToMap");
   225     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
   225     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
   226           "Something is wrong with MapToFunctor");
   226           "Something is wrong with MapToFunctor");
   234   // ConvertMap
   234   // ConvertMap
   235   {
   235   {
   236     checkConcept<ReadMap<double,double>,
   236     checkConcept<ReadMap<double,double>,
   237       ConvertMap<ReadMap<double, int>, double> >();
   237       ConvertMap<ReadMap<double, int>, double> >();
   238     ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
   238     ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
   239     ignore_unused_variable_warning(map1);
   239     ::lemon::ignore_unused_variable_warning(map1);
   240     ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
   240     ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
   241     ignore_unused_variable_warning(map2);
   241     ::lemon::ignore_unused_variable_warning(map2);
   242 
   242 
   243   }
   243   }
   244 
   244 
   245   // ForkMap
   245   // ForkMap
   246   {
   246   {