DGtal 1.4.0
Loading...
Searching...
No Matches
testAstroid2D.cpp File Reference
#include <iostream>
#include <random>
#include "DGtalCatch.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/shapes/parametric/Astroid2D.h"
Include dependency graph for testAstroid2D.cpp:

Go to the source code of this file.

Typedefs

typedef Astroid2D< SpaceShape
 

Functions

double notNullValue (std::uniform_real_distribution< double > &unif, std::default_random_engine &re)
 
RealPoint notNullRealPoint (std::uniform_real_distribution< double > &unif, std::default_random_engine &re)
 
 TEST_CASE ("Astroid2D")
 

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
Adrien Krähenbühl (krahe.nosp@m.nbuh.nosp@m.l@uni.nosp@m.stra.nosp@m..fr ) Laboratoire ICube, UMR 7357, Université de Strasbourg, France
Date
2019/07/18

Functions for testing the methods of the Astroid2D shape. In particular, test the parameter() method for cas leadind to a division by 0.

This file is part of the DGtal library.

Definition in file testAstroid2D.cpp.

Typedef Documentation

◆ Shape

Function Documentation

◆ notNullRealPoint()

RealPoint notNullRealPoint ( std::uniform_real_distribution< double > & unif,
std::default_random_engine & re )

Definition at line 59 of file testAstroid2D.cpp.

62{
63 return RealPoint(notNullValue(unif,re),notNullValue(unif,re));
64}
Space::RealPoint RealPoint
Definition StdDefs.h:97
double notNullValue(std::uniform_real_distribution< double > &unif, std::default_random_engine &re)

References notNullValue().

Referenced by TEST_CASE().

◆ notNullValue()

double notNullValue ( std::uniform_real_distribution< double > & unif,
std::default_random_engine & re )

Definition at line 47 of file testAstroid2D.cpp.

50{
51 double res;
52 do {
53 res = unif(re);
54 }
55 while ( res == Approx(0.) );
56 return res;
57}

Referenced by notNullRealPoint(), and TEST_CASE().

◆ TEST_CASE()

TEST_CASE ( "Astroid2D" )

Definition at line 66 of file testAstroid2D.cpp.

67{
68 std::uniform_real_distribution<double> unif(-10000,10000);
69 std::default_random_engine re;
70
71 SECTION("center()")
72 {
73 const RealPoint center(unif(re),unif(re));
74 Shape shape( center, unif(re), unif(re) );
75 REQUIRE( shape.center() == center );
76 }
77
78 SECTION("Lower and upper bounds")
79 {
80 Shape shape( unif(re), unif(re), unif(re), unif(re) );
81 REQUIRE( shape.getLowerBound() <= shape.getUpperBound() );
82 }
83
84 SECTION("parameter() with null x-radius -> division by 0.")
85 {
86 Shape shape( unif(re), unif(re), 0., notNullValue(unif,re) );
87 REQUIRE_NOTHROW( shape.parameter(notNullRealPoint(unif,re)) );
88 }
89
90 SECTION("parameter() with null y-radius -> division by 0.")
91 {
92 Shape shape( unif(re), unif(re), notNullValue(unif,re), 0. );
93 REQUIRE_NOTHROW( shape.parameter(notNullRealPoint(unif,re)) );
94 }
95
96 SECTION("parameter() with null x-radius and y-radius -> undefined behaviour.")
97 {
98 Shape shape( unif(re), unif(re), 0., 0. );
99 REQUIRE_NOTHROW( shape.parameter(notNullRealPoint(unif,re)) );
100 }
101
102 SECTION("parameter() where (x,y) parameter with x == center -> pi/2 or 3*pi/2")
103 {
104 const double centerX = unif(re);
105 Shape shape( centerX, unif(re), unif(re), unif(re) );
106 const RealPoint point( centerX, unif(re) );
107 REQUIRE_NOTHROW( shape.parameter(point) );
108 double res = shape.parameter(point);
109 REQUIRE_THAT( res, Catch::WithinAbs(M_PI_2,DBL_EPSILON) || Catch::WithinAbs(3*M_PI_2,DBL_EPSILON) );
110 }
111
112 SECTION("parameter() with point parameter with null y -> 0. or pi")
113 {
114 const double centerY = unif(re);
115 Shape shape( unif(re), centerY, unif(re), unif(re) );
116 const RealPoint point( unif(re), centerY );
117 REQUIRE_NOTHROW( shape.parameter(point) );
118 double res = shape.parameter(point);
119 REQUIRE_THAT( res, Catch::WithinAbs(0.,DBL_EPSILON) || Catch::WithinAbs(M_PI,DBL_EPSILON) );
120 }
121}
Aim: Implements basic operations that will be used in Point and Vector classes.
Point center(const std::vector< Point > &points)
RealPoint notNullRealPoint(std::uniform_real_distribution< double > &unif, std::default_random_engine &re)
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))

References DGtal::Astroid2D< TSpace >::center(), DGtal::Astroid2D< TSpace >::getLowerBound(), DGtal::Astroid2D< TSpace >::getUpperBound(), notNullRealPoint(), notNullValue(), DGtal::Astroid2D< TSpace >::parameter(), REQUIRE(), and SECTION().