DGtal 1.4.0
Loading...
Searching...
No Matches
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
37using namespace std;
38using namespace DGtal;
39
41// Functions for testing class ArithmeticalDSLKernel.
43
53template <typename Coordinate, typename Integer, unsigned short adj>
54bool 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;
79
80 return nbok == nb;
81}
82
93template <typename Coordinate, typename Integer, unsigned short adj>
94bool 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
166int 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 -------------------------
175 //8-adjacency
184 ;
185
186 //4-adjacency
187 res = res
196 ;
197
198 //-------------- special tests --------------------------
199 //8-adjacency
200 res = res
210 ;
211
212 //4-adjacency
213 res = res
223 ;
224
225
226
227
228
229#ifdef WITH_BIGINTEGER
230 res = res
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
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
static Vector shift(const TInteger &a, const TInteger &b)
std::pair< Vector, Vector > Steps
static Steps steps(const TInteger &a, const TInteger &b)
bool specialCases(const Integer &a, const Integer &b)
bool test(const Integer &a, const Integer &b)
int main()
Definition testBits.cpp:56