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