DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testBasicMathFunctions.cpp
Go to the documentation of this file.
1
16
29
31
#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
46
bool
testBasicMathFunctions
()
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
// //
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal::functions::power
T power(const T &aVal, const unsigned int exponent)
Definition
BasicMathFunctions.h:73
DGtal::functions::roundToUpperPowerOfTwo
T roundToUpperPowerOfTwo(const T &n)
Definition
BasicMathFunctions.h:102
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
testBasicMathFunctions
bool testBasicMathFunctions()
Definition
testBasicMathFunctions.cpp:46
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
tests
math
testBasicMathFunctions.cpp
Generated on
for DGtal by
1.18.0