test/maps_test.cc
changeset 90 2981a73d49a3
parent 80 15968e25ca08
child 94 a4688e4138ec
equal deleted inserted replaced
2:39e717bee9cd 3:a0bdb4b8d32d
    76     ConstMap<A,B> map1;
    76     ConstMap<A,B> map1;
    77     ConstMap<A,B> map2(B());
    77     ConstMap<A,B> map2(B());
    78     ConstMap<A,B> map3 = map1;
    78     ConstMap<A,B> map3 = map1;
    79     map1 = constMap<A>(B());
    79     map1 = constMap<A>(B());
    80     map1.setAll(B());
    80     map1.setAll(B());
    81     
    81 
    82     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
    82     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
    83     check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
    83     check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
    84 
    84 
    85     checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
    85     checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
    86     ConstMap<A,Const<int,10> > map4;
    86     ConstMap<A,Const<int,10> > map4;
    93   {
    93   {
    94     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
    94     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
    95     IdentityMap<A> map1;
    95     IdentityMap<A> map1;
    96     IdentityMap<A> map2 = map1;
    96     IdentityMap<A> map2 = map1;
    97     map1 = identityMap<A>();
    97     map1 = identityMap<A>();
    98     
    98 
    99     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
    99     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
   100     check(identityMap<double>()[1.0] == 1.0 && identityMap<double>()[3.14] == 3.14,
   100     check(identityMap<double>()[1.0] == 1.0 && identityMap<double>()[3.14] == 3.14,
   101           "Something is wrong with IdentityMap");
   101           "Something is wrong with IdentityMap");
   102   }
   102   }
   103 
   103 
   149   {
   149   {
   150     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
   150     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
   151     checkConcept<ReadMap<B,double>, CompMap>();
   151     checkConcept<ReadMap<B,double>, CompMap>();
   152     CompMap map1(DoubleMap(),ReadMap<B,A>());
   152     CompMap map1(DoubleMap(),ReadMap<B,A>());
   153     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
   153     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
   154     
   154 
   155     SparseMap<double, bool> m1(false); m1[3.14] = true;
   155     SparseMap<double, bool> m1(false); m1[3.14] = true;
   156     RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
   156     RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
   157     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], "Something is wrong with ComposeMap")
   157     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], "Something is wrong with ComposeMap")
   158   }
   158   }
   159 
   159 
   195   }
   195   }
   196 
   196 
   197   // ForkMap
   197   // ForkMap
   198   {
   198   {
   199     checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
   199     checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
   200     
   200 
   201     typedef RangeMap<double> RM;
   201     typedef RangeMap<double> RM;
   202     typedef SparseMap<int, double> SM;
   202     typedef SparseMap<int, double> SM;
   203     RM m1(10, -1);
   203     RM m1(10, -1);
   204     SM m2(-1);
   204     SM m2(-1);
   205     checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
   205     checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
   208     ForkMap<SM, RM> map2 = forkMap(m2,m1);
   208     ForkMap<SM, RM> map2 = forkMap(m2,m1);
   209     map2.set(5, 10);
   209     map2.set(5, 10);
   210     check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
   210     check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
   211           "Something is wrong with ForkMap");
   211           "Something is wrong with ForkMap");
   212   }
   212   }
   213   
   213 
   214   // Arithmetic maps:
   214   // Arithmetic maps:
   215   // - AddMap, SubMap, MulMap, DivMap
   215   // - AddMap, SubMap, MulMap, DivMap
   216   // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
   216   // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
   217   // - NegMap, NegWriteMap, AbsMap
   217   // - NegMap, NegWriteMap, AbsMap
   218   {
   218   {
   219     checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
   219     checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
   220     checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
   220     checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
   221     checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
   221     checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
   222     checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
   222     checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
   223     
   223 
   224     ConstMap<int, double> c1(1.0), c2(3.14);
   224     ConstMap<int, double> c1(1.0), c2(3.14);
   225     IdentityMap<int> im;
   225     IdentityMap<int> im;
   226     ConvertMap<IdentityMap<int>, double> id(im);
   226     ConvertMap<IdentityMap<int>, double> id(im);
   227     check(addMap(c1,id)[0] == 1.0  && addMap(c1,id)[10] == 11.0, "Something is wrong with AddMap");
   227     check(addMap(c1,id)[0] == 1.0  && addMap(c1,id)[10] == 11.0, "Something is wrong with AddMap");
   228     check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0,  "Something is wrong with SubMap");
   228     check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0,  "Something is wrong with SubMap");
   229     check(mulMap(id,c2)[0] == 0    && mulMap(id,c2)[2]  == 6.28, "Something is wrong with MulMap");
   229     check(mulMap(id,c2)[0] == 0    && mulMap(id,c2)[2]  == 6.28, "Something is wrong with MulMap");
   230     check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2]  == 1.57, "Something is wrong with DivMap");
   230     check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2]  == 1.57, "Something is wrong with DivMap");
   231     
   231 
   232     checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
   232     checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
   233     checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
   233     checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
   234     checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
   234     checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
   235     checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
   235     checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
   236     checkConcept<DoubleMap, NegMap<DoubleMap> >();
   236     checkConcept<DoubleMap, NegMap<DoubleMap> >();
   250     check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
   250     check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
   251           "Something is wrong with NegWriteMap");
   251           "Something is wrong with NegWriteMap");
   252     check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
   252     check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
   253           "Something is wrong with AbsMap");
   253           "Something is wrong with AbsMap");
   254   }
   254   }
   255   
   255 
   256   // Logical maps
   256   // Logical maps:
   257   {
   257   // - TrueMap, FalseMap
       
   258   // - AndMap, OrMap
       
   259   // - NotMap, NotWriteMap
       
   260   // - EqualMap, LessMap
       
   261   {
       
   262     checkConcept<BoolMap, TrueMap<A> >();
       
   263     checkConcept<BoolMap, FalseMap<A> >();
       
   264     checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >();
       
   265     checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >();
   258     checkConcept<BoolMap, NotMap<BoolMap> >();
   266     checkConcept<BoolMap, NotMap<BoolMap> >();
   259     checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
   267     checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
   260     
   268     checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
       
   269     checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
       
   270 
       
   271     TrueMap<int> tm;
       
   272     FalseMap<int> fm;
   261     RangeMap<bool> rm(2);
   273     RangeMap<bool> rm(2);
   262     rm[0] = true; rm[1] = false;
   274     rm[0] = true; rm[1] = false;
   263     check(!(notMap(rm)[0]) && notMap(rm)[1], "Something is wrong with NotMap");
   275     check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] && !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
   264     check(!(notWriteMap(rm)[0]) && notWriteMap(rm)[1], "Something is wrong with NotWriteMap");
   276           "Something is wrong with AndMap");
       
   277     check(orMap(tm,rm)[0] && orMap(tm,rm)[1] && orMap(fm,rm)[0] && !orMap(fm,rm)[1],
       
   278           "Something is wrong with OrMap");
       
   279     check(!notMap(rm)[0] && notMap(rm)[1], "Something is wrong with NotMap");
       
   280     check(!notWriteMap(rm)[0] && notWriteMap(rm)[1], "Something is wrong with NotWriteMap");
       
   281 
       
   282     ConstMap<int, double> cm(2.0);
       
   283     IdentityMap<int> im;
       
   284     ConvertMap<IdentityMap<int>, double> id(im);
       
   285     check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
       
   286           "Something is wrong with LessMap");
       
   287     check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
       
   288           "Something is wrong with EqualMap");
   265   }
   289   }
   266 
   290 
   267   return 0;
   291   return 0;
   268 }
   292 }