DGtal  0.9.2
exampleCatch.cpp
1 
30 #include <iostream>
32 #include "ConfigExamples.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/base/Common.h"
35 
36 #include <vector>
37 #include <list>
38 #include <set>
39 
41 #include "DGtalCatch.h"
43 
45 
46 using namespace std;
47 using namespace DGtal;
48 
49 
51 TEST_CASE( "Point Vector Unit tests" )
52 {
53 
54  //Global variables and init for this test case
55  typedef PointVector<4, DGtal::int32_t> Point;
57 
58  DGtal::int32_t t1[] = {1,2,3,4};
59  DGtal::int32_t t2[]= {5,4,3,2};
60  double t3[]= {1.0,-1.0,2.0,-2.0};
61 
62  Point p1( t1 );
63  Point p1bis( t1 );
64  Point p2( t2 );
65  RealPoint p3(t3);
66 
67  SECTION("Comparisons")
68  {
69  REQUIRE( (p1 == p1bis) );
70  REQUIRE( p1 < p2 );
71  }
72 
73  SECTION("Min/Max of vector components")
74  {
75  REQUIRE( (p3.max() == 2.0) );
76  REQUIRE( (p3.min() == -2.0) );
77  REQUIRE( (*p3.maxElement() == 2.0) );
78  REQUIRE( (*p3.minElement() == -2.0) );
79  }
80  SECTION("Arithmetical Operators")
81  {
82  REQUIRE( ((p1 + p2) == Point(6,6,6,6)) );
83  REQUIRE( ((p1 - p2) == Point(-4,-2,0,2)) );
84  REQUIRE( ((p1*2) == Point(2,4,6,8)) );
85  REQUIRE( ((2*p1) == Point(2,4,6,8)) );
86  REQUIRE( ((-p1) == Point(-1,-2,-3,-4)) );
87  REQUIRE( (p1.inf(p2) == Point(1,2,3,2)) );
88  REQUIRE( (p1.sup(p2) == Point(5,4,3,4)) );
89  REQUIRE( (p1.dot(p2) == 30) );
90  }
91 
92 }
94 
95 
97 TEMPLATE_TEST_CASE_3("STL Container test", "Description", T,
98  std::list<int>, std::vector<int>, std::set<int>)
99 {
100  T defaultConstructed;
101 
102  SECTION("Size of the default constructed container")
103  {
104  REQUIRE( ( defaultConstructed.size() == 0 ) );
105  }
106 
107  //Adding a value
108  defaultConstructed.insert( defaultConstructed.begin(), 5 );
109 
110  SECTION("Size after one insert")
111  {
112  REQUIRE( ( defaultConstructed.size() == 1 ) );
113  }
114 }
116 
117 
STL namespace.
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
DGtal is the top-level namespace which contains all DGtal functions and types.
Space::RealPoint RealPoint
Definition: StdDefs.h:97
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72