diff --git a/tests/test_CFunctionProcessor.cpp b/tests/test_CFunctionProcessor.cpp index 23034e555b0f5f90fe61007e9ba600af1a13a590..0a0a83230a3c6a6dde5cdec9b88a686e978ad0dd 100644 --- a/tests/test_CFunctionProcessor.cpp +++ b/tests/test_CFunctionProcessor.cpp @@ -12,17 +12,9 @@ #include <ASTNodeExpressionBuilder.hpp> -#include <ASTNodeAffectationExpressionBuilder.hpp> - #include <ASTSymbolTableBuilder.hpp> -#include <ASTPrinter.hpp> - -#include <Demangle.hpp> - -#include <PEGGrammar.hpp> - -#include <sstream> +#include <CMathModule.hpp> #define CHECK_CFUNCTION_EVALUATION_RESULT(data, variable_name, expected_value) \ { \ @@ -74,6 +66,15 @@ R x = sqrt(4); CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::sqrt(4l)}); } + { // abs + tested_function_set.insert("abs"); + std::string_view data = R"( +import math; +R x = abs(-3.4); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::abs(-3.4)}); + } + { // sin tested_function_set.insert("sin"); std::string_view data = R"( @@ -82,5 +83,223 @@ R x = sin(1.3); )"; CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::sin(1.3)}); } + + { // cos + tested_function_set.insert("cos"); + std::string_view data = R"( +import math; +R x = cos(1.3); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::cos(1.3)}); + } + + { // tan + tested_function_set.insert("tan"); + std::string_view data = R"( +import math; +R x = tan(1.3); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::tan(1.3)}); + } + + { // asin + tested_function_set.insert("asin"); + std::string_view data = R"( +import math; +R x = asin(0.7); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::asin(0.7)}); + } + + { // acos + tested_function_set.insert("acos"); + std::string_view data = R"( +import math; +R x = acos(0.7); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::acos(0.7)}); + } + + { // atan + tested_function_set.insert("atan"); + std::string_view data = R"( +import math; +R x = atan(0.7); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::atan(0.7)}); + } + + { // atan2 + tested_function_set.insert("atan2"); + std::string_view data = R"( +import math; +R x = atan2(0.7, 0.4); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::atan2(0.7, 0.4)}); + } + + { // sinh + tested_function_set.insert("sinh"); + std::string_view data = R"( +import math; +R x = sinh(0.6); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::sinh(0.6)}); + } + + { // cosh + tested_function_set.insert("cosh"); + std::string_view data = R"( +import math; +R x = cosh(1.7); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::cosh(1.7)}); + } + + { // tanh + tested_function_set.insert("tanh"); + std::string_view data = R"( +import math; +R x = tanh(0.6); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::tanh(0.6)}); + } + + { // asinh + tested_function_set.insert("asinh"); + std::string_view data = R"( +import math; +R x = asinh(0.6); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::asinh(0.6)}); + } + + { // acosh + tested_function_set.insert("acosh"); + std::string_view data = R"( +import math; +R x = acosh(1.7); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::acosh(1.7)}); + } + + { // tanh + tested_function_set.insert("atanh"); + std::string_view data = R"( +import math; +R x = atanh(0.6); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::atanh(0.6)}); + } + + { // exp + tested_function_set.insert("exp"); + std::string_view data = R"( +import math; +R x = exp(1.7); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::exp(1.7)}); + } + + { // log + tested_function_set.insert("log"); + std::string_view data = R"( +import math; +R x = log(1.6); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::log(1.6)}); + } + + { // pow + tested_function_set.insert("pow"); + std::string_view data = R"( +import math; +R x = pow(1.6, 2.3); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{std::pow(1.6, 2.3)}); + } + + { // exp + tested_function_set.insert("nearbyint"); + std::string_view data = R"( +import math; +R x = nearbyint(1.7); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{2}); + } + + { // ceil + tested_function_set.insert("ceil"); + std::string_view data = R"( +import math; +R x = ceil(-1.2); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{-1}); + } + + { // floor + tested_function_set.insert("floor"); + std::string_view data = R"( +import math; +R x = floor(-1.2); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{-2}); + } + + { // trunc + tested_function_set.insert("trunc"); + std::string_view data = R"( +import math; +R x = trunc(-0.2) + trunc(0.7); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{0}); + } + + { // round + tested_function_set.insert("round"); + std::string_view data = R"( +import math; +R x = round(-1.2); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{-1}); + } + + { // lround + tested_function_set.insert("lround"); + std::string_view data = R"( +import math; +Z i = lround(-1.2); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "i", int64_t{-1}); + } + + { // rint + tested_function_set.insert("rint"); + std::string_view data = R"( +import math; +R x = rint(-1.2); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "x", double{-1}); + } + + { // lrint + tested_function_set.insert("lrint"); + std::string_view data = R"( +import math; +Z i = lrint(-1.2); +)"; + CHECK_CFUNCTION_EVALUATION_RESULT(data, "i", int64_t{-1}); + } + + CMathModule math_module; + + bool missing_test = false; + for (auto [cmath_name, c_function] : math_module.getNameCFunctionsMap()) { + if (tested_function_set.find(cmath_name) == tested_function_set.end()) { + UNSCOPED_INFO("function '" << cmath_name << "' is NOT tested"); + missing_test = true; + } + } + REQUIRE_FALSE(missing_test); } }