DGtal 1.3.0
Loading...
Searching...
No Matches
testModuloComputer.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/arithmetic/ModuloComputer.h"
34#include "DGtal/kernel/NumberTraits.h"
35
37
38using namespace std;
39using namespace DGtal;
40
42// Functions for testing class ModuloComputer.
44
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;
81
82 return nbok == nb;
83}
84
86// Standard services - public :
87
88int 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;
99 return res ? 0 : 1;
100}
101// //
implements basic functions on modular arithmetic.
void increment(UnsignedInteger &i) const
UnsignedInteger cast(IntegerParamType i) const
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:564
int main()
Definition: testBits.cpp:56
bool testModuloComputer()