DGtal  0.9.3
Functions
testPointVector-catch.cpp File Reference
#include <cstdio>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/PointVector.h"
#include "DGtalCatch.h"
Include dependency graph for testPointVector-catch.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("Point Vector Unit tests")
 

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
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr )
Date
2015/06/06

This file is part of the DGtal library

Definition in file testPointVector-catch.cpp.

Function Documentation

◆ TEST_CASE()

TEST_CASE ( "Point Vector Unit tests"  )

Definition at line 46 of file testPointVector-catch.cpp.

References aPoint(), DGtal::PointVector< dim, TEuclideanRing, TContainer >::begin(), CAPTURE(), DGtal::PointVector< dim, TEuclideanRing, TContainer >::end(), REQUIRE(), and SECTION().

47 {
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 }
const Point aPoint(3, 4)
CAPTURE(thicknessHV)
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
MyPointD Point
Definition: testClone2.cpp:383
Space::RealPoint RealPoint
Definition: StdDefs.h:97
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
SECTION("Testing constant forward iterators")