DGtal  1.4.beta
testModuloComputer.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/arithmetic/ModuloComputer.h"
#include "DGtal/kernel/NumberTraits.h"
Include dependency graph for testModuloComputer.cpp:

Go to the source code of this file.

Functions

bool testModuloComputer ()
 
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
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2010/07/07

Functions for testing class ModuloComputer.

This file is part of the DGtal library.

Definition in file testModuloComputer.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 88 of file testModuloComputer.cpp.

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

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

◆ testModuloComputer()

bool testModuloComputer ( )

Example of a test. To be completed.

Definition at line 48 of file testModuloComputer.cpp.

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 }
implements basic functions on modular arithmetic.
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:564

References DGtal::Trace::beginBlock(), DGtal::ModuloComputer< TInteger >::cast(), DGtal::Trace::endBlock(), DGtal::ModuloComputer< TInteger >::increment(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().