DGtal 1.4.0
Loading...
Searching...
No Matches
testBasicBoolFunctors.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/base/BasicBoolFunctors.h"
35
36using namespace std;
37using namespace DGtal;
38using namespace DGtal::functors;
39
40#define INBLOCK_TEST(x) \
41 nbok += ( x ) ? 1 : 0; \
42 nb++; \
43 trace.info() << "(" << nbok << "/" << nb << ") " \
44 << #x << std::endl;
45
46#define INBLOCK_TEST2(x,y) \
47 nbok += ( x ) ? 1 : 0; \
48 nb++; \
49 trace.info() << "(" << nbok << "/" << nb << ") " \
50 << y << std::endl;
51
53// Functions for testing class BasicBoolFunctors.
55
60{
61 unsigned int nbok = 0;
62 unsigned int nb = 0;
63
64 trace.beginBlock ( "Testing block ..." );
65 // true()
66 nbok += trueBF0() == true ? 1 : 0;
67 nb++;
68 trace.info() << "(" << nbok << "/" << nb << ") "
69 << "true() == true" << std::endl;
70
71 // false()
72 nbok += falseBF0() == false ? 1 : 0;
73 nb++;
74 trace.info() << "(" << nbok << "/" << nb << ") "
75 << "false() == false" << std::endl;
76
77 // id( b )
78 nbok += identityBF1( true ) == true ? 1 : 0;
79 nb++;
80 trace.info() << "(" << nbok << "/" << nb << ") "
81 << "id(true) == true" << std::endl;
82 nbok += identityBF1( false ) == false ? 1 : 0;
83 nb++;
84 trace.info() << "(" << nbok << "/" << nb << ") "
85 << "id(false) == false" << std::endl;
86
87 // not( b )
88 nbok += notBF1( true ) == false ? 1 : 0;
89 nb++;
90 trace.info() << "(" << nbok << "/" << nb << ") "
91 << "not(true) == false" << std::endl;
92 nbok += notBF1( false ) == true ? 1 : 0;
93 nb++;
94 trace.info() << "(" << nbok << "/" << nb << ") "
95 << "not(false) == true" << std::endl;
96
97 // and( b1, b2 )
98 nbok += andBF2( true, true ) == true ? 1 : 0;
99 nb++;
100 trace.info() << "(" << nbok << "/" << nb << ") "
101 << "and( true, true ) == true" << std::endl;
102 nbok += andBF2( false, true ) == false ? 1 : 0;
103 nb++;
104 trace.info() << "(" << nbok << "/" << nb << ") "
105 << "and( false, true ) == false" << std::endl;
106 nbok += andBF2( true, false ) == false ? 1 : 0;
107 nb++;
108 trace.info() << "(" << nbok << "/" << nb << ") "
109 << "and( true, false ) == false" << std::endl;
110 nbok += andBF2( false, false ) == false ? 1 : 0;
111 nb++;
112 trace.info() << "(" << nbok << "/" << nb << ") "
113 << "and( false, false ) == false" << std::endl;
114
115 // or( b1, b2 )
116 nbok += orBF2( true, true ) == true ? 1 : 0;
117 nb++;
118 trace.info() << "(" << nbok << "/" << nb << ") "
119 << "or( true, true ) == true" << std::endl;
120 nbok += orBF2( false, true ) == true ? 1 : 0;
121 nb++;
122 trace.info() << "(" << nbok << "/" << nb << ") "
123 << "or( false, true ) == true" << std::endl;
124 nbok += orBF2( true, false ) == true ? 1 : 0;
125 nb++;
126 trace.info() << "(" << nbok << "/" << nb << ") "
127 << "or( true, false ) == true" << std::endl;
128 nbok += orBF2( false, false ) == false ? 1 : 0;
129 nb++;
130 trace.info() << "(" << nbok << "/" << nb << ") "
131 << "or( false, false ) == true" << std::endl;
132
133 // xor( b1, b2 )
134 INBLOCK_TEST2( xorBF2( true, true ) == false, "xor( true, true ) == false" );
135 INBLOCK_TEST2( xorBF2( false, true ) == true, "xor( false, true ) == true" );
136 INBLOCK_TEST2( xorBF2( true, false ) == true, "xor( true, false ) == true" );
137 INBLOCK_TEST2( xorBF2( false, false ) == false, "xor( false, false ) == false" );
138
139 // implies( b1, b2 )
140 INBLOCK_TEST2( impliesBF2( true, true ) == true,
141 "implies( true, true ) == true" );
142 INBLOCK_TEST2( impliesBF2( false, true ) == true,
143 "implies( false, true ) == true" );
144 INBLOCK_TEST2( impliesBF2( true, false ) == false,
145 "implies( true, false ) == false" );
146 INBLOCK_TEST2( impliesBF2( false, false ) == true,
147 "implies( false, false ) == true" );
148
149 trace.endBlock();
150
151 return nbok == nb;
152}
153
155// Standard services - public :
156
157int main( int argc, char** argv )
158{
159 trace.beginBlock ( "Testing class BasicBoolFunctors" );
160 trace.info() << "Args:";
161 for ( int i = 0; i < argc; ++i )
162 trace.info() << " " << argv[ i ];
163 trace.info() << endl;
164
165 bool res = testBasicBoolFunctors(); // && ... other tests
166 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
167 trace.endBlock();
168 return res ? 0 : 1;
169}
170// //
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
functors namespace gathers all DGtal functors.
static const BoolFunctor1 notBF1
static const BoolFunctor2 andBF2
static const BoolFunctor1 identityBF1
static const BoolFunctor0 falseBF0
static const BoolFunctor2 impliesBF2
static const BoolFunctor0 trueBF0
static const BoolFunctor2 xorBF2
static const BoolFunctor2 orBF2
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
bool testBasicBoolFunctors()
#define INBLOCK_TEST2(x, y)
int main()
Definition testBits.cpp:56