DGtal  0.9.3
Functions
testInteger.cpp File Reference
#include <iostream>
#include <string>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/CInteger.h"
#include "DGtal/kernel/CUnsignedNumber.h"
Include dependency graph for testInteger.cpp:

Go to the source code of this file.

Functions

bool testInteger ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
Date
2010/07/02

Functions for testing class Integer.

This file is part of the DGtal library.

Definition in file testInteger.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 124 of file testInteger.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testInteger(), and DGtal::trace.

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
std::ostream & emphase()
bool testInteger()
Definition: testInteger.cpp:49
std::ostream & info()

◆ testInteger()

bool testInteger ( )

Example of a test. To be completed.

Definition at line 49 of file testInteger.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), max(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

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 }
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...
double endBlock()
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:69
int max(int a, int b)
std::ostream & warning()
std::ostream & info()