37 #include "DGtal/base/Common.h"
38 #include "DGtal/base/LabelledMap.h"
40 using namespace DGtal;
43 template <
typename Container1,
typename Container2>
45 isEqual( Container1 & c1, Container2 & c2 )
47 return ( c1.size() == c2.size() )
48 && std::equal( c1.begin(), c1.end(), c2.begin() );
51 template <
typename VContainer1,
typename LContainer2>
52 void insert( VContainer1 & c1, LContainer2 & c2,
unsigned int idx,
double v )
54 c1.insert( std::make_pair(idx, v) );
55 c2.insert( std::make_pair(idx, v) );
58 template <
typename VContainer1,
typename LContainer2>
60 checkInsert( VContainer1 & v, LContainer2 & l,
63 for (
unsigned int i = 0; i < nb; ++i )
65 unsigned int idx = random() % ( l.max_size() );
66 double val = ( (double)random() ) / RAND_MAX;
67 insert( v, l, idx, val );
69 return isEqual( v, l );
72 template <
typename VContainer1,
typename LContainer2>
73 void erase( VContainer1 & c1, LContainer2 & c2,
unsigned int idx )
79 template <
typename VContainer1,
typename LContainer2>
81 checkErase( VContainer1 & v, LContainer2 & l,
84 for (
unsigned int i = 0; i < nb; ++i )
86 unsigned int idx = random() % ( l.max_size() );
90 return isEqual( v, l );
93 template <
typename AContainer>
94 void display( ostream & out,
const AContainer & C )
97 for (
typename AContainer::const_iterator it = C.begin(), it_end = C.end();
100 out <<
" (" << (*it).first <<
"," << (*it).second <<
")";
107 BOOST_CONCEPT_ASSERT(( boost::AssociativeContainer< MyLabelledMap > ));
108 BOOST_CONCEPT_ASSERT(( boost::PairAssociativeContainer< MyLabelledMap > ));
109 BOOST_CONCEPT_ASSERT(( boost::UniqueAssociativeContainer< MyLabelledMap > ));
113 unsigned int nbok = 0;
116 map<unsigned int, double> v;
117 ++nb, nbok += isEqual( v, l ) ? 1 : 0;
118 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
119 insert( v, l, 3, 4.5 );
120 ++nb, nbok += isEqual( v, l ) ? 1 : 0;
121 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
122 insert( v, l, 0, 10.1 );
123 ++nb, nbok += isEqual( v, l ) ? 1 : 0;
124 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
125 insert( v, l, 1, 3.7 );
126 ++nb, nbok += isEqual( v, l ) ? 1 : 0;
127 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
128 insert( v, l, 2, 8.4 );
129 insert( v, l, 1, 2.1 );
130 ++nb, nbok += isEqual( v, l ) ? 1 : 0;
131 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
132 display( std::cout, v );
133 insert( v, l, 1, -3.0 );
134 ++nb, nbok += isEqual( v, l ) ? 1 : 0;
135 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
136 insert( v, l, 15, -13.1 );
137 ++nb, nbok += isEqual( v, l ) ? 1 : 0;
138 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
139 insert( v, l, 2, -7.1 );
140 ++nb, nbok += isEqual( v, l ) ? 1 : 0;
141 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
147 ++nb, nbok += checkInsert( v, l, 1000 ) ? 1 : 0;
148 std::cout <<
"(" << nbok <<
"/" << nb <<
") 1000 insertions l=" << l << std::endl;
149 ++nb, nbok += checkErase( v, l, 1000 ) ? 1 : 0;
150 std::cout <<
"(" << nbok <<
"/" << nb <<
") 1000 deletions l=" << l << std::endl;
153 ++nb, nbok += checkInsert( v, l, 10 ) ? 1 : 0;
154 std::cout <<
"(" << nbok <<
"/" << nb <<
") 10 deletions l=" << l << std::endl;
155 std::pair< MyLabelledMap::Iterator,
156 MyLabelledMap::Iterator > pair1 = l.equal_range( 7 );
157 std::cout <<
"Range(7)=[" << (*pair1.first).first <<
"," << (*pair1.second).first <<
")" << std::endl;
158 ++nb, nbok += ( pair1.first == l.lower_bound( 7 ) ) ? 1 : 0;
159 ++nb, nbok += ( pair1.second == l.upper_bound( 7 ) ) ? 1 : 0;
160 std::cout <<
"(" << nbok <<
"/" << nb <<
") equal_range, lower_bound." << std::endl;
164 return ( nb == nbok ) ? 0 : 1;