DGtal  1.0.0
testBasicMathFunctions.cpp
Go to the documentation of this file.
1
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/math/BasicMathFunctions.h"
35
36 using namespace std;
37 using namespace DGtal;
38
40 // Functions for testing class BasicMathFunctions.
42
47 {
48  unsigned int nbok = 0;
49  unsigned int nb = 0;
50
51  trace.beginBlock ( "Testing power by squaring ..." );
52
53  trace.info() << "power(5,4)= "<< functions::power(5,4) <<std::endl;
54  nbok += (functions::power(5,4)==625) ? 1 : 0;
55  nb++;
56  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
57
58
59  trace.info() << "power(5.0,4)= "<< functions::power(5.0,4) <<std::endl;
60  nbok += (functions::power(5,4)==625.0) ? 1 : 0;
61  nb++;
62  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
63
64
65  trace.endBlock();
66  trace.beginBlock ( "Testing roundToUpperPowerOfTwo ..." );
67
68  trace.info() << "roundToUpperPowerOfTwo(200)= "<< functions::roundToUpperPowerOfTwo(200) <<std::endl;
69  nbok += (functions::roundToUpperPowerOfTwo(200)==256) ? 1 : 0;
70  nb++;
71
72  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
73
74
75  trace.info() << "roundToUpperPowerOfTwo(1000)= "<< functions::roundToUpperPowerOfTwo(1000) <<std::endl;
76  nbok += (functions::roundToUpperPowerOfTwo(1000)==1024) ? 1 : 0;
77  nb++;
78  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
79
80
81  trace.info() << "power(5.0,4)= "<< functions::power(5.0,4) <<std::endl;
82  nbok += (functions::power(5,4)==625.0) ? 1 : 0;
83  nb++;
84  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
85
86
87  trace.endBlock();
88
89  return nbok == nb;
90 }
91
93 // Standard services - public :
94
95 int main( int argc, char** argv )
96 {
97  trace.beginBlock ( "Testing class BasicMathFunctions" );
98  trace.info() << "Args:";
99  for ( int i = 0; i < argc; ++i )
100  trace.info() << " " << argv[ i ];
101  trace.info() << endl;
102
103  bool res = testBasicMathFunctions(); // && ... other tests
104  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
105  trace.endBlock();
106  return res ? 0 : 1;
107 }
108 // //
void beginBlock(const std::string &keyword="")
int main(int argc, char **argv)
Trace trace
Definition: Common.h:144
double endBlock()
bool testBasicMathFunctions()
std::ostream & emphase()
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()