DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testModuloComputer.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
#include "DGtal/arithmetic/ModuloComputer.h"
34
#include "DGtal/kernel/NumberTraits.h"
35
37
38
using namespace
std
;
39
using namespace
DGtal
;
40
42
// Functions for testing class ModuloComputer.
44
48
bool
testModuloComputer
()
49
{
50
unsigned
int
nbok = 0;
51
unsigned
int
nb = 0;
52
53
trace
.
beginBlock
(
"Testing block ..."
);
54
55
//Construct an arithmetic modulo 15
56
57
58
ModuloComputer< int >
modular(15);
59
typedef
NumberTraits< int >::UnsignedVersion
myUnsignedInteger;
60
myUnsignedInteger a;
61
62
a = modular.
cast
( 2 );
//a contains the value 2
63
nbok += (a == 2) ? 1 : 0;
64
nb++;
65
trace
.
info
() <<
"a= "
<<a<<std::endl;
66
67
a = modular.
cast
( -1 );
//a contains the value 14
68
nbok += (a== 14) ? 1 : 0;
69
nb++;
70
trace
.
info
() <<
"a= "
<<a<<std::endl;
71
72
modular.
increment
( a );
//a contains the value 0
73
nbok += (a== 0) ? 1 : 0;
74
nb++;
75
trace
.
info
() <<
"a= "
<<a<<std::endl;
76
77
nbok += 1;
78
nb++;
79
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
<< std::endl;
80
trace
.
endBlock
();
81
82
return
nbok == nb;
83
}
84
86
// Standard services - public :
87
88
int
main
(
int
argc,
char
** argv )
89
{
90
trace
.
beginBlock
(
"Testing class ModuloComputer"
);
91
trace
.
info
() <<
"Args:"
;
92
for
(
int
i = 0; i < argc; ++i )
93
trace
.
info
() <<
" "
<< argv[ i ];
94
trace
.
info
() << endl;
95
96
bool
res =
testModuloComputer
();
// && ... other tests
97
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
98
trace
.
endBlock
();
99
return
res ? 0 : 1;
100
}
101
// //
DGtal::ModuloComputer
implements basic functions on modular arithmetic.
Definition
ModuloComputer.h:80
DGtal::ModuloComputer::increment
void increment(UnsignedInteger &i) const
DGtal::ModuloComputer::cast
UnsignedInteger cast(IntegerParamType i) const
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()
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::NumberTraits
Aim: The traits class for all models of Cinteger.
Definition
NumberTraits.h:562
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testModuloComputer
bool testModuloComputer()
Definition
testModuloComputer.cpp:48
tests
arithmetic
testModuloComputer.cpp
Generated on
for DGtal by
1.18.0