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>
63 for (
unsigned int i = 0; i < nb; ++i )
65 unsigned int idx = rand() % ( l.max_size() );
66 double val = ( (double)rand() ) / RAND_MAX;
72 template <
typename VContainer1,
typename LContainer2>
73 void erase( VContainer1 & c1, LContainer2 & c2,
unsigned int idx )
79 template <
typename VContainer1,
typename LContainer2>
84 for (
unsigned int i = 0; i < nb; ++i )
86 unsigned int idx = rand() % ( l.max_size() );
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 <<
")";
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;
120 ++nb; nbok +=
isEqual( v, l ) ? 1 : 0;
121 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
123 ++nb; nbok +=
isEqual( v, l ) ? 1 : 0;
124 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
126 ++nb; nbok +=
isEqual( v, l ) ? 1 : 0;
127 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
130 ++nb; nbok +=
isEqual( v, l ) ? 1 : 0;
131 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
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;
140 ++nb; nbok +=
isEqual( v, l ) ? 1 : 0;
141 std::cout <<
"(" << nbok <<
"/" << nb <<
") l=" << l << std::endl;
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;
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;
166 trace.
beginBlock (
"Testing LabelledMap copy constructor and copy operator" );
167 MyOtherLabelledMap ll;
169 for (
unsigned int size = 0; size <= 2 + 3 + 2; ++size )
171 for (
unsigned int i = 0; i < size; ++i)
174 MyOtherLabelledMap ll_ccopy(ll);
175 MyOtherLabelledMap ll_ocopy; ll_ocopy = ll;
177 for (
unsigned int i = 0; i < size; ++i)
180 bool csuccess =
true;
181 bool osuccess =
true;
182 for (
unsigned int i = 0; i < size; ++i)
184 csuccess &= ll_ccopy[i] == i;
185 osuccess &= ll_ocopy[i] == i;
188 ++nb; nbok += csuccess ? 1 : 0;
189 std::cout <<
"(" << nbok <<
"/" << nb <<
") ll_copy_constructed=" << ll_ccopy << std::endl;
191 ++nb; nbok += osuccess ? 1 : 0;
192 std::cout <<
"(" << nbok <<
"/" << nb <<
") ll_copied=" << ll_ocopy << std::endl;
197 return ( nb == nbok ) ? 0 : 1;
Aim: Represents a map label -> data, where the label is an integer between 0 and a constant L-1....
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
Go to http://www.sgi.com/tech/stl/AssociativeContainer.html.
Go to http://www.sgi.com/tech/stl/PairAssociativeContainer.html.
Go to http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html.
void erase(VContainer1 &c1, LContainer2 &c2, unsigned int idx)
bool isEqual(Container1 &c1, Container2 &c2)
bool checkInsert(VContainer1 &v, LContainer2 &l, unsigned int nb)
void insert(VContainer1 &c1, LContainer2 &c2, unsigned int idx, double v)
void display(ostream &out, const AContainer &C)
bool checkErase(VContainer1 &v, LContainer2 &l, unsigned int nb)