test/maps_test.cc
changeset 1090 70b199792735
parent 997 761fe0846f49
child 1084 8b2d4e5d96e4
equal deleted inserted replaced
25:7eff83a56142 28:8edba269074d
    76   // NullMap
    76   // NullMap
    77   {
    77   {
    78     checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
    78     checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
    79     NullMap<A,B> map1;
    79     NullMap<A,B> map1;
    80     NullMap<A,B> map2 = map1;
    80     NullMap<A,B> map2 = map1;
    81     ignore_unused_variable_warning(map2);
    81     ::lemon::ignore_unused_variable_warning(map2);
    82     map1 = nullMap<A,B>();
    82     map1 = nullMap<A,B>();
    83   }
    83   }
    84 
    84 
    85   // ConstMap
    85   // ConstMap
    86   {
    86   {
    87     checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
    87     checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
    88     checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
    88     checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
    89     ConstMap<A,B> map1;
    89     ConstMap<A,B> map1;
    90     ConstMap<A,B> map2 = B();
    90     ConstMap<A,B> map2 = B();
    91     ConstMap<A,B> map3 = map1;
    91     ConstMap<A,B> map3 = map1;
    92     ignore_unused_variable_warning(map2,map3);
    92     ::lemon::ignore_unused_variable_warning(map2,map3);
    93 
    93 
    94     map1 = constMap<A>(B());
    94     map1 = constMap<A>(B());
    95     map1 = constMap<A,B>();
    95     map1 = constMap<A,B>();
    96     map1.setAll(B());
    96     map1.setAll(B());
    97     ConstMap<A,C> map4(C(1));
    97     ConstMap<A,C> map4(C(1));
    98     ConstMap<A,C> map5 = map4;
    98     ConstMap<A,C> map5 = map4;
    99     ignore_unused_variable_warning(map5);
    99     ::lemon::ignore_unused_variable_warning(map5);
   100 
   100 
   101     map4 = constMap<A>(C(2));
   101     map4 = constMap<A>(C(2));
   102     map4.setAll(C(3));
   102     map4.setAll(C(3));
   103 
   103 
   104     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
   104     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
   116   // IdentityMap
   116   // IdentityMap
   117   {
   117   {
   118     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
   118     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
   119     IdentityMap<A> map1;
   119     IdentityMap<A> map1;
   120     IdentityMap<A> map2 = map1;
   120     IdentityMap<A> map2 = map1;
   121     ignore_unused_variable_warning(map2);
   121     ::lemon::ignore_unused_variable_warning(map2);
   122 
   122 
   123     map1 = identityMap<A>();
   123     map1 = identityMap<A>();
   124 
   124 
   125     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
   125     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
   126     check(identityMap<double>()[1.0] == 1.0 &&
   126     check(identityMap<double>()[1.0] == 1.0 &&
   177   // ComposeMap
   177   // ComposeMap
   178   {
   178   {
   179     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
   179     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
   180     checkConcept<ReadMap<B,double>, CompMap>();
   180     checkConcept<ReadMap<B,double>, CompMap>();
   181     CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
   181     CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
   182     ignore_unused_variable_warning(map1);
   182     ::lemon::ignore_unused_variable_warning(map1);
   183     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
   183     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
   184     ignore_unused_variable_warning(map2);
   184     ::lemon::ignore_unused_variable_warning(map2);
   185 
   185 
   186     SparseMap<double, bool> m1(false); m1[3.14] = true;
   186     SparseMap<double, bool> m1(false); m1[3.14] = true;
   187     RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
   187     RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
   188     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
   188     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
   189           "Something is wrong with ComposeMap")
   189           "Something is wrong with ComposeMap")
   192   // CombineMap
   192   // CombineMap
   193   {
   193   {
   194     typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
   194     typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
   195     checkConcept<ReadMap<A,double>, CombMap>();
   195     checkConcept<ReadMap<A,double>, CombMap>();
   196     CombMap map1 = CombMap(DoubleMap(), DoubleMap());
   196     CombMap map1 = CombMap(DoubleMap(), DoubleMap());
   197     ignore_unused_variable_warning(map1);
   197     ::lemon::ignore_unused_variable_warning(map1);
   198     CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
   198     CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
   199     ignore_unused_variable_warning(map2);
   199     ::lemon::ignore_unused_variable_warning(map2);
   200 
   200 
   201     check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
   201     check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
   202           "Something is wrong with CombineMap");
   202           "Something is wrong with CombineMap");
   203   }
   203   }
   204 
   204 
   206   {
   206   {
   207     checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
   207     checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
   208     checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
   208     checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
   209     FunctorToMap<F> map1;
   209     FunctorToMap<F> map1;
   210     FunctorToMap<F> map2 = FunctorToMap<F>(F());
   210     FunctorToMap<F> map2 = FunctorToMap<F>(F());
   211     ignore_unused_variable_warning(map2);
   211     ::lemon::ignore_unused_variable_warning(map2);
   212 
   212 
   213     B b = functorToMap(F())[A()];
   213     B b = functorToMap(F())[A()];
   214     ignore_unused_variable_warning(b);
   214     ::lemon::ignore_unused_variable_warning(b);
   215 
   215 
   216     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
   216     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
   217     MapToFunctor<ReadMap<A,B> > map =
   217     MapToFunctor<ReadMap<A,B> > map =
   218       MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
   218       MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
   219     ignore_unused_variable_warning(map);
   219     ::lemon::ignore_unused_variable_warning(map);
   220 
   220 
   221     check(functorToMap(&func)[A()] == 3,
   221     check(functorToMap(&func)[A()] == 3,
   222           "Something is wrong with FunctorToMap");
   222           "Something is wrong with FunctorToMap");
   223     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
   223     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
   224           "Something is wrong with MapToFunctor");
   224           "Something is wrong with MapToFunctor");
   232   // ConvertMap
   232   // ConvertMap
   233   {
   233   {
   234     checkConcept<ReadMap<double,double>,
   234     checkConcept<ReadMap<double,double>,
   235       ConvertMap<ReadMap<double, int>, double> >();
   235       ConvertMap<ReadMap<double, int>, double> >();
   236     ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
   236     ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
   237     ignore_unused_variable_warning(map1);
   237     ::lemon::ignore_unused_variable_warning(map1);
   238     ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
   238     ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
   239     ignore_unused_variable_warning(map2);
   239     ::lemon::ignore_unused_variable_warning(map2);
   240 
   240 
   241   }
   241   }
   242 
   242 
   243   // ForkMap
   243   // ForkMap
   244   {
   244   {