Files
karl/test/test_function_generator.cpp
T

67 lines
2.2 KiB
C++
Executable File

#include "catch.hpp"
#include "generators/function_generator.h"
#include "simulation/parameter.h"
TEST_CASE("Function Generator", "[FunctionGenerator]") {
SECTION("function1D") {
std::string filename = "simulation_config/test_parameter.json";
Parameter p(filename);
GIVEN("An parameter file and a path to a piecewise linear function") {
json_t* obj = p.jsonObjectFromBase({"Functions", "1Dto1D", "f1"});
THEN("the correct function is created") {
std::function<double(double)> pw = generator::function1D(obj);
REQUIRE(pw(-1) == 5E-4);
REQUIRE(pw(3) == 0.02);
}
}
GIVEN("An parameter file and a path to a constant function") {
json_t* obj = p.jsonObjectFromBase({"Functions", "1Dto1D", "f2"});
THEN("the correct function is created") {
std::function<double(double)> co = generator::function1D(obj);
REQUIRE(co(-1) == 1.);
REQUIRE(co(3) == 1.);
}
}
GIVEN("An parameter file and a path to a product function") {
json_t* obj = p.jsonObjectFromBase({"Functions", "1Dto1D", "f3"});
THEN("the correct function is created") {
std::function<double(double)> product = generator::function1D(obj);
REQUIRE(product(-1) == 6);
REQUIRE(product(3) == 6);
}
}
}
SECTION("function3D") {
std::string filename = "simulation_config/test_parameter.json";
Parameter p(filename);
GIVEN("An parameter file and a path to a Constant function") {
json_t* obj = p.jsonObjectFromBase({"Functions", "3dto1D", "f1"});
THEN("the correct function is created") {
std::function<double(double, double, double)> co =
generator::function3D(obj);
REQUIRE(co(-1., 1., 0.) == 2.);
REQUIRE(co(0., 2., -1.) == 2);
}
}
GIVEN("An parameter file and a path to a Product function") {
json_t* obj = p.jsonObjectFromBase({"Functions", "3dto1D", "f2"});
THEN("the correct function is created") {
std::function<double(double, double, double)> product =
generator::function3D(obj);
REQUIRE(product(-1., 1., 0.) == 20E-4);
REQUIRE(product(0., 2., 3.) == 0.08);
}
}
}
}