DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testInteger.cpp
1 
30 
31 #include <iostream>
32 #include <string>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/kernel/CInteger.h"
35 #include "DGtal/kernel/CUnsignedInteger.h"
37 
38 using namespace std;
39 using namespace DGtal;
40 
42 // Functions for testing class Integer.
44 
49 bool testInteger()
50 {
51  unsigned int nbok = 0;
52  unsigned int nb = 0;
53 
54  trace.beginBlock ( "Checking CInteger models ..." );
55  BOOST_CONCEPT_ASSERT(( CInteger<int> ));
56  BOOST_CONCEPT_ASSERT(( CInteger<unsigned int> ));
57  BOOST_CONCEPT_ASSERT(( CInteger<DGtal::uint16_t> ));
58  BOOST_CONCEPT_ASSERT(( CInteger<DGtal::int16_t> ));
59 
60  //OS depedent instances
61  //BOOST_CONCEPT_ASSERT(( CInteger<long int> ));
62 
63  // These tests fail : bool is not a model of CInteger.
64  // BOOST_CONCEPT_ASSERT(( CInteger<std::string> ));
65  // BOOST_CONCEPT_ASSERT(( CInteger<bool> ));
66  nbok += true ? 1 : 0;
67  nb++;
68  trace.info() << "(" << nbok << "/" << nb << ") "
69  << "true == true" << std::endl;
70 
71  trace.info() << " - max int16 = " << NumberTraits<DGtal::int16_t>::max()
72  << std::endl;
73  trace.info() << " - min int16 = " << NumberTraits<DGtal::int16_t>::min()
74  << std::endl;
75  trace.info() << " - max int32 = " << NumberTraits<DGtal::int32_t>::max()
76  << std::endl;
77  trace.info() << " - min int32 = " << NumberTraits<DGtal::int32_t>::min()
78  << std::endl;
79  trace.info() << " - max int64 = " << NumberTraits<DGtal::int64_t>::max()
80  << std::endl;
81  trace.info() << " - min int64 = " << NumberTraits<DGtal::int64_t>::min()
82  << std::endl;
83  trace.info() << " - max uint16 = " << NumberTraits<DGtal::uint16_t>::max()
84  << std::endl;
85  trace.info() << " - min uint16 = " << NumberTraits<DGtal::uint16_t>::min()
86  << std::endl;
87  trace.info() << " - max uint32 = " << NumberTraits<DGtal::uint32_t>::max()
88  << std::endl;
89  trace.info() << " - min uint32 = " << NumberTraits<DGtal::uint32_t>::min()
90  << std::endl;
91  trace.info() << " - max uint64 = " << NumberTraits<DGtal::uint64_t>::max()
92  << std::endl;
93  trace.info() << " - min uint64 = " << NumberTraits<DGtal::uint64_t>::min()
94  << std::endl;
95 
96  trace.endBlock();
97 
98  trace.beginBlock ( "Checking CUnsignedInteger models ..." );
99  BOOST_CONCEPT_ASSERT(( CUnsignedInteger<unsigned int> ));
100  // These tests fail : int is not a model of CUnsignedInteger.
101  // BOOST_CONCEPT_ASSERT(( CUnsignedInteger<int> ));
102  nbok += true ? 1 : 0;
103  nb++;
104  trace.info() << "(" << nbok << "/" << nb << ") "
105  << "true == true" << std::endl;
106  trace.endBlock();
107 
108  trace.beginBlock ( "Checking NumberTraits on built-in OS dependent types ..." );
109  trace.warning() << "If digits() returns 0, the type is not considered in specilizations"<<endl;
110  trace.info() << " - digits int = " << NumberTraits<int>::digits()<< std::endl;
111  // nbok += (NumberTraits<int>::digits() == 0) ? 0 : 1;
112  // nb++;
113  trace.info() << " - digits unsigned int = " << NumberTraits<unsigned int>::digits()<< std::endl;
114  // nbok += (NumberTraits<unsigned int>::digits() == 0) ? 0 : 1;
115  //nb++;
116  trace.info() << " - digits long int = " << NumberTraits<long int>::digits()<< std::endl;
117  //nbok += (NumberTraits<long int>::digits() == 0) ? 0 : 1;
118  //nb++;
119 
120  trace.info() << "(" << nbok << "/" << nb << ") "
121  << "true == true" << std::endl;
122  trace.endBlock();
123 
124 
125 
126  return nbok == nb;
127 }
128 
130 // Standard services - public :
131 
132 int main( int argc, char** argv )
133 {
134  trace.beginBlock ( "Testing class Integer" );
135  trace.info() << "Args:";
136  for ( int i = 0; i < argc; ++i )
137  trace.info() << " " << argv[ i ];
138  trace.info() << endl;
139 
140  bool res = testInteger(); // && ... other tests
141  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
142  trace.endBlock();
143  return res ? 0 : 1;
144 }
145 // //