DGtal  1.4.beta
testArithmeticalDSLKernel.cpp
Go to the documentation of this file.
1
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33
34 #include "DGtal/geometry/curves/ArithmeticalDSLKernel.h"
36
37 using namespace std;
38 using namespace DGtal;
39
41 // Functions for testing class ArithmeticalDSLKernel.
43
53 template <typename Coordinate, typename Integer, unsigned short adj>
54 bool test(const Integer& a, const Integer& b)
55 {
56  unsigned int nbok = 0;
57  unsigned int nb = 0;
58
59  trace.beginBlock ( "testing general cases..." );
60
63
64  trace.info() << " step1: " << steps.first << std::endl;
65  trace.info() << " step2: " << steps.second << std::endl;
66
69
70  trace.info() << " shift: " << shift << std::endl;
71
72  if ( (steps.first - steps.second) == shift )
73  nbok++;
74  nb++;
75
76  trace.info() << "(" << nbok << "/" << nb << ") "
77  << std::endl;
78  trace.endBlock();
79
80  return nbok == nb;
81 }
82
93 template <typename Coordinate, typename Integer, unsigned short adj>
94 bool specialCases(const Integer& a, const Integer& b)
95 {
96  unsigned int nbok = 0;
97  unsigned int nb = 0;
98
99  trace.beginBlock ( "testing special cases..." );
100
101  trace.info() << " a " << a << " b " << b << std::endl;
102
105
106  trace.info() << " step1: " << steps.first << std::endl;
107  trace.info() << " step2: " << steps.second << std::endl;
108
110  Vector shift =
112
113  trace.info() << " shift: " << shift << std::endl;
114
115  if ( (a == 0) && (b == 0) )
116  {
117  if ( (steps.first == Vector(0,0))
118  && (steps.second == Vector(0,0))
119  && (shift == Vector(0,0)))
120  nbok++;
121  nb++;
122  }
123  else
124  {
125  if ( (a == 0)||(b == 0) )
126  {
127  if ( (steps.first != Vector(0,0))
128  && (steps.second == Vector(0,0))
129  && (shift != Vector(0,0)))
130  nbok++;
131  nb++;
132  }
133  else
134  {
135  if ( (adj == 8)
136  &&( (a == b)||(a == -b) ) )
137  {
138  if ( (steps.first != Vector(0,0))
139  && (steps.second == Vector(0,0))
140  && (shift != Vector(0,0)) )
141  nbok++;
142  nb++;
143  }
144  else
145  {
146  if ( (steps.first != Vector(0,0))
147  && (steps.second != Vector(0,0))
148  && (shift != Vector(0,0)) )
149  nbok++;
150  nb++;
151  }
152  }
153  }
154  trace.info() << "(" << nbok << "/" << nb << ") "
155  << std::endl;
156  trace.endBlock();
157
158  return nbok == nb;
159
160 }
161
162
164 // Standard services - public :
165
166 int main( int argc, char** argv )
167 {
168  trace.beginBlock ( "Testing class ArithmeticalDSLKernel" );
169  trace.info() << "Args:";
170  for ( int i = 0; i < argc; ++i )
171  trace.info() << " " << argv[ i ];
172  trace.info() << endl;
173
174  //-------------- general tests -------------------------
176  bool res = test<DGtal::int32_t, DGtal::int32_t, 8>(8,5)
177  && test<DGtal::int32_t, DGtal::int32_t, 8>(5,8)
178  && test<DGtal::int32_t, DGtal::int32_t, 8>(-5,8)
179  && test<DGtal::int32_t, DGtal::int32_t, 8>(-8,5)
180  && test<DGtal::int32_t, DGtal::int32_t, 8>(-8,-5)
181  && test<DGtal::int32_t, DGtal::int32_t, 8>(-5,-8)
182  && test<DGtal::int32_t, DGtal::int32_t, 8>(5,-8)
183  && test<DGtal::int32_t, DGtal::int32_t, 8>(8,-5)
184  ;
185
187  res = res
188  && test<DGtal::int32_t, DGtal::int32_t, 4>(8,5)
189  && test<DGtal::int32_t, DGtal::int32_t, 4>(5,8)
190  && test<DGtal::int32_t, DGtal::int32_t, 4>(-5,8)
191  && test<DGtal::int32_t, DGtal::int32_t, 4>(-8,5)
192  && test<DGtal::int32_t, DGtal::int32_t, 4>(-8,-5)
193  && test<DGtal::int32_t, DGtal::int32_t, 4>(-5,-8)
194  && test<DGtal::int32_t, DGtal::int32_t, 4>(5,-8)
195  && test<DGtal::int32_t, DGtal::int32_t, 4>(8,-5)
196  ;
197
198  //-------------- special tests --------------------------
200  res = res
201  && specialCases<DGtal::int32_t, DGtal::int32_t, 8>(0,0)
202  && specialCases<DGtal::int32_t, DGtal::int32_t, 8>(0,5)
203  && specialCases<DGtal::int32_t, DGtal::int32_t, 8>(0,-5)
204  && specialCases<DGtal::int32_t, DGtal::int32_t, 8>(5,0)
205  && specialCases<DGtal::int32_t, DGtal::int32_t, 8>(-5,0)
206  && specialCases<DGtal::int32_t, DGtal::int32_t, 8>(1,1)
207  && specialCases<DGtal::int32_t, DGtal::int32_t, 8>(1,-1)
208  && specialCases<DGtal::int32_t, DGtal::int32_t, 8>(-1,1)
209  && specialCases<DGtal::int32_t, DGtal::int32_t, 8>(-1,-1)
210  ;
211
213  res = res
214  && specialCases<DGtal::int32_t, DGtal::int32_t, 4>(0,0)
215  && specialCases<DGtal::int32_t, DGtal::int32_t, 4>(0,5)
216  && specialCases<DGtal::int32_t, DGtal::int32_t, 4>(0,-5)
217  && specialCases<DGtal::int32_t, DGtal::int32_t, 4>(5,0)
218  && specialCases<DGtal::int32_t, DGtal::int32_t, 4>(-5,0)
219  && specialCases<DGtal::int32_t, DGtal::int32_t, 4>(1,1)
220  && specialCases<DGtal::int32_t, DGtal::int32_t, 4>(1,-1)
221  && specialCases<DGtal::int32_t, DGtal::int32_t, 4>(-1,1)
222  && specialCases<DGtal::int32_t, DGtal::int32_t, 4>(-1,-1)
223  ;
224
225
226
227
228
229 #ifdef WITH_BIGINTEGER
230  res = res
231  && test<DGtal::BigInteger, DGtal::BigInteger, 8>(8,5)
232  && test<DGtal::BigInteger, DGtal::BigInteger, 4>(8,5)
233  ;
234 #endif
235
236  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
237  trace.endBlock();
238  return res ? 0 : 1;
239 }
240 // //
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DigitalPlane::Point Vector
Point::Coordinate Integer
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: Small class that contains the code that depends on the arithmetical thickness (either naive or s...
std::pair< Vector, Vector > Steps
int main(int argc, char **argv)
bool specialCases(const Integer &a, const Integer &b)
bool test(const Integer &a, const Integer &b)