32 #include "DGtal/base/Common.h"
34 #include "DGtal/kernel/SpaceND.h"
35 #include "DGtal/kernel/domains/HyperRectDomain.h"
36 #include "DGtal/images/ImageContainerByHashTree.h"
40 #define dim ImageContainerByHashTree<Domain , T, DGtal::uint64_t >::dim
41 #define defHashKey typename ImageContainerByHashTree<Domain , int, DGtal::uint64_t >::HashKey
43 using namespace DGtal;
45 int iRand (
int iMin,
int iMax )
47 double f = ( double ) rand() / RAND_MAX;
48 return (
int) (iMin +
static_cast<double> ( f * ( iMax - iMin ) ));
51 template<
typename Domain,
typename T >
54 srand ( (
unsigned int)time ( NULL ) );
57 cerr <<
"Test: set" <<endl;
58 cerr <<
"phase 1..." <<endl;
60 unsigned DepthMask = 100000;
62 for (
int key = DepthMask; key > 1; --key )
69 container.
setValue ( key, iRand ( 0, 100 ) );
70 if ( checkAfterEachSet )
74 cerr <<
"test_set: failure in phase 1" << endl
82 cerr <<
"checking the container's validity..." << endl;
86 cerr <<
"test_set: failure in phase 1" << endl;
91 cerr <<
"phase 2..." <<endl;
92 for (
unsigned key = container.
ROOT_KEY; key < DepthMask; ++key )
98 container.
setValue ( key, iRand ( 0, 100 ) );
99 if ( checkAfterEachSet )
102 cerr <<
"test_set: failure in phase 2" << endl
110 cerr <<
"test_set: failure in phase 2" << endl;
114 cerr <<
"test_set: success !" << endl;
119 template<
typename Domain,
typename T >
122 srand ( (
unsigned int)time ( NULL ) );
125 unsigned DepthMask = 100000;
127 for (
unsigned key = DepthMask; key > container.
ROOT_KEY; --key )
135 T val = iRand ( 0, 100 );
145 if ( val != container.
get ( key2 ) )
147 cerr <<
"test_get: failure" << endl
155 cerr <<
"test_get: success !" << endl
156 <<
"tested with " << count <<
" keys" << endl;
162 int main (
int argc,
char** argv )
166 for (
int i = 0; i < argc; ++i )
171 typedef Space::Point
Point;
174 Tree tree ( 12,5,1 );
179 Dom::Point p1, p2, p3;
180 cerr <<
"azertyuiop" << endl;
198 cerr <<
"azertyuiop" << endl;
200 cerr <<
"azertyuiop" << endl;
201 cerr <<
"coord get " << tree2.get ( p1 ) << endl;
202 cerr <<
"_-_-_-_-_-_-_-_-_-_-_-_-" << endl;
203 cerr <<
"coord get " << tree2.get ( p3 ) << endl;
204 cerr <<
"coord get " << tree2.get ( p1+=p3 ) << endl;
205 cerr <<
"coord get " << tree2.get ( p1+=p3 ) << endl;
206 cerr <<
"coord get " << tree2.get ( p1+=p3 ) << endl;
207 cerr <<
"coord get " << tree2.get ( p1+=p3 ) << endl;
211 HashTreeIterator it = tree.begin();
212 for ( it = tree.begin(); it != tree.end(); ++it )
219 test_setVal ( tree,
false ) &&
220 test_get ( tree,
false )
225 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;