alpar@209: /* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@25:  *
alpar@209:  * This file is a part of LEMON, a generic C++ optimization library.
alpar@25:  *
alpar@877:  * Copyright (C) 2003-2010
alpar@25:  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@25:  * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@25:  *
alpar@25:  * Permission to use, modify and distribute this software is granted
alpar@25:  * provided that this copyright notice appears in all copies. For
alpar@25:  * precise terms see the accompanying LICENSE file.
alpar@25:  *
alpar@25:  * This software is provided "AS IS" with no warranty of any kind,
alpar@25:  * express or implied, and with no claim as to its suitability for any
alpar@25:  * purpose.
alpar@25:  *
alpar@25:  */
alpar@25: 
alpar@25: #include <deque>
alpar@25: #include <set>
alpar@25: 
alpar@25: #include <lemon/concept_check.h>
alpar@25: #include <lemon/concepts/maps.h>
alpar@25: #include <lemon/maps.h>
kpeter@684: #include <lemon/list_graph.h>
kpeter@694: #include <lemon/smart_graph.h>
kpeter@723: #include <lemon/adaptors.h>
kpeter@723: #include <lemon/dfs.h>
kpeter@789: #include <algorithm>
alpar@25: 
alpar@25: #include "test_tools.h"
alpar@25: 
alpar@25: using namespace lemon;
alpar@25: using namespace lemon::concepts;
alpar@25: 
alpar@25: struct A {};
alpar@25: inline bool operator<(A, A) { return true; }
alpar@25: struct B {};
alpar@25: 
kpeter@94: class C {
kpeter@789:   int _x;
kpeter@94: public:
kpeter@789:   C(int x) : _x(x) {}
kpeter@789:   int get() const { return _x; }
kpeter@789: };
kpeter@789: inline bool operator<(C c1, C c2) { return c1.get() < c2.get(); }
kpeter@789: inline bool operator==(C c1, C c2) { return c1.get() == c2.get(); }
kpeter@789: 
kpeter@789: C createC(int x) { return C(x); }
kpeter@789: 
kpeter@789: template <typename T>
kpeter@789: class Less {
kpeter@789:   T _t;
kpeter@789: public:
kpeter@789:   Less(T t): _t(t) {}
kpeter@789:   bool operator()(const T& t) const { return t < _t; }
kpeter@94: };
kpeter@94: 
alpar@25: class F {
alpar@25: public:
alpar@25:   typedef A argument_type;
alpar@25:   typedef B result_type;
alpar@25: 
kpeter@80:   B operator()(const A&) const { return B(); }
kpeter@80: private:
kpeter@80:   F& operator=(const F&);
alpar@25: };
alpar@25: 
kpeter@80: int func(A) { return 3; }
alpar@25: 
kpeter@80: int binc(int a, B) { return a+1; }
alpar@25: 
kpeter@789: template <typename T>
kpeter@789: class Sum {
kpeter@789:   T& _sum;
kpeter@789: public:
kpeter@789:   Sum(T& sum) : _sum(sum) {}
kpeter@789:   void operator()(const T& t) { _sum += t; }
kpeter@789: };
kpeter@789: 
kpeter@80: typedef ReadMap<A, double> DoubleMap;
kpeter@80: typedef ReadWriteMap<A, double> DoubleWriteMap;
kpeter@80: typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
alpar@25: 
kpeter@80: typedef ReadMap<A, bool> BoolMap;
alpar@25: typedef ReadWriteMap<A, bool> BoolWriteMap;
kpeter@80: typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
alpar@25: 
alpar@25: int main()
kpeter@80: {
kpeter@80:   // Map concepts
alpar@25:   checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
kpeter@94:   checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
alpar@25:   checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
kpeter@94:   checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
alpar@25:   checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
kpeter@94:   checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
alpar@25:   checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
kpeter@94:   checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
alpar@25: 
kpeter@80:   // NullMap
kpeter@80:   {
kpeter@80:     checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
kpeter@80:     NullMap<A,B> map1;
kpeter@80:     NullMap<A,B> map2 = map1;
kpeter@80:     map1 = nullMap<A,B>();
kpeter@80:   }
kpeter@80: 
kpeter@80:   // ConstMap
kpeter@80:   {
kpeter@80:     checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
kpeter@123:     checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
kpeter@80:     ConstMap<A,B> map1;
deba@136:     ConstMap<A,B> map2 = B();
kpeter@80:     ConstMap<A,B> map3 = map1;
kpeter@80:     map1 = constMap<A>(B());
kpeter@123:     map1 = constMap<A,B>();
kpeter@80:     map1.setAll(B());
kpeter@123:     ConstMap<A,C> map4(C(1));
kpeter@123:     ConstMap<A,C> map5 = map4;
kpeter@123:     map4 = constMap<A>(C(2));
kpeter@123:     map4.setAll(C(3));
kpeter@82: 
kpeter@80:     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
kpeter@80:     check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
kpeter@80: 
kpeter@80:     checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
kpeter@123:     ConstMap<A,Const<int,10> > map6;
kpeter@123:     ConstMap<A,Const<int,10> > map7 = map6;
kpeter@123:     map6 = constMap<A,int,10>();
kpeter@123:     map7 = constMap<A,Const<int,10> >();
alpar@210:     check(map6[A()] == 10 && map7[A()] == 10,
alpar@210:           "Something is wrong with ConstMap");
kpeter@80:   }
kpeter@80: 
kpeter@80:   // IdentityMap
kpeter@80:   {
kpeter@80:     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
kpeter@80:     IdentityMap<A> map1;
kpeter@80:     IdentityMap<A> map2 = map1;
kpeter@80:     map1 = identityMap<A>();
kpeter@82: 
kpeter@80:     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
alpar@210:     check(identityMap<double>()[1.0] == 1.0 &&
alpar@210:           identityMap<double>()[3.14] == 3.14,
kpeter@80:           "Something is wrong with IdentityMap");
kpeter@80:   }
kpeter@80: 
kpeter@80:   // RangeMap
kpeter@80:   {
kpeter@80:     checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >();
kpeter@80:     RangeMap<B> map1;
kpeter@80:     RangeMap<B> map2(10);
kpeter@80:     RangeMap<B> map3(10,B());
kpeter@80:     RangeMap<B> map4 = map1;
kpeter@80:     RangeMap<B> map5 = rangeMap<B>();
kpeter@80:     RangeMap<B> map6 = rangeMap<B>(10);
kpeter@80:     RangeMap<B> map7 = rangeMap(10,B());
kpeter@80: 
kpeter@80:     checkConcept< ReferenceMap<int, double, double&, const double&>,
kpeter@80:                   RangeMap<double> >();
kpeter@80:     std::vector<double> v(10, 0);
kpeter@80:     v[5] = 100;
kpeter@80:     RangeMap<double> map8(v);
kpeter@80:     RangeMap<double> map9 = rangeMap(v);
kpeter@80:     check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100,
kpeter@80:           "Something is wrong with RangeMap");
kpeter@80:   }
kpeter@80: 
kpeter@80:   // SparseMap
kpeter@80:   {
kpeter@80:     checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >();
kpeter@80:     SparseMap<A,B> map1;
deba@136:     SparseMap<A,B> map2 = B();
kpeter@80:     SparseMap<A,B> map3 = sparseMap<A,B>();
kpeter@80:     SparseMap<A,B> map4 = sparseMap<A>(B());
kpeter@80: 
kpeter@80:     checkConcept< ReferenceMap<double, int, int&, const int&>,
kpeter@80:                   SparseMap<double, int> >();
kpeter@80:     std::map<double, int> m;
kpeter@80:     SparseMap<double, int> map5(m);
kpeter@80:     SparseMap<double, int> map6(m,10);
kpeter@80:     SparseMap<double, int> map7 = sparseMap(m);
kpeter@80:     SparseMap<double, int> map8 = sparseMap(m,10);
kpeter@80: 
alpar@210:     check(map5[1.0] == 0 && map5[3.14] == 0 &&
alpar@210:           map6[1.0] == 10 && map6[3.14] == 10,
kpeter@80:           "Something is wrong with SparseMap");
kpeter@80:     map5[1.0] = map6[3.14] = 100;
alpar@210:     check(map5[1.0] == 100 && map5[3.14] == 0 &&
alpar@210:           map6[1.0] == 10 && map6[3.14] == 100,
kpeter@80:           "Something is wrong with SparseMap");
kpeter@80:   }
kpeter@80: 
kpeter@80:   // ComposeMap
kpeter@80:   {
kpeter@80:     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
kpeter@80:     checkConcept<ReadMap<B,double>, CompMap>();
alpar@507:     CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
kpeter@80:     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
kpeter@82: 
kpeter@80:     SparseMap<double, bool> m1(false); m1[3.14] = true;
kpeter@80:     RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
alpar@210:     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
alpar@210:           "Something is wrong with ComposeMap")
kpeter@80:   }
kpeter@80: 
kpeter@80:   // CombineMap
kpeter@80:   {
kpeter@80:     typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
kpeter@80:     checkConcept<ReadMap<A,double>, CombMap>();
alpar@507:     CombMap map1 = CombMap(DoubleMap(), DoubleMap());
kpeter@80:     CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
kpeter@80: 
kpeter@80:     check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
kpeter@80:           "Something is wrong with CombineMap");
kpeter@80:   }
kpeter@80: 
kpeter@80:   // FunctorToMap, MapToFunctor
kpeter@80:   {
kpeter@80:     checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
kpeter@80:     checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
kpeter@80:     FunctorToMap<F> map1;
alpar@507:     FunctorToMap<F> map2 = FunctorToMap<F>(F());
kpeter@80:     B b = functorToMap(F())[A()];
kpeter@80: 
kpeter@80:     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
alpar@877:     MapToFunctor<ReadMap<A,B> > map =
alpar@877:       MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
kpeter@80: 
alpar@210:     check(functorToMap(&func)[A()] == 3,
alpar@210:           "Something is wrong with FunctorToMap");
alpar@210:     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
alpar@210:           "Something is wrong with MapToFunctor");
alpar@210:     check(mapToFunctor(functorToMap(&func))(A()) == 3 &&
alpar@210:           mapToFunctor(functorToMap(&func))[A()] == 3,
kpeter@80:           "Something is wrong with FunctorToMap or MapToFunctor");
kpeter@80:     check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2,
kpeter@80:           "Something is wrong with FunctorToMap or MapToFunctor");
kpeter@80:   }
kpeter@80: 
kpeter@80:   // ConvertMap
kpeter@80:   {
alpar@210:     checkConcept<ReadMap<double,double>,
alpar@210:       ConvertMap<ReadMap<double, int>, double> >();
kpeter@80:     ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
kpeter@80:     ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
kpeter@80:   }
kpeter@80: 
kpeter@80:   // ForkMap
kpeter@80:   {
kpeter@80:     checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
kpeter@82: 
kpeter@80:     typedef RangeMap<double> RM;
kpeter@80:     typedef SparseMap<int, double> SM;
kpeter@80:     RM m1(10, -1);
kpeter@80:     SM m2(-1);
kpeter@80:     checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
kpeter@80:     checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >();
kpeter@80:     ForkMap<RM, SM> map1(m1,m2);
kpeter@80:     ForkMap<SM, RM> map2 = forkMap(m2,m1);
kpeter@80:     map2.set(5, 10);
alpar@210:     check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 &&
alpar@210:           m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
kpeter@80:           "Something is wrong with ForkMap");
kpeter@80:   }
kpeter@82: 
kpeter@80:   // Arithmetic maps:
kpeter@80:   // - AddMap, SubMap, MulMap, DivMap
kpeter@80:   // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
kpeter@80:   // - NegMap, NegWriteMap, AbsMap
kpeter@80:   {
kpeter@80:     checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
kpeter@80:     checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
kpeter@80:     checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
kpeter@80:     checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
kpeter@82: 
kpeter@80:     ConstMap<int, double> c1(1.0), c2(3.14);
kpeter@80:     IdentityMap<int> im;
kpeter@80:     ConvertMap<IdentityMap<int>, double> id(im);
alpar@210:     check(addMap(c1,id)[0] == 1.0  && addMap(c1,id)[10] == 11.0,
alpar@210:           "Something is wrong with AddMap");
alpar@210:     check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0,
alpar@210:           "Something is wrong with SubMap");
alpar@210:     check(mulMap(id,c2)[0] == 0    && mulMap(id,c2)[2]  == 6.28,
alpar@210:           "Something is wrong with MulMap");
alpar@210:     check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2]  == 1.57,
alpar@210:           "Something is wrong with DivMap");
kpeter@82: 
kpeter@80:     checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
kpeter@80:     checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
kpeter@80:     checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
kpeter@80:     checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
kpeter@80:     checkConcept<DoubleMap, NegMap<DoubleMap> >();
kpeter@80:     checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >();
kpeter@80:     checkConcept<DoubleMap, AbsMap<DoubleMap> >();
alpar@25: 
kpeter@80:     check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0,
kpeter@80:           "Something is wrong with ShiftMap");
alpar@210:     check(shiftWriteMap(id, 2.0)[1] == 3.0 &&
alpar@210:           shiftWriteMap(id, 2.0)[10] == 12.0,
kpeter@80:           "Something is wrong with ShiftWriteMap");
kpeter@80:     check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0,
kpeter@80:           "Something is wrong with ScaleMap");
alpar@210:     check(scaleWriteMap(id, 2.0)[1] == 2.0 &&
alpar@210:           scaleWriteMap(id, 2.0)[10] == 20.0,
kpeter@80:           "Something is wrong with ScaleWriteMap");
kpeter@80:     check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0,
kpeter@80:           "Something is wrong with NegMap");
kpeter@80:     check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
kpeter@80:           "Something is wrong with NegWriteMap");
kpeter@80:     check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
kpeter@80:           "Something is wrong with AbsMap");
kpeter@80:   }
kpeter@82: 
kpeter@82:   // Logical maps:
kpeter@82:   // - TrueMap, FalseMap
kpeter@82:   // - AndMap, OrMap
kpeter@82:   // - NotMap, NotWriteMap
kpeter@82:   // - EqualMap, LessMap
kpeter@80:   {
kpeter@82:     checkConcept<BoolMap, TrueMap<A> >();
kpeter@82:     checkConcept<BoolMap, FalseMap<A> >();
kpeter@82:     checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >();
kpeter@82:     checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >();
kpeter@80:     checkConcept<BoolMap, NotMap<BoolMap> >();
kpeter@80:     checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
kpeter@82:     checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
kpeter@82:     checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
kpeter@82: 
kpeter@82:     TrueMap<int> tm;
kpeter@82:     FalseMap<int> fm;
kpeter@80:     RangeMap<bool> rm(2);
kpeter@80:     rm[0] = true; rm[1] = false;
alpar@210:     check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] &&
alpar@210:           !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
kpeter@82:           "Something is wrong with AndMap");
alpar@210:     check(orMap(tm,rm)[0] && orMap(tm,rm)[1] &&
alpar@210:           orMap(fm,rm)[0] && !orMap(fm,rm)[1],
kpeter@82:           "Something is wrong with OrMap");
alpar@210:     check(!notMap(rm)[0] && notMap(rm)[1],
alpar@210:           "Something is wrong with NotMap");
alpar@210:     check(!notWriteMap(rm)[0] && notWriteMap(rm)[1],
alpar@210:           "Something is wrong with NotWriteMap");
kpeter@82: 
kpeter@82:     ConstMap<int, double> cm(2.0);
kpeter@82:     IdentityMap<int> im;
kpeter@82:     ConvertMap<IdentityMap<int>, double> id(im);
kpeter@82:     check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
kpeter@82:           "Something is wrong with LessMap");
kpeter@82:     check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
kpeter@82:           "Something is wrong with EqualMap");
kpeter@80:   }
alpar@209: 
kpeter@167:   // LoggerBoolMap
kpeter@159:   {
kpeter@159:     typedef std::vector<int> vec;
kpeter@720:     checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
kpeter@720:     checkConcept<WriteMap<int, bool>,
kpeter@720:                  LoggerBoolMap<std::back_insert_iterator<vec> > >();
kpeter@720: 
kpeter@159:     vec v1;
kpeter@159:     vec v2(10);
alpar@210:     LoggerBoolMap<std::back_insert_iterator<vec> >
alpar@210:       map1(std::back_inserter(v1));
kpeter@167:     LoggerBoolMap<vec::iterator> map2(v2.begin());
kpeter@159:     map1.set(10, false);
kpeter@159:     map1.set(20, true);   map2.set(20, true);
kpeter@159:     map1.set(30, false);  map2.set(40, false);
kpeter@159:     map1.set(50, true);   map2.set(50, true);
kpeter@159:     map1.set(60, true);   map2.set(60, true);
kpeter@159:     check(v1.size() == 3 && v2.size() == 10 &&
alpar@210:           v1[0]==20 && v1[1]==50 && v1[2]==60 &&
alpar@210:           v2[0]==20 && v2[1]==50 && v2[2]==60,
kpeter@167:           "Something is wrong with LoggerBoolMap");
alpar@209: 
kpeter@159:     int i = 0;
kpeter@167:     for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
kpeter@159:           it != map2.end(); ++it )
kpeter@167:       check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
alpar@877: 
kpeter@723:     typedef ListDigraph Graph;
kpeter@723:     DIGRAPH_TYPEDEFS(Graph);
kpeter@723:     Graph gr;
kpeter@723: 
kpeter@723:     Node n0 = gr.addNode();
kpeter@723:     Node n1 = gr.addNode();
kpeter@723:     Node n2 = gr.addNode();
kpeter@723:     Node n3 = gr.addNode();
alpar@877: 
kpeter@723:     gr.addArc(n3, n0);
kpeter@723:     gr.addArc(n3, n2);
kpeter@723:     gr.addArc(n0, n2);
kpeter@723:     gr.addArc(n2, n1);
kpeter@723:     gr.addArc(n0, n1);
alpar@877: 
kpeter@723:     {
kpeter@723:       std::vector<Node> v;
kpeter@723:       dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
kpeter@723: 
kpeter@723:       check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
kpeter@723:             "Something is wrong with LoggerBoolMap");
kpeter@723:     }
kpeter@723:     {
kpeter@723:       std::vector<Node> v(countNodes(gr));
kpeter@723:       dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
alpar@877: 
kpeter@723:       check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
kpeter@723:             "Something is wrong with LoggerBoolMap");
kpeter@723:     }
kpeter@694:   }
alpar@877: 
kpeter@720:   // IdMap, RangeIdMap
kpeter@720:   {
kpeter@720:     typedef ListDigraph Graph;
kpeter@720:     DIGRAPH_TYPEDEFS(Graph);
kpeter@720: 
kpeter@720:     checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
kpeter@720:     checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
kpeter@720:     checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
kpeter@720:     checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
alpar@877: 
kpeter@720:     Graph gr;
kpeter@720:     IdMap<Graph, Node> nmap(gr);
kpeter@720:     IdMap<Graph, Arc> amap(gr);
kpeter@720:     RangeIdMap<Graph, Node> nrmap(gr);
kpeter@720:     RangeIdMap<Graph, Arc> armap(gr);
alpar@877: 
kpeter@720:     Node n0 = gr.addNode();
kpeter@720:     Node n1 = gr.addNode();
kpeter@720:     Node n2 = gr.addNode();
alpar@877: 
kpeter@720:     Arc a0 = gr.addArc(n0, n1);
kpeter@720:     Arc a1 = gr.addArc(n0, n2);
kpeter@720:     Arc a2 = gr.addArc(n2, n1);
kpeter@720:     Arc a3 = gr.addArc(n2, n0);
alpar@877: 
kpeter@720:     check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
kpeter@720:     check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
kpeter@720:     check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
kpeter@720: 
kpeter@720:     check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
kpeter@720:     check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
kpeter@720:     check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
kpeter@720:     check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
kpeter@720: 
kpeter@720:     check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
kpeter@720:     check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
alpar@877: 
kpeter@720:     check(nrmap.size() == 3 && armap.size() == 4,
kpeter@720:           "Wrong RangeIdMap::size()");
kpeter@720: 
kpeter@720:     check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
kpeter@720:     check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
kpeter@720:     check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
alpar@877: 
kpeter@720:     check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
kpeter@720:     check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
kpeter@720:     check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
kpeter@720:     check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
kpeter@720: 
kpeter@720:     check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
kpeter@720:     check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
alpar@877: 
kpeter@720:     gr.erase(n1);
alpar@877: 
kpeter@720:     if (nrmap[n0] == 1) nrmap.swap(n0, n2);
kpeter@720:     nrmap.swap(n2, n0);
kpeter@720:     if (armap[a1] == 1) armap.swap(a1, a3);
kpeter@720:     armap.swap(a3, a1);
alpar@877: 
kpeter@720:     check(nrmap.size() == 2 && armap.size() == 2,
kpeter@720:           "Wrong RangeIdMap::size()");
kpeter@720: 
kpeter@720:     check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
kpeter@720:     check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
alpar@877: 
kpeter@720:     check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
kpeter@720:     check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
kpeter@720: 
kpeter@720:     check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
kpeter@720:     check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
kpeter@720:   }
alpar@877: 
kpeter@723:   // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
kpeter@723:   {
kpeter@723:     typedef ListGraph Graph;
kpeter@723:     GRAPH_TYPEDEFS(Graph);
alpar@877: 
kpeter@723:     checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
kpeter@723:     checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
kpeter@723:     checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
kpeter@723:     checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
kpeter@723:     checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
kpeter@723:     checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
kpeter@723: 
kpeter@723:     Graph gr;
kpeter@723:     Node n0 = gr.addNode();
kpeter@723:     Node n1 = gr.addNode();
kpeter@723:     Node n2 = gr.addNode();
alpar@877: 
kpeter@723:     gr.addEdge(n0,n1);
kpeter@723:     gr.addEdge(n1,n2);
kpeter@723:     gr.addEdge(n0,n2);
kpeter@723:     gr.addEdge(n2,n1);
kpeter@723:     gr.addEdge(n1,n2);
kpeter@723:     gr.addEdge(n0,n1);
alpar@877: 
kpeter@723:     for (EdgeIt e(gr); e != INVALID; ++e) {
kpeter@723:       check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
kpeter@723:       check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
kpeter@723:     }
alpar@877: 
kpeter@789:     check(mapCompare(gr,
kpeter@789:           sourceMap(orienter(gr, constMap<Edge, bool>(true))),
kpeter@789:           targetMap(orienter(gr, constMap<Edge, bool>(false)))),
kpeter@789:           "Wrong SourceMap or TargetMap");
kpeter@723: 
kpeter@723:     typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
kpeter@723:     Digraph dgr(gr, constMap<Edge, bool>(true));
kpeter@723:     OutDegMap<Digraph> odm(dgr);
kpeter@723:     InDegMap<Digraph> idm(dgr);
alpar@877: 
kpeter@723:     check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
kpeter@723:     check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
alpar@877: 
kpeter@723:     gr.addEdge(n2, n0);
kpeter@723: 
kpeter@723:     check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
kpeter@723:     check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
kpeter@723:   }
alpar@877: 
kpeter@684:   // CrossRefMap
kpeter@684:   {
kpeter@684:     typedef ListDigraph Graph;
kpeter@684:     DIGRAPH_TYPEDEFS(Graph);
kpeter@684: 
kpeter@684:     checkConcept<ReadWriteMap<Node, int>,
kpeter@684:                  CrossRefMap<Graph, Node, int> >();
kpeter@720:     checkConcept<ReadWriteMap<Node, bool>,
kpeter@720:                  CrossRefMap<Graph, Node, bool> >();
kpeter@720:     checkConcept<ReadWriteMap<Node, double>,
kpeter@720:                  CrossRefMap<Graph, Node, double> >();
alpar@877: 
kpeter@684:     Graph gr;
kpeter@684:     typedef CrossRefMap<Graph, Node, char> CRMap;
kpeter@684:     CRMap map(gr);
alpar@877: 
kpeter@684:     Node n0 = gr.addNode();
kpeter@684:     Node n1 = gr.addNode();
kpeter@684:     Node n2 = gr.addNode();
alpar@877: 
kpeter@684:     map.set(n0, 'A');
kpeter@684:     map.set(n1, 'B');
kpeter@684:     map.set(n2, 'C');
alpar@877: 
kpeter@720:     check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
kpeter@720:           "Wrong CrossRefMap");
kpeter@720:     check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
kpeter@720:           "Wrong CrossRefMap");
kpeter@720:     check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
kpeter@720:           "Wrong CrossRefMap");
kpeter@720:     check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
kpeter@720:           "Wrong CrossRefMap::count()");
alpar@877: 
kpeter@724:     CRMap::ValueIt it = map.beginValue();
kpeter@720:     check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@720:           it == map.endValue(), "Wrong value iterator");
alpar@877: 
kpeter@684:     map.set(n2, 'A');
kpeter@720: 
kpeter@720:     check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
kpeter@720:           "Wrong CrossRefMap");
kpeter@720:     check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
kpeter@720:     check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@720:     check(map('C') == INVALID && map.inverse()['C'] == INVALID,
kpeter@720:           "Wrong CrossRefMap");
kpeter@720:     check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
kpeter@720:           "Wrong CrossRefMap::count()");
kpeter@720: 
kpeter@720:     it = map.beginValue();
kpeter@720:     check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
kpeter@720:           it == map.endValue(), "Wrong value iterator");
kpeter@720: 
kpeter@684:     map.set(n0, 'C');
kpeter@684: 
kpeter@684:     check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
kpeter@684:           "Wrong CrossRefMap");
kpeter@684:     check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
kpeter@684:     check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@684:     check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
kpeter@720:     check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
kpeter@720:           "Wrong CrossRefMap::count()");
kpeter@684: 
kpeter@720:     it = map.beginValue();
kpeter@684:     check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@684:           it == map.endValue(), "Wrong value iterator");
kpeter@159:   }
alpar@25: 
kpeter@684:   // CrossRefMap
kpeter@684:   {
alpar@695:     typedef SmartDigraph Graph;
kpeter@684:     DIGRAPH_TYPEDEFS(Graph);
kpeter@684: 
kpeter@684:     checkConcept<ReadWriteMap<Node, int>,
kpeter@684:                  CrossRefMap<Graph, Node, int> >();
alpar@877: 
kpeter@684:     Graph gr;
kpeter@684:     typedef CrossRefMap<Graph, Node, char> CRMap;
kpeter@684:     typedef CRMap::ValueIterator ValueIt;
kpeter@684:     CRMap map(gr);
alpar@877: 
kpeter@684:     Node n0 = gr.addNode();
kpeter@684:     Node n1 = gr.addNode();
kpeter@684:     Node n2 = gr.addNode();
alpar@877: 
kpeter@684:     map.set(n0, 'A');
kpeter@684:     map.set(n1, 'B');
kpeter@684:     map.set(n2, 'C');
kpeter@684:     map.set(n2, 'A');
kpeter@684:     map.set(n0, 'C');
kpeter@684: 
kpeter@684:     check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
kpeter@684:           "Wrong CrossRefMap");
kpeter@684:     check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
kpeter@684:     check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@684:     check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
kpeter@684: 
kpeter@684:     ValueIt it = map.beginValue();
kpeter@684:     check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@684:           it == map.endValue(), "Wrong value iterator");
kpeter@684:   }
alpar@877: 
deba@693:   // Iterable bool map
deba@693:   {
deba@693:     typedef SmartGraph Graph;
deba@693:     typedef SmartGraph::Node Item;
deba@693: 
deba@693:     typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
kpeter@694:     checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
deba@693: 
deba@693:     const int num = 10;
deba@693:     Graph g;
deba@693:     std::vector<Item> items;
deba@693:     for (int i = 0; i < num; ++i) {
deba@693:       items.push_back(g.addNode());
deba@693:     }
deba@693: 
deba@693:     Ibm map1(g, true);
deba@693:     int n = 0;
deba@693:     for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@693:       check(map1[static_cast<Item>(it)], "Wrong TrueIt");
deba@693:       ++n;
deba@693:     }
deba@693:     check(n == num, "Wrong number");
deba@693: 
deba@693:     n = 0;
deba@693:     for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
deba@693:         check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
deba@693:         ++n;
deba@693:     }
deba@693:     check(n == num, "Wrong number");
deba@693:     check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
deba@693:     check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
deba@693: 
deba@693:     map1[items[5]] = true;
deba@693: 
deba@693:     n = 0;
deba@693:     for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
deba@693:         check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
deba@693:         ++n;
deba@693:     }
deba@693:     check(n == num, "Wrong number");
deba@693: 
deba@693:     map1[items[num / 2]] = false;
deba@693:     check(map1[items[num / 2]] == false, "Wrong map value");
deba@693: 
deba@693:     n = 0;
deba@693:     for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@693:         check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
deba@693:         ++n;
deba@693:     }
deba@693:     check(n == num - 1, "Wrong number");
deba@693: 
deba@693:     n = 0;
deba@693:     for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
deba@693:         check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
deba@693:         ++n;
deba@693:     }
deba@693:     check(n == 1, "Wrong number");
deba@693: 
deba@693:     map1[items[0]] = false;
deba@693:     check(map1[items[0]] == false, "Wrong map value");
deba@693: 
deba@693:     map1[items[num - 1]] = false;
deba@693:     check(map1[items[num - 1]] == false, "Wrong map value");
deba@693: 
deba@693:     n = 0;
deba@693:     for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@693:         check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
deba@693:         ++n;
deba@693:     }
deba@693:     check(n == num - 3, "Wrong number");
deba@693:     check(map1.trueNum() == num - 3, "Wrong number");
deba@693: 
deba@693:     n = 0;
deba@693:     for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
deba@693:         check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
deba@693:         ++n;
deba@693:     }
deba@693:     check(n == 3, "Wrong number");
deba@693:     check(map1.falseNum() == 3, "Wrong number");
deba@693:   }
deba@693: 
deba@693:   // Iterable int map
deba@693:   {
deba@693:     typedef SmartGraph Graph;
deba@693:     typedef SmartGraph::Node Item;
deba@693:     typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
deba@693: 
kpeter@694:     checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
deba@693: 
deba@693:     const int num = 10;
deba@693:     Graph g;
deba@693:     std::vector<Item> items;
deba@693:     for (int i = 0; i < num; ++i) {
deba@693:       items.push_back(g.addNode());
deba@693:     }
deba@693: 
deba@693:     Iim map1(g);
deba@693:     check(map1.size() == 0, "Wrong size");
deba@693: 
deba@693:     for (int i = 0; i < num; ++i) {
deba@693:       map1[items[i]] = i;
deba@693:     }
deba@693:     check(map1.size() == num, "Wrong size");
deba@693: 
deba@693:     for (int i = 0; i < num; ++i) {
deba@693:       Iim::ItemIt it(map1, i);
deba@693:       check(static_cast<Item>(it) == items[i], "Wrong value");
deba@693:       ++it;
deba@693:       check(static_cast<Item>(it) == INVALID, "Wrong value");
deba@693:     }
deba@693: 
deba@693:     for (int i = 0; i < num; ++i) {
deba@693:       map1[items[i]] = i % 2;
deba@693:     }
deba@693:     check(map1.size() == 2, "Wrong size");
deba@693: 
deba@693:     int n = 0;
deba@693:     for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
kpeter@694:       check(map1[static_cast<Item>(it)] == 0, "Wrong value");
deba@693:       ++n;
deba@693:     }
deba@693:     check(n == (num + 1) / 2, "Wrong number");
deba@693: 
deba@693:     for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
kpeter@694:       check(map1[static_cast<Item>(it)] == 1, "Wrong value");
deba@693:       ++n;
deba@693:     }
deba@693:     check(n == num, "Wrong number");
deba@693: 
deba@693:   }
deba@693: 
deba@693:   // Iterable value map
deba@693:   {
deba@693:     typedef SmartGraph Graph;
deba@693:     typedef SmartGraph::Node Item;
deba@693:     typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
deba@693: 
deba@693:     checkConcept<ReadWriteMap<Item, double>, Ivm>();
deba@693: 
deba@693:     const int num = 10;
deba@693:     Graph g;
deba@693:     std::vector<Item> items;
deba@693:     for (int i = 0; i < num; ++i) {
deba@693:       items.push_back(g.addNode());
deba@693:     }
deba@693: 
deba@693:     Ivm map1(g, 0.0);
deba@693:     check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
deba@693:     check(*map1.beginValue() == 0.0, "Wrong value");
deba@693: 
deba@693:     for (int i = 0; i < num; ++i) {
deba@693:       map1.set(items[i], static_cast<double>(i));
deba@693:     }
deba@693:     check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
deba@693: 
deba@693:     for (int i = 0; i < num; ++i) {
deba@693:       Ivm::ItemIt it(map1, static_cast<double>(i));
deba@693:       check(static_cast<Item>(it) == items[i], "Wrong value");
deba@693:       ++it;
deba@693:       check(static_cast<Item>(it) == INVALID, "Wrong value");
deba@693:     }
deba@693: 
kpeter@724:     for (Ivm::ValueIt vit = map1.beginValue();
deba@693:          vit != map1.endValue(); ++vit) {
deba@693:       check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
kpeter@724:             "Wrong ValueIt");
deba@693:     }
deba@693: 
deba@693:     for (int i = 0; i < num; ++i) {
deba@693:       map1.set(items[i], static_cast<double>(i % 2));
deba@693:     }
deba@693:     check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
deba@693: 
deba@693:     int n = 0;
deba@693:     for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
kpeter@694:       check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
deba@693:       ++n;
deba@693:     }
deba@693:     check(n == (num + 1) / 2, "Wrong number");
deba@693: 
deba@693:     for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
kpeter@694:       check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
deba@693:       ++n;
deba@693:     }
deba@693:     check(n == num, "Wrong number");
deba@693: 
deba@693:   }
alpar@877: 
kpeter@789:   // Graph map utilities:
kpeter@789:   // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
kpeter@789:   // mapFind(), mapFindIf(), mapCount(), mapCountIf()
kpeter@789:   // mapCopy(), mapCompare(), mapFill()
kpeter@789:   {
kpeter@789:     DIGRAPH_TYPEDEFS(SmartDigraph);
kpeter@789: 
kpeter@789:     SmartDigraph g;
kpeter@789:     Node n1 = g.addNode();
kpeter@789:     Node n2 = g.addNode();
kpeter@789:     Node n3 = g.addNode();
alpar@877: 
kpeter@789:     SmartDigraph::NodeMap<int> map1(g);
kpeter@789:     SmartDigraph::ArcMap<char> map2(g);
kpeter@789:     ConstMap<Node, A> cmap1 = A();
kpeter@789:     ConstMap<Arc, C> cmap2 = C(0);
alpar@877: 
kpeter@789:     map1[n1] = 10;
kpeter@789:     map1[n2] = 5;
kpeter@789:     map1[n3] = 12;
alpar@877: 
kpeter@789:     // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
kpeter@789:     check(mapMin(g, map1) == n2, "Wrong mapMin()");
kpeter@789:     check(mapMax(g, map1) == n3, "Wrong mapMax()");
kpeter@789:     check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()");
kpeter@789:     check(mapMax(g, map1, std::greater<int>()) == n2, "Wrong mapMax()");
kpeter@789:     check(mapMinValue(g, map1) == 5, "Wrong mapMinValue()");
kpeter@789:     check(mapMaxValue(g, map1) == 12, "Wrong mapMaxValue()");
kpeter@789: 
kpeter@789:     check(mapMin(g, map2) == INVALID, "Wrong mapMin()");
kpeter@789:     check(mapMax(g, map2) == INVALID, "Wrong mapMax()");
kpeter@789: 
kpeter@789:     check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
kpeter@789:     check(mapMax(g, cmap2) == INVALID, "Wrong mapMax()");
kpeter@789: 
kpeter@789:     Arc a1 = g.addArc(n1, n2);
kpeter@789:     Arc a2 = g.addArc(n1, n3);
kpeter@789:     Arc a3 = g.addArc(n2, n3);
kpeter@789:     Arc a4 = g.addArc(n3, n1);
alpar@877: 
kpeter@789:     map2[a1] = 'b';
kpeter@789:     map2[a2] = 'a';
kpeter@789:     map2[a3] = 'b';
kpeter@789:     map2[a4] = 'c';
kpeter@789: 
kpeter@789:     // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
kpeter@789:     check(mapMin(g, map2) == a2, "Wrong mapMin()");
kpeter@789:     check(mapMax(g, map2) == a4, "Wrong mapMax()");
kpeter@789:     check(mapMin(g, map2, std::greater<int>()) == a4, "Wrong mapMin()");
kpeter@789:     check(mapMax(g, map2, std::greater<int>()) == a2, "Wrong mapMax()");
kpeter@789:     check(mapMinValue(g, map2, std::greater<int>()) == 'c',
kpeter@789:           "Wrong mapMinValue()");
kpeter@789:     check(mapMaxValue(g, map2, std::greater<int>()) == 'a',
kpeter@789:           "Wrong mapMaxValue()");
kpeter@789: 
kpeter@789:     check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
kpeter@789:     check(mapMax(g, cmap2) != INVALID, "Wrong mapMax()");
kpeter@789:     check(mapMaxValue(g, cmap2) == C(0), "Wrong mapMaxValue()");
kpeter@789: 
kpeter@789:     check(mapMin(g, composeMap(functorToMap(&createC), map2)) == a2,
kpeter@789:           "Wrong mapMin()");
kpeter@789:     check(mapMax(g, composeMap(functorToMap(&createC), map2)) == a4,
kpeter@789:           "Wrong mapMax()");
kpeter@789:     check(mapMinValue(g, composeMap(functorToMap(&createC), map2)) == C('a'),
kpeter@789:           "Wrong mapMinValue()");
kpeter@789:     check(mapMaxValue(g, composeMap(functorToMap(&createC), map2)) == C('c'),
kpeter@789:           "Wrong mapMaxValue()");
kpeter@789: 
kpeter@789:     // mapFind(), mapFindIf()
kpeter@789:     check(mapFind(g, map1, 5) == n2, "Wrong mapFind()");
kpeter@789:     check(mapFind(g, map1, 6) == INVALID, "Wrong mapFind()");
kpeter@789:     check(mapFind(g, map2, 'a') == a2, "Wrong mapFind()");
kpeter@789:     check(mapFind(g, map2, 'e') == INVALID, "Wrong mapFind()");
kpeter@789:     check(mapFind(g, cmap2, C(0)) == ArcIt(g), "Wrong mapFind()");
kpeter@789:     check(mapFind(g, cmap2, C(1)) == INVALID, "Wrong mapFind()");
kpeter@789: 
kpeter@789:     check(mapFindIf(g, map1, Less<int>(7)) == n2,
kpeter@789:           "Wrong mapFindIf()");
kpeter@789:     check(mapFindIf(g, map1, Less<int>(5)) == INVALID,
kpeter@789:           "Wrong mapFindIf()");
kpeter@789:     check(mapFindIf(g, map2, Less<char>('d')) == ArcIt(g),
kpeter@789:           "Wrong mapFindIf()");
kpeter@789:     check(mapFindIf(g, map2, Less<char>('a')) == INVALID,
kpeter@789:           "Wrong mapFindIf()");
kpeter@789: 
kpeter@789:     // mapCount(), mapCountIf()
kpeter@789:     check(mapCount(g, map1, 5) == 1, "Wrong mapCount()");
kpeter@789:     check(mapCount(g, map1, 6) == 0, "Wrong mapCount()");
kpeter@789:     check(mapCount(g, map2, 'a') == 1, "Wrong mapCount()");
kpeter@789:     check(mapCount(g, map2, 'b') == 2, "Wrong mapCount()");
kpeter@789:     check(mapCount(g, map2, 'e') == 0, "Wrong mapCount()");
kpeter@789:     check(mapCount(g, cmap2, C(0)) == 4, "Wrong mapCount()");
kpeter@789:     check(mapCount(g, cmap2, C(1)) == 0, "Wrong mapCount()");
kpeter@789: 
kpeter@789:     check(mapCountIf(g, map1, Less<int>(11)) == 2,
kpeter@789:           "Wrong mapCountIf()");
kpeter@789:     check(mapCountIf(g, map1, Less<int>(13)) == 3,
kpeter@789:           "Wrong mapCountIf()");
kpeter@789:     check(mapCountIf(g, map1, Less<int>(5)) == 0,
kpeter@789:           "Wrong mapCountIf()");
kpeter@789:     check(mapCountIf(g, map2, Less<char>('d')) == 4,
kpeter@789:           "Wrong mapCountIf()");
kpeter@789:     check(mapCountIf(g, map2, Less<char>('c')) == 3,
kpeter@789:           "Wrong mapCountIf()");
kpeter@789:     check(mapCountIf(g, map2, Less<char>('a')) == 0,
kpeter@789:           "Wrong mapCountIf()");
alpar@877: 
kpeter@789:     // MapIt, ConstMapIt
kpeter@789: /*
kpeter@789: These tests can be used after applying bugfix #330
kpeter@789:     typedef SmartDigraph::NodeMap<int>::MapIt MapIt;
kpeter@789:     typedef SmartDigraph::NodeMap<int>::ConstMapIt ConstMapIt;
kpeter@789:     check(*std::min_element(MapIt(map1), MapIt(INVALID)) == 5,
kpeter@789:           "Wrong NodeMap<>::MapIt");
kpeter@789:     check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12,
kpeter@789:           "Wrong NodeMap<>::MapIt");
alpar@877: 
kpeter@789:     int sum = 0;
kpeter@789:     std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum));
kpeter@789:     check(sum == 27, "Wrong NodeMap<>::MapIt");
kpeter@789:     std::for_each(ConstMapIt(map1), ConstMapIt(INVALID), Sum<int>(sum));
kpeter@789:     check(sum == 54, "Wrong NodeMap<>::ConstMapIt");
kpeter@789: */
kpeter@789: 
kpeter@789:     // mapCopy(), mapCompare(), mapFill()
kpeter@789:     check(mapCompare(g, map1, map1), "Wrong mapCompare()");
kpeter@789:     check(mapCompare(g, cmap2, cmap2), "Wrong mapCompare()");
kpeter@789:     check(mapCompare(g, map1, shiftMap(map1, 0)), "Wrong mapCompare()");
kpeter@789:     check(mapCompare(g, map2, scaleMap(map2, 1)), "Wrong mapCompare()");
kpeter@789:     check(!mapCompare(g, map1, shiftMap(map1, 1)), "Wrong mapCompare()");
kpeter@789: 
kpeter@789:     SmartDigraph::NodeMap<int> map3(g, 0);
kpeter@789:     SmartDigraph::ArcMap<char> map4(g, 'a');
alpar@877: 
kpeter@789:     check(!mapCompare(g, map1, map3), "Wrong mapCompare()");
alpar@877:     check(!mapCompare(g, map2, map4), "Wrong mapCompare()");
alpar@877: 
kpeter@789:     mapCopy(g, map1, map3);
kpeter@789:     mapCopy(g, map2, map4);
kpeter@789: 
kpeter@789:     check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()");
alpar@877:     check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()");
alpar@877: 
kpeter@789:     Undirector<SmartDigraph> ug(g);
kpeter@789:     Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x');
kpeter@789:     Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14);
alpar@877: 
kpeter@789:     check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
kpeter@789:     check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
kpeter@789:     check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
kpeter@789:     check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
alpar@877: 
kpeter@789:     mapCopy(g, map2, umap1);
kpeter@789: 
kpeter@789:     check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
kpeter@789:     check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
kpeter@789:     check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
kpeter@789:     check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
alpar@877: 
kpeter@789:     mapCopy(g, map2, umap1);
kpeter@789:     mapCopy(g, umap1, map2);
kpeter@789:     mapCopy(ug, map2, umap1);
kpeter@789:     mapCopy(ug, umap1, map2);
alpar@877: 
kpeter@789:     check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
kpeter@789:     mapCopy(ug, umap1, umap2);
kpeter@789:     check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
alpar@877: 
kpeter@789:     check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()");
kpeter@789:     mapFill(g, map1, 2);
kpeter@789:     check(mapCompare(g, constMap<Node>(2), map1), "Wrong mapFill()");
kpeter@789: 
kpeter@789:     check(!mapCompare(g, map2, constMap<Arc>('z')), "Wrong mapCompare()");
kpeter@789:     mapCopy(g, constMap<Arc>('z'), map2);
kpeter@789:     check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()");
kpeter@789:   }
alpar@877: 
alpar@25:   return 0;
alpar@25: }