DGtal 2.1.0
Loading...
Searching...
No Matches
testDGtalBigInteger.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/io/boards/Board2D.h"
34#include "DGtal/kernel/SpaceND.h"
35#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
36#include "DGtal/geometry/curves/FreemanChain.h"
37#include "DGtal/geometry/curves/GreedySegmentation.h"
38#include "DGtal/kernel/domains/HyperRectDomain.h"
39#include "DGtal/images/ImageContainerBySTLVector.h"
40
42
43using namespace std;
44using namespace DGtal;
45
47// Functions for testing class DGtalBIGINTEGER.
49
54{
55 unsigned int nbok = 0;
56 unsigned int nb = 0;
57
58 trace.beginBlock ( "BIGINTEGER linking test..." );
59
60 DGtal::BigInteger a(1234);
61 DGtal::BigInteger b("-5678");
62 DGtal::BigInteger c = a + b;
63
64 trace.info() << "sum is " << c << "\n";
65 trace.info() << "absolute value is " << abs(c) << "\n";
66
67 nbok += (abs(c)==4444) ? 1 : 0;
68 nb++;
69 trace.info() << "(" << nbok << "/" << nb << ") "
70 << "true == true" << std::endl;
72
73 return nbok == nb;
74}
75
76
82{
83 unsigned int nbok = 0;
84 unsigned int nb = 0;
85
86 trace.beginBlock ( "BIGINTEGER Space test..." );
87
88 //This space is weird...
89 typedef SpaceND<2, DGtal::BigInteger> Space2;
90 typedef Space2::Point Point;
91 typedef Space2::Point::Coordinate Coordinate;
93
94 DGtal::BigInteger a(1234);
95 DGtal::BigInteger b("-5678");
96 Point p(a,b);
97
99
100 // Construct the Freeman chain
101 std::stringstream ss(stringstream::in | stringstream::out);
102 ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
103 Contour theContour( ss );
104
105 Point p1( 0, 0 );
106 Point p2( 31, 31 );
107
108 trace.info() <<"p2.norm()= "<< p2.norm()<<endl;
109
110 Domain domain( p1, p2 );
111 Board2D aBoard;
112 aBoard << SetMode( domain.className(), "Grid" )
113 << domain
114 << theContour;
115
116 aBoard.saveSVG("testbigintcontour.svg");
117
118
119 nbok += true ? 1 : 0;
120 nb++;
121 trace.info() << "(" << nbok << "/" << nb << ") "
122 << "true == true" << std::endl;
123 trace.endBlock();
124
125 return nbok == nb;
126}
127
129// Standard services - public :
130
131int main( int argc, char** argv )
132{
133 trace.beginBlock ( "Testing class DGtalBIGINTEGER" );
134 trace.info() << "Args:";
135 for ( int i = 0; i < argc; ++i )
136 trace.info() << " " << argv[ i ];
137 trace.info() << endl;
138
139 bool res = testDGtalBIGINTEGER() && testBIGINTEGERSpace(); // && ... other tests
140 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
141 trace.endBlock();
142 return res ? 0 : 1;
143}
144// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition Board2D.h:71
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
std::string className() const
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1011
double norm() const
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>, boost::multiprecision::et_off > BigInteger
Definition BasicTypes.h:75
STL namespace.
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition Board2D.h:247
int main()
Definition testBits.cpp:56
MyPointD Point
FreemanChain< int > Contour
bool testDGtalBIGINTEGER()
bool testBIGINTEGERSpace()
Domain domain
HyperRectDomain< Space > Domain