DGtal  0.9.3
testInteger.cpp
Go to the documentation of this file.
1 
30 #include <iostream>
32 #include <string>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/kernel/CInteger.h"
35 #include "DGtal/kernel/CUnsignedNumber.h"
37 
38 using namespace std;
39 using namespace DGtal;
40 
42 // Functions for testing class Integer.
44 
50 {
51  unsigned int nbok = 0;
52  unsigned int nb = 0;
53 
54  trace.beginBlock ( "Checking CInteger models ..." );
55  BOOST_CONCEPT_ASSERT(( concepts::CInteger<int> ));
56  BOOST_CONCEPT_ASSERT(( concepts::CInteger<DGtal::int16_t> ));
57 
58  nbok += true ? 1 : 0;
59  nb++;
60  trace.info() << "(" << nbok << "/" << nb << ") "
61  << "true == true" << std::endl;
62 
63  trace.info() << " - max int16 = " << NumberTraits<DGtal::int16_t>::max()
64  << std::endl;
65  trace.info() << " - min int16 = " << NumberTraits<DGtal::int16_t>::min()
66  << std::endl;
67  trace.info() << " - max int32 = " << NumberTraits<DGtal::int32_t>::max()
68  << std::endl;
69  trace.info() << " - min int32 = " << NumberTraits<DGtal::int32_t>::min()
70  << std::endl;
71  trace.info() << " - max int64 = " << NumberTraits<DGtal::int64_t>::max()
72  << std::endl;
73  trace.info() << " - min int64 = " << NumberTraits<DGtal::int64_t>::min()
74  << std::endl;
75  trace.info() << " - max uint16 = " << NumberTraits<DGtal::uint16_t>::max()
76  << std::endl;
77  trace.info() << " - min uint16 = " << NumberTraits<DGtal::uint16_t>::min()
78  << std::endl;
79  trace.info() << " - max uint32 = " << NumberTraits<DGtal::uint32_t>::max()
80  << std::endl;
81  trace.info() << " - min uint32 = " << NumberTraits<DGtal::uint32_t>::min()
82  << std::endl;
83  trace.info() << " - max uint64 = " << NumberTraits<DGtal::uint64_t>::max()
84  << std::endl;
85  trace.info() << " - min uint64 = " << NumberTraits<DGtal::uint64_t>::min()
86  << std::endl;
87 
88  trace.endBlock();
89 
90  trace.beginBlock ( "Checking CUnsignedInteger models ..." );
91  BOOST_CONCEPT_ASSERT(( concepts::CUnsignedNumber<unsigned int> ));
92  // These tests fail : int is not a model of CUnsignedInteger.
93  // BOOST_CONCEPT_ASSERT(( CUnsignedInteger<int> ));
94  nbok += true ? 1 : 0;
95  nb++;
96  trace.info() << "(" << nbok << "/" << nb << ") "
97  << "true == true" << std::endl;
98  trace.endBlock();
99 
100  trace.beginBlock ( "Checking NumberTraits on built-in OS dependent types ..." );
101  trace.warning() << "If digits() returns 0, the type is not considered in specilizations"<<endl;
102  trace.info() << " - digits int = " << NumberTraits<int>::digits()<< std::endl;
103  // nbok += (NumberTraits<int>::digits() == 0) ? 0 : 1;
104  // nb++;
105  trace.info() << " - digits unsigned int = " << NumberTraits<unsigned int>::digits()<< std::endl;
106  // nbok += (NumberTraits<unsigned int>::digits() == 0) ? 0 : 1;
107  //nb++;
108  trace.info() << " - digits long int = " << NumberTraits<long int>::digits()<< std::endl;
109  //nbok += (NumberTraits<long int>::digits() == 0) ? 0 : 1;
110  //nb++;
111 
112  trace.info() << "(" << nbok << "/" << nb << ") "
113  << "true == true" << std::endl;
114  trace.endBlock();
115 
116 
117 
118  return nbok == nb;
119 }
120 
122 // Standard services - public :
123 
124 int main( int argc, char** argv )
125 {
126  trace.beginBlock ( "Testing class Integer" );
127  trace.info() << "Args:";
128  for ( int i = 0; i < argc; ++i )
129  trace.info() << " " << argv[ i ];
130  trace.info() << endl;
131 
132  bool res = testInteger(); // && ... other tests
133  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
134  trace.endBlock();
135  return res ? 0 : 1;
136 }
137 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
Aim: Concept checking for Unsigned numbers. Models of this concept should be listed in NumberTraits c...
STL namespace.
double endBlock()
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
std::ostream & emphase()
bool testInteger()
Definition: testInteger.cpp:49
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:69
DGtal is the top-level namespace which contains all DGtal functions and types.
int max(int a, int b)
std::ostream & warning()
std::ostream & info()
int main(int argc, char **argv)