double operator()(A a, B b) const
    {
        return a + b;
    }
};

TEST_CASE("const binary visitor works on const variants" NAME_EXT, "[visitor][binary visitor]")
{
    const variant_type a{7};
    const variant_type b = 3;
    const variant_type c{7.1};
    const variant_type d = 2.9;

    const add_visitor v;

    REQUIRE(mapbox::util::apply_visitor(v, a, b) == Approx(10));
    REQUIRE(mapbox::util::apply_visitor(v, c, d) == Approx(10));
    REQUIRE(mapbox::util::apply_visitor(v, a, c) == Approx(14.1));
    REQUIRE(mapbox::util::apply_visitor(v, a, d) == Approx(9.9));

    REQUIRE(mapbox::util::apply_visitor(v, b, a) == Approx(10));
    REQUIRE(mapbox::util::apply_visitor(v, d, c) == Approx(10));
    REQUIRE(mapbox::util::apply_visitor(v, c, a) == Approx(14.1));
    REQUIRE(mapbox::util::apply_visitor(v, d, a) == Approx(9.9));
}

TEST_CASE("non-const binary visitor works on const variants" NAME_EXT, "[visitor][binary visitor]")
{
    const variant_type a = 7;
    const variant_type b = 3;
    const variant_type c = 7.1;
예제 #2
0
 void operator() (mapnik::geometry::point<T> const& p1, mapnik::geometry::point<T> const& p2)
 {
     REQUIRE(p1.x == Approx(p2.x));
     REQUIRE(p1.y == Approx(p2.y));
 }
예제 #3
0
파일: hw513_main.cpp 프로젝트: roeje/hw513
#include "gvsu_cis.h"

#include "Polynomial.hpp"
#include <sstream>

TEST_CASE ("Getter")
{
    /* 8x^100 - 3x^5 + 9 */
    Polynomial<float> one("[8 100] [-3 5] [9 0]");

    SECTION ("Coefficient getters") {
        REQUIRE (one[0] == Approx(8.0));
        REQUIRE (one[1] == Approx(-3.0));
        REQUIRE (one[2] == Approx(9.0));
    }
    SECTION ("Exponent getters") {
        REQUIRE (one % 0 == 100);
        REQUIRE (one % 1 == 5);
        REQUIRE (one % 2 == 0);
    }

    SECTION ("Highest Order") {
        REQUIRE (one.maxDegree() == 100);
    }
}

TEST_CASE ("Evaluate Constant Polynom")
{
    Polynomial<float> one("[2.5 0]");

    for (int k = -10; k < 10; k++)
예제 #4
0
#include "../catch.hpp"

#include "hist.h"

TEST_CASE("Hist", "[vector]" )
{

    SECTION( "init" )
    {
        nucmath::Hist hist;
        hist.init(-10.0, 0.25, 8);

        REQUIRE(hist.getBinWidth() == Approx(0.25));
        REQUIRE(hist.getLowestEdge() == Approx(-10.0));
        REQUIRE(hist.getHighestEdge() == Approx(-10.0 + 0.25*8));
    }

    SECTION( "add" )
    {
        nucmath::Hist hist;
        hist.init(-10.0, 0.25, 8);

        hist.add(3.0);
        REQUIRE(hist.getLowestEdge() == Approx(-10.0));
        REQUIRE(hist.getHighestEdge() == Approx(3.0 + 0.25));

        hist.add(-20.1);
        REQUIRE(hist.getLowestEdge() == Approx(-20.0 - 0.25));
        REQUIRE(hist.getHighestEdge() == Approx(3.0 + 0.25));
    }
예제 #5
0
 *  Distributed under the Boost Software License, Version 1.0. (See accompanying
 *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 */

#include "catch.hpp"

///////////////////////////////////////////////////////////////////////////////
TEST_CASE
(
    "./succeeding/Approx/simple", 
    "Some simple comparisons between doubles"
)
{
    double d = 1.23;
    
    REQUIRE( d == Approx( 1.23 ) );
    REQUIRE( d != Approx( 1.22 ) );
    REQUIRE( d != Approx( 1.24 ) );

    REQUIRE( Approx( d ) == 1.23 );
    REQUIRE( Approx( d ) != 1.22 );
    REQUIRE( Approx( d ) != 1.24 );
}

///////////////////////////////////////////////////////////////////////////////
TEST_CASE
(
    "./succeeding/Approx/epsilon", 
    "Approximate comparisons with different epsilons"
 )
{
예제 #6
0
파일: Helpers_test.cpp 프로젝트: mmyros/Oat
SCENARIO ("Sample period comparisons with epsilon tolerance.", "[Helpers]") {

    GIVEN ("An epsilon tolerance for sample periods.") {

        double min_rate;
        const double epsilon = 1e-6;

        WHEN ("The difference between the max and min sample periods is greater than epsilon.") {

            std::vector<double> all_ts {10, 10 + epsilon, 10 - epsilon};

            THEN ("The sample periods are inconsistent.") {

                bool ts_consistent = oat::checkSamplePeriods(all_ts, min_rate, epsilon);
                REQUIRE (!ts_consistent);
                REQUIRE (min_rate == Approx(1.0 / (10 - epsilon)));
            }
        }

        WHEN ("The difference between the max and min sample periods is less than or equal to epsilon.") {

            double div = 2.01;
            std::vector<double> all_ts {10, 10 + epsilon/div, 10 - epsilon/div};

            THEN ("The sample periods are consistent.") {

                bool ts_consistent = oat::checkSamplePeriods(all_ts, min_rate, epsilon);
                REQUIRE (ts_consistent);
                REQUIRE (min_rate == Approx(1.0 / (10 - epsilon/div)));
            }
        }
예제 #7
0
파일: tests.cpp 프로젝트: iamfd/fensterchen
#include <catch.hpp>
#include <color.hpp>
#include <point2d.hpp>
#include <circle.hpp>
#include <rectangle.hpp>
#define _USE_MATH_DEFINES
#include <cmath>

int main(int argc, char *argv[])
{
  return Catch::Session().run(argc, argv);
}

TEST_CASE("describe_test", "[test]"){
	Point2d punkt{0.5, 1.0};
	REQUIRE(punkt.getX() == Approx(0.5));
	REQUIRE(punkt.getY() == Approx(1.0));
	Point2d punkt2{1.0, 1.0};
	punkt2.translate(-2.0, -2.0);
	REQUIRE(punkt2.getX() == Approx(-1.0));
	REQUIRE(punkt2.getY() == Approx(-1.0));
	punkt2.rotate(M_PI);
	REQUIRE(punkt2.getX() == Approx(1.0));
	REQUIRE(punkt2.getY() == Approx(1.0));


	Color farbe{1.0, 0.0, 0.0};
	Circle kreis{punkt, 2.0, farbe};
	REQUIRE(kreis.getRadius() == Approx(2.0));
	REQUIRE(kreis.circumference() == Approx(12.56637));
	REQUIRE(kreis.getColor().r == Approx(1.0));
예제 #8
0
#include "catch.hpp"

#include "math/interpolate.hpp"

extern int testNumber;

SCENARIO("The histogram interpolation function will return a correct result",
         "[math], [interpolate], [histogram]"){
  GIVEN("Some simple interpolation problems"){
    WHEN("computed using the histogram function"){
      THEN("the correct value will be returned"){
        LOG(INFO) << "Test " << ++testNumber
                  << ": [histogram] No Errors Expected";
        REQUIRE(0.0 == Approx( math::interpolate::histogram(0.5,
                                                            0.0, 1.0,
                                                            0.0, 1.0) ));
        LOG(INFO) << "Test " << ++testNumber
                  << ": [histogram] No Errors Expected";
        REQUIRE(0.0 == Approx( math::interpolate::histogram(0.5,
                                                            0.5, 1.0,
                                                            0.0, 1.0) ));
        LOG(INFO) << "Test " << ++testNumber
                  << ": [histogram] No Errors Expected";
        REQUIRE(0.0 == Approx( math::interpolate::histogram(1.0,
                                                            0.0, 1.0,
                                                            0.0, 1.0) ));
        LOG(INFO) << "Test " << ++testNumber
                  << ": [histogram] No Errors Expected";
        REQUIRE(1.0 == Approx( math::interpolate::histogram(0.5,
                                                            0.0, 1.0,
                                                            1.0, 0.0) ));
예제 #9
0
bool Approx(pMat3_t M1) {// compares to identity -- element by element
  return(Approx(M1->val[0][0], 1.0) && Approx(M1->val[1][1], 1.0) && Approx(M1->val[2][2], 1.0) &&
	 Approx(M1->val[0][1]) && Approx(M1->val[1][2]) && Approx(M1->val[2][0]) &&
	 Approx(M1->val[0][2]) && Approx(M1->val[1][0]) && Approx(M1->val[2][1]));
}
예제 #10
0
 static Approx custom() {
     return Approx( 0 );
 }
예제 #11
0
bool Approx(pVec3_t V1, pVec3_t V2){ return(Approx(Distance(V1, V2)));}
예제 #12
0
bool Approx(pVec3_t V1) { return(Approx(Length(V1)));}
예제 #13
0
bool Approx(double V1, double V2){ return(Approx(V1-V2));}
예제 #14
0
        Eigen::Vector3d probe = Eigen::Vector3d::Random();
        Eigen::Vector3d probeNormal = probe + Eigen::Vector3d::Random();
        probeNormal.normalize();
        Eigen::Array4d result = analyticAnisotropicLiquid(epsilon, euler, sourceNormal, source, probeNormal, probe);

        /*! \class AnisotropicLiquid
         *  \test \b AnisotropicLiquidTest_numerical tests the numerical evaluation of the AnisotropicLiquid Green's function against analytical result
         */
        WHEN("the derivatives are evaluated numerically")
        {
            AnisotropicLiquid<Numerical, CollocationIntegrator> gf(epsilon, euler);
            THEN("the value of the Green's function is")
            {
                double value = result(0);
                double gf_value = gf.kernelS(source, probe);
                REQUIRE(value == Approx(gf_value));
            }
            AND_THEN("the value of the Green's function directional derivative wrt the probe point is")
            {
                double derProbe = result(1);
                double gf_derProbe = gf.derivativeProbe(probeNormal, source, probe);
                REQUIRE(derProbe == Approx(gf_derProbe));
            }
            AND_THEN("the value of the Green's function directional derivative wrt the source point is")
            {
                double derSource = result(2);
                double gf_derSource = gf.derivativeSource(sourceNormal, source, probe);
                REQUIRE(derSource == Approx(gf_derSource));
            }
        }
예제 #15
0
    Eigen::Vector3d source = Eigen::Vector3d::Random();
    Eigen::Vector3d sourceNormal = source + Eigen::Vector3d::Random();
    sourceNormal.normalize();
    Eigen::Vector3d probe = Eigen::Vector3d::Random();
    Eigen::Vector3d probeNormal = probe + Eigen::Vector3d::Random();
    probeNormal.normalize();
    Eigen::Array4d result = analyticUniformDielectric(epsilon, sourceNormal, source, probeNormal, probe);
    /*! \class UniformDielectric
     *  \test \b UniformDielectricTest_numerical tests the numerical evaluation of the UniformDielectric Green's function against analytical result
     */
    SECTION("Numerical derivative")
    {
        UniformDielectric<Numerical, CollocationIntegrator> gf(epsilon);
        double value = result(0);
        double gf_value = gf.kernelS(source, probe);
        REQUIRE(value == Approx(gf_value));

        double derProbe = result(1);
        double gf_derProbe = gf.derivativeProbe(probeNormal, source, probe);
        REQUIRE(derProbe == Approx(gf_derProbe));

        double derSource = result(2);
        double gf_derSource = gf.derivativeSource(sourceNormal, source, probe);
        REQUIRE(derSource == Approx(gf_derSource));
    }

    /*! \class UniformDielectric
     *  \test \b UniformDielectricTest_directional_AD tests the automatic evaluation (directional derivative only)
     *  of the UniformDielectric Green's function against analytical result
     */
    SECTION("Directional derivative via AD")
예제 #16
0
// Catch
#include <catch.hpp>
#include "../../catchHelper.hpp"

SCENARIO("bbob::RastriginFunction.getObjectiveFunctions", "[bbob::RastriginFunction][bbob::RastriginFunction.getObjectiveFunctions]") {
  GIVEN("A parameter") {
    THEN("Return its objective value") {
      mant::bbob::RastriginFunction optimisationProblem(3);

      CHECK(optimisationProblem.getObjectiveFunctions().at(0).first({1.0, -2.0, 3.0}) == Approx(235.3181057912));
    }
  }

  THEN("Return the objective function name") {
    mant::bbob::RastriginFunction optimisationProblem(2);

    CHECK(optimisationProblem.getObjectiveFunctions().size() == 1);
    CHECK(optimisationProblem.getObjectiveFunctions().at(0).second == "BBOB Rastrigin Function (f3)");
  }
}
    REQUIRE( potencia(2,2)    == 4 );
    REQUIRE( potencia(3,2)    == 9 );
    REQUIRE( potencia(2,10)   == 1024 );
    REQUIRE( potencia(10,2)   == 100 );
    REQUIRE( potencia(10,0)   == 1 );
    REQUIRE( potencia(10,1)   == 10 );
    REQUIRE( potencia(10,2)   == 100 );
    REQUIRE( potencia(10,3)   == 1000 );
    REQUIRE( potencia(10,4)   == 10000 );
    REQUIRE( potencia(10,5)   == 100000 );
    REQUIRE( potencia(10,6)   == 1000000 );
    REQUIRE( potencia(-1,2)   == 1 );
    REQUIRE( potencia(-5,2)   == 25 );
    REQUIRE( potencia(-1,0)   == 1 );
    REQUIRE( potencia(-1.1,0) == 1 );
    REQUIRE( potencia(-0.1,0) == 1 );
    REQUIRE( potencia(0.1,0)  == 1 );
    REQUIRE( potencia(2.25,2) == Approx(5.0625) );
    REQUIRE( potencia(-5,-2)  == Approx(0.04) );
    REQUIRE( potencia(1.5,3)  == Approx(3.375) );
    REQUIRE( potencia(10,-6)  == Approx(0.000001) );
    REQUIRE( potencia(10,-5)  == Approx(0.00001) );
    REQUIRE( potencia(10,-4)  == Approx(0.0001) );
    REQUIRE( potencia(10,-3)  == Approx(0.001) );
    REQUIRE( potencia(10,-2)  == Approx(0.01) );
    REQUIRE( potencia(10,-1)  == Approx(0.1) );




}
예제 #18
0
#include <cml/matrix/dynamic.h>
#include <cml/matrix/external.h>
#include <cml/matrix/types.h>

/* Testing headers: */
#include "catch_runner.h"


CATCH_TEST_CASE("fixed, inverse_assign_2x2")
{
  cml::matrix22d M(
    1., 2.,
    3., 4.
    );
  M.inverse();
  CATCH_CHECK(M(0,0) == Approx(-2.0).epsilon(1e-12));
  CATCH_CHECK(M(0,1) == Approx( 1.0).epsilon(1e-12));
  CATCH_CHECK(M(1,0) == Approx( 1.5).epsilon(1e-12));
  CATCH_CHECK(M(1,1) == Approx(-0.5).epsilon(1e-12));
}

CATCH_TEST_CASE("fixed, inverse_assign_3x3")
{
  cml::matrix33d M(
    1.,  2.,  3.,
    1.,  4.,  9.,
    1., 16., 25.
    );
  M.inverse();

  auto expected = cml::matrix33d(
예제 #19
0
#include "shape.hpp"
#include "cylinder.hpp"
#include "material.hpp"
#include "composite.hpp"
 
#include <catch.hpp>
#include <glm/glm.hpp>
#include <glm/gtx/intersect.hpp>
#include <glm/vec3.hpp>
#include <memory>


 
TEST_CASE("Boxmin","[minimum]"){
    Box b{};
    REQUIRE(Approx(0.0f) == b.getmin().x);
    REQUIRE(Approx(0.0f) == b.getmin().y);
    REQUIRE(Approx(0.0f) == b.getmin().z);
 
   
    glm::vec3 max{1.5f,5.6f,2.3f};
    glm::vec3 min{2.0f,3.3f,4.0f};
   
    Box b1{min, max};
    REQUIRE(Approx(2.0f) == b1.getmin().x);
    REQUIRE(Approx(3.3f) == b1.getmin().y);
    REQUIRE(Approx(4.0f) == b1.getmin().z);
}
 
TEST_CASE("BoxSetsMin","[setminimum]"){
 
예제 #20
0
파일: usLDAPProp.cpp 프로젝트: zomboir/MITK
LDAPPropExpr LDAPProp::Approx(const us::Any& any) const
{
  return Approx(any.ToString());
}
예제 #21
0
};

// The "failing" tests all use the CHECK macro, which continues if the specific test fails.
// This allows us to see all results, even if an earlier check fails

// Equality tests
TEST_CASE( "Equality checks that should succeed", "" )
{

    TestDef td;
    td + "hello" + "hello";

    TestData data;

    REQUIRE( data.int_seven == 7 );
    REQUIRE( data.float_nine_point_one == Approx( 9.1f ) );
    REQUIRE( data.double_pi == Approx( 3.1415926535 ) );
    REQUIRE( data.str_hello == "hello" );
    REQUIRE( "hello" == data.str_hello );
    REQUIRE( data.str_hello.size() == 5 );

    double x = 1.1 + 0.1 + 0.1;
    REQUIRE( x == Approx( 1.3 ) );
}

TEST_CASE( "Equality checks that should fail", "[.][failing][!mayfail]" )
{
    TestData data;

    CHECK( data.int_seven == 6 );
    CHECK( data.int_seven == 8 );