DGtal 1.3.0
Searching...
No Matches
testBasicMathFunctions.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/math/BasicMathFunctions.h"
35
36using namespace std;
37using 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
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
88
89 return nbok == nb;
90}
91
93// Standard services - public :
94
95int 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="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
T power(const T &aVal, const unsigned int exponent)
T roundToUpperPowerOfTwo(const T &n)
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
bool testBasicMathFunctions()
int main()
Definition: testBits.cpp:56