test/maps_test.cc
branch1.1
changeset 793 8d2e55fac752
parent 761 f1398882a928
parent 792 761fe0846f49
child 808 bdfc038f364c
equal deleted inserted replaced
14:797d77020d63 16:87e405c8d764
    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     map1 = nullMap<A,B>();
    84     map1 = nullMap<A,B>();
    84   }
    85   }
    85 
    86 
    86   // ConstMap
    87   // ConstMap
    87   {
    88   {
    88     checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
    89     checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
    89     checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
    90     checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
    90     ConstMap<A,B> map1;
    91     ConstMap<A,B> map1;
    91     ConstMap<A,B> map2 = B();
    92     ConstMap<A,B> map2 = B();
    92     ConstMap<A,B> map3 = map1;
    93     ConstMap<A,B> map3 = map1;
       
    94     ignore_unused_variable_warning(map2,map3);
       
    95 
    93     map1 = constMap<A>(B());
    96     map1 = constMap<A>(B());
    94     map1 = constMap<A,B>();
    97     map1 = constMap<A,B>();
    95     map1.setAll(B());
    98     map1.setAll(B());
    96     ConstMap<A,C> map4(C(1));
    99     ConstMap<A,C> map4(C(1));
    97     ConstMap<A,C> map5 = map4;
   100     ConstMap<A,C> map5 = map4;
       
   101     ignore_unused_variable_warning(map5);
       
   102 
    98     map4 = constMap<A>(C(2));
   103     map4 = constMap<A>(C(2));
    99     map4.setAll(C(3));
   104     map4.setAll(C(3));
   100 
   105 
   101     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
   106     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
   102     check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
   107     check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
   113   // IdentityMap
   118   // IdentityMap
   114   {
   119   {
   115     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
   120     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
   116     IdentityMap<A> map1;
   121     IdentityMap<A> map1;
   117     IdentityMap<A> map2 = map1;
   122     IdentityMap<A> map2 = map1;
       
   123     ignore_unused_variable_warning(map2);
       
   124 
   118     map1 = identityMap<A>();
   125     map1 = identityMap<A>();
   119 
   126 
   120     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
   127     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
   121     check(identityMap<double>()[1.0] == 1.0 &&
   128     check(identityMap<double>()[1.0] == 1.0 &&
   122           identityMap<double>()[3.14] == 3.14,
   129           identityMap<double>()[3.14] == 3.14,
   172   // ComposeMap
   179   // ComposeMap
   173   {
   180   {
   174     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
   181     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
   175     checkConcept<ReadMap<B,double>, CompMap>();
   182     checkConcept<ReadMap<B,double>, CompMap>();
   176     CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
   183     CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
       
   184     ignore_unused_variable_warning(map1);
   177     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
   185     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
       
   186     ignore_unused_variable_warning(map2);
   178 
   187 
   179     SparseMap<double, bool> m1(false); m1[3.14] = true;
   188     SparseMap<double, bool> m1(false); m1[3.14] = true;
   180     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;
   181     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
   190     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
   182           "Something is wrong with ComposeMap")
   191           "Something is wrong with ComposeMap")
   185   // CombineMap
   194   // CombineMap
   186   {
   195   {
   187     typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
   196     typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
   188     checkConcept<ReadMap<A,double>, CombMap>();
   197     checkConcept<ReadMap<A,double>, CombMap>();
   189     CombMap map1 = CombMap(DoubleMap(), DoubleMap());
   198     CombMap map1 = CombMap(DoubleMap(), DoubleMap());
       
   199     ignore_unused_variable_warning(map1);
   190     CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
   200     CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
       
   201     ignore_unused_variable_warning(map2);
   191 
   202 
   192     check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
   203     check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
   193           "Something is wrong with CombineMap");
   204           "Something is wrong with CombineMap");
   194   }
   205   }
   195 
   206 
   197   {
   208   {
   198     checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
   209     checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
   199     checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
   210     checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
   200     FunctorToMap<F> map1;
   211     FunctorToMap<F> map1;
   201     FunctorToMap<F> map2 = FunctorToMap<F>(F());
   212     FunctorToMap<F> map2 = FunctorToMap<F>(F());
       
   213     ignore_unused_variable_warning(map2);
       
   214 
   202     B b = functorToMap(F())[A()];
   215     B b = functorToMap(F())[A()];
       
   216     ignore_unused_variable_warning(b);
   203 
   217 
   204     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
   218     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
   205     MapToFunctor<ReadMap<A,B> > map =
   219     MapToFunctor<ReadMap<A,B> > map =
   206       MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
   220       MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
       
   221     ignore_unused_variable_warning(map);
   207 
   222 
   208     check(functorToMap(&func)[A()] == 3,
   223     check(functorToMap(&func)[A()] == 3,
   209           "Something is wrong with FunctorToMap");
   224           "Something is wrong with FunctorToMap");
   210     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
   225     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
   211           "Something is wrong with MapToFunctor");
   226           "Something is wrong with MapToFunctor");
   219   // ConvertMap
   234   // ConvertMap
   220   {
   235   {
   221     checkConcept<ReadMap<double,double>,
   236     checkConcept<ReadMap<double,double>,
   222       ConvertMap<ReadMap<double, int>, double> >();
   237       ConvertMap<ReadMap<double, int>, double> >();
   223     ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
   238     ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
       
   239     ignore_unused_variable_warning(map1);
   224     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);
       
   242 
   225   }
   243   }
   226 
   244 
   227   // ForkMap
   245   // ForkMap
   228   {
   246   {
   229     checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
   247     checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();