DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testArithmeticalDSLKernel.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/geometry/curves/ArithmeticalDSLKernel.h"

Go to the source code of this file.

Functions

template<typename Coordinate , typename Integer , unsigned short adj>
bool test (const Integer &a, const Integer &b)
 
template<typename Coordinate , typename Integer , unsigned short adj>
bool specialCases (const Integer &a, const Integer &b)
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2013/07/03

Functions for testing class ArithmeticalDSLKernel.

This file is part of the DGtal library.

Definition in file testArithmeticalDSLKernel.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 166 of file testArithmeticalDSLKernel.cpp.

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
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}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

◆ specialCases()

template<typename Coordinate , typename Integer , unsigned short adj>
bool specialCases ( const Integer a,
const Integer b 
)

Test for the special cases

Parameters
aa-parameter
bb-parameter
Template Parameters
Coordinatemodel of integer for the vector components
Integermodel of integer for the a- and b-parameter
adjinteger equal to 4 or 8 for the adjacency type

Definition at line 94 of file testArithmeticalDSLKernel.cpp.

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}
static Vector shift(const TInteger &a, const TInteger &b)
std::pair< Vector, Vector > Steps
static Steps steps(const TInteger &a, const TInteger &b)
FreemanChain< int >::Vector Vector

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::ArithmeticalDSLKernel< TCoordinate, adjacency >::shift(), DGtal::ArithmeticalDSLKernel< TCoordinate, adjacency >::steps(), and DGtal::trace.

◆ test()

template<typename Coordinate , typename Integer , unsigned short adj>
bool test ( const Integer a,
const Integer b 
)

General test.

Parameters
aa-parameter
bb-parameter
Template Parameters
Coordinatemodel of integer for the vector components
Integermodel of integer for the a- and b-parameter
adjinteger equal to 4 or 8 for the adjacency type

Definition at line 54 of file testArithmeticalDSLKernel.cpp.

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}

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::ArithmeticalDSLKernel< TCoordinate, adjacency >::shift(), DGtal::ArithmeticalDSLKernel< TCoordinate, adjacency >::steps(), and DGtal::trace.