DGtal
0.6.devel
Main Page
Related Pages
Modules
Namespaces
Data Structures
Examples
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
tests
arithmetic
testModuloComputer.cpp
1
30
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 +=
true
? 1 : 0;
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
// //
Generated on Wed Dec 19 2012 19:10:41 for DGtal by
1.8.1.1