DGtal 1.4.0
Loading...
Searching...
No Matches
doc-examples/exampleCatch.cpp

DGtal/Catch examples

See also
Unit test in DGtal using Catch
#include <iostream>
#include "ConfigExamples.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include <vector>
#include <list>
#include <set>
#include "DGtalCatch.h"
using namespace std;
using namespace DGtal;
TEST_CASE( "Point Vector Unit tests" )
{
//Global variables and init for this test case
DGtal::int32_t t1[] = {1,2,3,4};
DGtal::int32_t t2[]= {5,4,3,2};
double t3[]= {1.0,-1.0,2.0,-2.0};
Point p1( t1 );
Point p1bis( t1 );
Point p2( t2 );
RealPoint p3(t3);
SECTION("Comparisons")
{
REQUIRE( (p1 == p1bis) );
REQUIRE( p1 < p2 );
}
SECTION("Min/Max of vector components")
{
REQUIRE( (p3.max() == 2.0) );
REQUIRE( (p3.min() == -2.0) );
REQUIRE( (*p3.maxElement() == 2.0) );
REQUIRE( (*p3.minElement() == -2.0) );
}
SECTION("Arithmetical Operators")
{
REQUIRE( ((p1 + p2) == Point(6,6,6,6)) );
REQUIRE( ((p1 - p2) == Point(-4,-2,0,2)) );
REQUIRE( ((p1*2) == Point(2,4,6,8)) );
REQUIRE( ((2*p1) == Point(2,4,6,8)) );
REQUIRE( ((-p1) == Point(-1,-2,-3,-4)) );
REQUIRE( (p1.inf(p2) == Point(1,2,3,2)) );
REQUIRE( (p1.sup(p2) == Point(5,4,3,4)) );
REQUIRE( (p1.dot(p2) == 30) );
}
}
TEMPLATE_TEST_CASE("STL Container test", "Description",
std::list<int>, std::vector<int>, std::set<int>)
{
TestType defaultConstructed;
SECTION("Size of the default constructed container")
{
REQUIRE( ( defaultConstructed.size() == 0 ) );
}
//Adding a value
defaultConstructed.insert( defaultConstructed.begin(), 5 );
SECTION("Size after one insert")
{
REQUIRE( ( defaultConstructed.size() == 1 ) );
}
}
Aim: Implements basic operations that will be used in Point and Vector classes.
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int32_t int32_t
signed 32-bit integer.
Definition BasicTypes.h:72
STL namespace.
MyPointD Point
TEST_CASE("int container traits", "[int][traits]")
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))
PointVector< 3, double > RealPoint