test/maps_test.cc
changeset 1085 a337a0dd3f75
parent 998 7fdaa05a69a1
parent 1083 3e711ee55d31
child 1086 97f1760dcd13
equal deleted inserted replaced
26:5e06aef3fe7a 29:dc5aaa377cd0
   101   // NullMap
   101   // NullMap
   102   {
   102   {
   103     checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
   103     checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
   104     NullMap<A,B> map1;
   104     NullMap<A,B> map1;
   105     NullMap<A,B> map2 = map1;
   105     NullMap<A,B> map2 = map1;
   106     ignore_unused_variable_warning(map2);
   106     ::lemon::ignore_unused_variable_warning(map2);
   107     map1 = nullMap<A,B>();
   107     map1 = nullMap<A,B>();
   108   }
   108   }
   109 
   109 
   110   // ConstMap
   110   // ConstMap
   111   {
   111   {
   112     checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
   112     checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
   113     checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
   113     checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
   114     ConstMap<A,B> map1;
   114     ConstMap<A,B> map1;
   115     ConstMap<A,B> map2 = B();
   115     ConstMap<A,B> map2 = B();
   116     ConstMap<A,B> map3 = map1;
   116     ConstMap<A,B> map3 = map1;
   117     ignore_unused_variable_warning(map2,map3);
   117     ::lemon::ignore_unused_variable_warning(map2,map3);
   118 
   118 
   119     map1 = constMap<A>(B());
   119     map1 = constMap<A>(B());
   120     map1 = constMap<A,B>();
   120     map1 = constMap<A,B>();
   121     map1.setAll(B());
   121     map1.setAll(B());
   122     ConstMap<A,C> map4(C(1));
   122     ConstMap<A,C> map4(C(1));
   123     ConstMap<A,C> map5 = map4;
   123     ConstMap<A,C> map5 = map4;
   124     ignore_unused_variable_warning(map5);
   124     ::lemon::ignore_unused_variable_warning(map5);
   125 
   125 
   126     map4 = constMap<A>(C(2));
   126     map4 = constMap<A>(C(2));
   127     map4.setAll(C(3));
   127     map4.setAll(C(3));
   128 
   128 
   129     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
   129     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
   141   // IdentityMap
   141   // IdentityMap
   142   {
   142   {
   143     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
   143     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
   144     IdentityMap<A> map1;
   144     IdentityMap<A> map1;
   145     IdentityMap<A> map2 = map1;
   145     IdentityMap<A> map2 = map1;
   146     ignore_unused_variable_warning(map2);
   146     ::lemon::ignore_unused_variable_warning(map2);
   147 
   147 
   148     map1 = identityMap<A>();
   148     map1 = identityMap<A>();
   149 
   149 
   150     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
   150     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
   151     check(identityMap<double>()[1.0] == 1.0 &&
   151     check(identityMap<double>()[1.0] == 1.0 &&
   202   // ComposeMap
   202   // ComposeMap
   203   {
   203   {
   204     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
   204     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
   205     checkConcept<ReadMap<B,double>, CompMap>();
   205     checkConcept<ReadMap<B,double>, CompMap>();
   206     CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
   206     CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
   207     ignore_unused_variable_warning(map1);
   207     ::lemon::ignore_unused_variable_warning(map1);
   208     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
   208     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
   209     ignore_unused_variable_warning(map2);
   209     ::lemon::ignore_unused_variable_warning(map2);
   210 
   210 
   211     SparseMap<double, bool> m1(false); m1[3.14] = true;
   211     SparseMap<double, bool> m1(false); m1[3.14] = true;
   212     RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
   212     RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
   213     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
   213     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
   214           "Something is wrong with ComposeMap")
   214           "Something is wrong with ComposeMap")
   217   // CombineMap
   217   // CombineMap
   218   {
   218   {
   219     typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
   219     typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
   220     checkConcept<ReadMap<A,double>, CombMap>();
   220     checkConcept<ReadMap<A,double>, CombMap>();
   221     CombMap map1 = CombMap(DoubleMap(), DoubleMap());
   221     CombMap map1 = CombMap(DoubleMap(), DoubleMap());
   222     ignore_unused_variable_warning(map1);
   222     ::lemon::ignore_unused_variable_warning(map1);
   223     CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
   223     CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
   224     ignore_unused_variable_warning(map2);
   224     ::lemon::ignore_unused_variable_warning(map2);
   225 
   225 
   226     check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
   226     check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
   227           "Something is wrong with CombineMap");
   227           "Something is wrong with CombineMap");
   228   }
   228   }
   229 
   229 
   231   {
   231   {
   232     checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
   232     checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
   233     checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
   233     checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
   234     FunctorToMap<F> map1;
   234     FunctorToMap<F> map1;
   235     FunctorToMap<F> map2 = FunctorToMap<F>(F());
   235     FunctorToMap<F> map2 = FunctorToMap<F>(F());
   236     ignore_unused_variable_warning(map2);
   236     ::lemon::ignore_unused_variable_warning(map2);
   237 
   237 
   238     B b = functorToMap(F())[A()];
   238     B b = functorToMap(F())[A()];
   239     ignore_unused_variable_warning(b);
   239     ::lemon::ignore_unused_variable_warning(b);
   240 
   240 
   241     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
   241     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
   242     MapToFunctor<ReadMap<A,B> > map =
   242     MapToFunctor<ReadMap<A,B> > map =
   243       MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
   243       MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
   244     ignore_unused_variable_warning(map);
   244     ::lemon::ignore_unused_variable_warning(map);
   245 
   245 
   246     check(functorToMap(&func)[A()] == 3,
   246     check(functorToMap(&func)[A()] == 3,
   247           "Something is wrong with FunctorToMap");
   247           "Something is wrong with FunctorToMap");
   248     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
   248     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
   249           "Something is wrong with MapToFunctor");
   249           "Something is wrong with MapToFunctor");
   257   // ConvertMap
   257   // ConvertMap
   258   {
   258   {
   259     checkConcept<ReadMap<double,double>,
   259     checkConcept<ReadMap<double,double>,
   260       ConvertMap<ReadMap<double, int>, double> >();
   260       ConvertMap<ReadMap<double, int>, double> >();
   261     ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
   261     ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
   262     ignore_unused_variable_warning(map1);
   262     ::lemon::ignore_unused_variable_warning(map1);
   263     ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
   263     ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
   264     ignore_unused_variable_warning(map2);
   264     ::lemon::ignore_unused_variable_warning(map2);
   265 
   265 
   266   }
   266   }
   267 
   267 
   268   // ForkMap
   268   // ForkMap
   269   {
   269   {