DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testArithmeticalDSLKernel.cpp
Go to the documentation of this file.
1
16
29
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
61
typename
ArithmeticalDSLKernel<Coordinate, adj>::Steps
steps =
62
ArithmeticalDSLKernel<Coordinate, adj>::steps
(a, b);
63
64
trace
.
info
() <<
" step1: "
<< steps.first << std::endl;
65
trace
.
info
() <<
" step2: "
<< steps.second << std::endl;
66
67
typename
ArithmeticalDSLKernel<Coordinate, adj>::Vector
shift =
68
ArithmeticalDSLKernel<Coordinate, adj>::shift
(a, b);
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
103
typename
ArithmeticalDSLKernel<Coordinate, adj>::Steps
steps =
104
ArithmeticalDSLKernel<Coordinate, adj>::steps
(a, b);
105
106
trace
.
info
() <<
" step1: "
<< steps.first << std::endl;
107
trace
.
info
() <<
" step2: "
<< steps.second << std::endl;
108
109
typedef
typename
ArithmeticalDSLKernel<Coordinate, adj>::Vector
Vector
;
110
Vector
shift =
111
ArithmeticalDSLKernel<Coordinate, adj>::shift
(a, b);
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 -------------------------
175
//8-adjacency
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
186
//4-adjacency
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 --------------------------
199
//8-adjacency
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
212
//4-adjacency
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
res = res
226
&&
test<DGtal::BigInteger, DGtal::BigInteger, 8>
(8,5)
227
&&
test<DGtal::BigInteger, DGtal::BigInteger, 4>
(8,5)
228
;
229
230
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
231
trace
.
endBlock
();
232
return
res ? 0 : 1;
233
}
234
// //
DGtal::Vector
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
Integer
Point::Coordinate Integer
Definition
examplePlaneProbingParallelepipedEstimator.cpp:44
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::ArithmeticalDSLKernel::shift
static Vector shift(const TInteger &a, const TInteger &b)
DGtal::ArithmeticalDSLKernel::Vector
Space::Vector Vector
Definition
ArithmeticalDSLKernel.h:103
DGtal::ArithmeticalDSLKernel::Steps
std::pair< Vector, Vector > Steps
Definition
ArithmeticalDSLKernel.h:107
DGtal::ArithmeticalDSLKernel::steps
static Steps steps(const TInteger &a, const TInteger &b)
specialCases
bool specialCases(const Integer &a, const Integer &b)
Definition
testArithmeticalDSLKernel.cpp:94
test
bool test(const Integer &a, const Integer &b)
Definition
testArithmeticalDSLKernel.cpp:54
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
test
bool test(const I &itb, const I &ite)
Definition
testMostCenteredMSEstimator.cpp:71
tests
geometry
curves
testArithmeticalDSLKernel.cpp
Generated on
for DGtal by
1.18.0