DGtal  1.0.0
doc-examples/exampleCatch.cpp

DGtal/Catch examples

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_3("STL Container test", "Description", T,
std::list<int>, std::vector<int>, std::set<int>)
{
T defaultConstructed;
SECTION("Size of the default constructed container")
{
REQUIRE( ( defaultConstructed.size() == 0 ) );
}