DGtal  0.9.3
testPointVector-catch.cpp
Go to the documentation of this file.
1 
32 #include <cstdio>
33 #include <cmath>
34 #include <iostream>
35 #include <fstream>
36 #include <vector>
37 #include "DGtal/base/Common.h"
38 #include "DGtal/kernel/PointVector.h"
39 
40 #include "DGtalCatch.h"
41 
42 using namespace DGtal;
43 using namespace std;
44 
45 
46 TEST_CASE( "Point Vector Unit tests" )
47 {
49  typedef PointVector<4, double> RealPoint;
50 
51  DGtal::int32_t t1[] = {1,2,3,4};
52  DGtal::int32_t t2[]= {5,4,3,2};
53  double t3[]= {1.0,-1.0,2.0,-2.0};
54 
55  Point p1( t1 );
56  Point p1bis( t1 );
57  Point p2( t2 );
58  RealPoint p3(t3);
59 
60 
61  SECTION("Comparisons")
62  {
63  REQUIRE( p1 == p1bis );
64  REQUIRE( p1 < p2 );
65 
66  RealPoint realInitializerlist( { 3.5, 4.2, 2.2, 3.2 } );
67  REQUIRE( p1 != realInitializerlist );
68  }
69 
70  SECTION("Min/Max of vector components")
71  {
72  REQUIRE( p3.max() == 2.0 );
73  REQUIRE( p3.min() == -2.0 );
74  REQUIRE( *p3.maxElement() == 2.0 );
75  REQUIRE( *p3.minElement() == -2.0 );
76  }
77 
78  Point aPoint;
79  aPoint[ 3 ] = 0;
80  aPoint[ 2 ] = 2;
81  aPoint[ 1 ] = -1;
82  aPoint[ 0 ] = 3;
83 
84  SECTION("Testing norms")
85  {
86  RealPoint normalized = aPoint.getNormalized();
87  CAPTURE( normalized );
88  REQUIRE( aPoint.norm ( Point::L_1 ) == 6 );
89  REQUIRE( aPoint.norm ( Point::L_infty ) == 3 );
90  REQUIRE( normalized[0] == Approx( 0.801784) );
91  REQUIRE( normalized[1] == Approx( -0.267261) );
92  REQUIRE( normalized[2] == Approx( 0.534522) );
93  REQUIRE( normalized[3] == Approx( 0.0) );
94  }
95 
96  SECTION("PointVector Iterator")
97  {
98  PointVector<25,int> aPoint25;
99  for (unsigned int i=0;i<25;++i)
100  aPoint25[i] = i;
101 
102  int sum = 0;
103  for (PointVector<25,int>::ConstIterator it = aPoint25.begin() ; it != aPoint25.end(); ++it)
104  sum += (*it);
105 
106  CAPTURE(aPoint25);
107  CAPTURE(sum);
108  REQUIRE( sum == 300 );
109  }
110 
111  SECTION("Arithmetical Operators")
112  {
113  REQUIRE( (p1 + p2) == Point(6,6,6,6) );
114  REQUIRE( (p1 - p2) == Point(-4,-2,0,2) );
115  REQUIRE( (p1*2) == Point(2,4,6,8) );
116  REQUIRE( (2*p1) == Point(2,4,6,8) );
117  REQUIRE( (-p1) == Point(-1,-2,-3,-4) );
118  REQUIRE( p1.inf(p2) == Point(1,2,3,2) );
119  REQUIRE( p1.sup(p2) == Point(5,4,3,4) );
120  REQUIRE( p1.dot(p2) == 30 );
121  }
122 
123 }
124 
125 
const Point aPoint(3, 4)
CAPTURE(thicknessHV)
TEST_CASE("Point Vector Unit tests")
STL namespace.
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
REQUIRE(domain.isInside(aPoint))
Container::const_iterator ConstIterator
Definition: PointVector.h:182
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
SECTION("Testing constant forward iterators")