diff --git a/server/src/Tests.cpp b/server/src/Tests.cpp index 355fdced1..c35140f2f 100644 --- a/server/src/Tests.cpp +++ b/server/src/Tests.cpp @@ -33,6 +33,13 @@ Tests::MethodDescription::MethodDescription() { Tests::ERROR_SUITE_NAME, std::string() }}, modifiers{} { } +static const std::unordered_map FPSpecialValuesMappings = { + {"nan", "NAN"}, + {"-nan", "-NAN"}, + {"inf", "INFINITY"}, + {"-inf", "-INFINITY"} +}; + static std::string makeDecimalConstant(std::string value, const std::string &typeName) { if (typeName == "long") { if (value == INT64_MIN_STRING) { @@ -55,16 +62,16 @@ static std::string makeDecimalConstant(std::string value, const std::string &typ if (typeName == "unsigned long long") { return value + "ULL"; } + if (typeName == "long double") { + if ( FPSpecialValuesMappings.find(value) == FPSpecialValuesMappings.end()) { + // we need it to avoid overflow in exponent for const like 1.18973e+4932L + // BUT! Skip the NAN/INFINITY values + return value + "L"; + } + } return value; } -static const std::unordered_map FPSpecialValuesMappings = { - {"nan", "NAN"}, - {"-nan", "-NAN"}, - {"inf", "INFINITY"}, - {"-inf", "-INFINITY"} -}; - namespace tests { /** * The function checks for presence of argument in values as it is diff --git a/server/src/clang-utils/SourceToHeaderRewriter.cpp b/server/src/clang-utils/SourceToHeaderRewriter.cpp index ac7eaf5e0..91630d956 100644 --- a/server/src/clang-utils/SourceToHeaderRewriter.cpp +++ b/server/src/clang-utils/SourceToHeaderRewriter.cpp @@ -71,6 +71,7 @@ std::string SourceToHeaderRewriter::generateTestHeader(const fs::path &sourceFil sourceFileToInclude = fs::canonical(test.sourceFilePath.parent_path() / test.mainHeader.value().path); } + sourceFileToInclude = fs::relative(sourceFilePath, test.testHeaderFilePath.parent_path()); return StringUtils::stringFormat("#define main main__\n\n" "#include \"%s\"\n\n", sourceFileToInclude); diff --git a/server/src/printers/TestsPrinter.cpp b/server/src/printers/TestsPrinter.cpp index 47545e9f7..711e2b4e9 100644 --- a/server/src/printers/TestsPrinter.cpp +++ b/server/src/printers/TestsPrinter.cpp @@ -48,8 +48,6 @@ void TestsPrinter::joinToFinalCode(Tests &tests, const fs::path& generatedHeader genHeaders(tests, generatedHeaderPath); ss << "namespace " << PrinterUtils::TEST_NAMESPACE << " {\n"; - strDeclareAbsError(PrinterUtils::ABS_ERROR); - for (const auto &commentBlock : tests.commentBlocks) { strComment(commentBlock) << NL; } diff --git a/server/src/utils/PrinterUtils.cpp b/server/src/utils/PrinterUtils.cpp index 2907b4f05..ebb851fb9 100644 --- a/server/src/utils/PrinterUtils.cpp +++ b/server/src/utils/PrinterUtils.cpp @@ -36,8 +36,9 @@ namespace PrinterUtils { const std::string EXPECTED = "expected"; const std::string ACTUAL = "actual"; - const std::string ABS_ERROR = "utbot_abs_error"; const std::string EXPECT_ = "EXPECT_"; + const std::string EXPECT_FLOAT_EQ = "EXPECT_FLOAT_EQ"; + const std::string EXPECT_DOUBLE_EQ = "EXPECT_DOUBLE_EQ"; const std::string EQ = "EQ"; std::string convertToBytesFunctionName(const std::string &typeName) { diff --git a/server/src/utils/PrinterUtils.h b/server/src/utils/PrinterUtils.h index 6d28f848b..106525cbe 100644 --- a/server/src/utils/PrinterUtils.h +++ b/server/src/utils/PrinterUtils.h @@ -23,12 +23,15 @@ namespace PrinterUtils { extern const std::string KLEE_PATH_FLAG; extern const std::string KLEE_PATH_FLAG_SYMBOLIC; extern const std::string EQ_OPERATOR; + extern const std::string ASSIGN_OPERATOR; extern const std::string TAB; extern const std::string EXPECTED; + extern const std::string EXPECT_FLOAT_EQ; + extern const std::string EXPECT_DOUBLE_EQ; + extern const std::string ACTUAL; - extern const std::string ABS_ERROR; extern const std::string EXPECT_; extern const std::string EQ; diff --git a/server/src/visitors/AssertsVisitor.cpp b/server/src/visitors/AssertsVisitor.cpp index 6bf148b6e..291a27fb7 100644 --- a/server/src/visitors/AssertsVisitor.cpp +++ b/server/src/visitors/AssertsVisitor.cpp @@ -30,13 +30,16 @@ namespace visitor { AssertsVisitor::FunctionSignature AssertsVisitor::processExpect( const types::Type &type, const std::string >estMacro, std::vector &&args) { - bool changePredicate = types::TypesHandler::isFloatingPointType(type) && (gtestMacro == PrinterUtils::EQ); - std::string targetMacro = gtestMacro; - if (changePredicate) { - targetMacro = "NEAR"; - args.emplace_back(PrinterUtils::ABS_ERROR); + std::string macroName = PrinterUtils::EXPECT_ + gtestMacro; + if (types::TypesHandler::isFloatingPointType(type) && gtestMacro == PrinterUtils::EQ) { + const types::TypeName &typeName = type.baseType(); + if (typeName == "float") { + macroName = PrinterUtils::EXPECT_FLOAT_EQ; + } else if (typeName == "double" || typeName == "long double") { + macroName = PrinterUtils::EXPECT_DOUBLE_EQ; + } } - return VerboseAssertsVisitor::FunctionSignature{ PrinterUtils::EXPECT_ + targetMacro, std::move(args) }; + return VerboseAssertsVisitor::FunctionSignature{ macroName, std::move(args) }; } std::string AssertsVisitor::getDecorateActualVarName(const std::string &access) { diff --git a/server/test/framework/Syntax_Tests.cpp b/server/test/framework/Syntax_Tests.cpp index dab0f5cd1..0c1019f3c 100644 --- a/server/test/framework/Syntax_Tests.cpp +++ b/server/test/framework/Syntax_Tests.cpp @@ -1693,12 +1693,18 @@ namespace { ASSERT_TRUE(status.ok()) << status.error_message(); + + printer::TestsPrinter testsPrinter(nullptr, utbot::Language::C); + const auto &tests = testGen.tests.at(floats_special_c) + .methods.begin().value().testCases; checkTestCasePredicates( - testGen.tests.at(floats_special_c).methods.begin().value().testCases, - std::vector( - {[](const tests::Tests::MethodTestCase &testCase) { + tests, std::vector( + { [](const tests::Tests::MethodTestCase &testCase) { return testCase.paramValues[0].view->getEntryValue(nullptr) == "NAN"; - }})); + }, + [](const tests::Tests::MethodTestCase &testCase) { + return testCase.paramValues[0].view->getEntryValue(nullptr) == "0.000000e+00L"; + } })); } TEST_F(Syntax_Test, Floats_Special_Values_Inf) { diff --git a/server/test/suites/coverage/pregenerated_tests/dependent_functions_dot_c_test.cpp b/server/test/suites/coverage/pregenerated_tests/dependent_functions_dot_c_test.cpp index ee9d67b9c..dee9610f7 100644 --- a/server/test/suites/coverage/pregenerated_tests/dependent_functions_dot_c_test.cpp +++ b/server/test/suites/coverage/pregenerated_tests/dependent_functions_dot_c_test.cpp @@ -2,7 +2,6 @@ #include "gtest/gtest.h" namespace UTBot { - static const float utbot_abs_error = 1e-6; diff --git a/server/test/suites/coverage/pregenerated_tests/simple_class_dot_cpp_test.cpp b/server/test/suites/coverage/pregenerated_tests/simple_class_dot_cpp_test.cpp index 8d149e130..959fc976a 100644 --- a/server/test/suites/coverage/pregenerated_tests/simple_class_dot_cpp_test.cpp +++ b/server/test/suites/coverage/pregenerated_tests/simple_class_dot_cpp_test.cpp @@ -7,7 +7,6 @@ ACCESS_PRIVATE_FIELD(Point_2d, int, x); namespace UTBot { - static const float utbot_abs_error = 1e-6; @@ -67,7 +66,7 @@ namespace UTBot { { Point_2d Point_2d_obj; double actual = Point_2d_obj.get_dist_to_zero(); - EXPECT_NEAR(-0.000000e+00, actual, utbot_abs_error); + EXPECT_DOUBLE_EQ(-0.000000e+00, actual); } @@ -106,7 +105,7 @@ namespace UTBot { class Point_2d lhs = {0, 0}; class Point_2d rhs = {0, 0}; double actual = get_dist(lhs, rhs); - EXPECT_NEAR(0.000000e+00, actual, utbot_abs_error); + EXPECT_DOUBLE_EQ(0.000000e+00, actual); class Point_2d expected_lhs = {0, 0}; EXPECT_EQ(access_private::x(expected_lhs), access_private::x(lhs)); EXPECT_EQ(expected_lhs.y, lhs.y); diff --git a/server/test/suites/syntax/floats_special.c b/server/test/suites/syntax/floats_special.c index 07996773c..f7c915b61 100644 --- a/server/test/suites/syntax/floats_special.c +++ b/server/test/suites/syntax/floats_special.c @@ -9,7 +9,7 @@ int is_nanf(float x) { } } -int is_nan(double x) { +int is_nan(long double x) { if (x != x) { return 1; } else { diff --git a/server/test/suites/syntax/floats_special.h b/server/test/suites/syntax/floats_special.h index 33719299f..32c7e7943 100644 --- a/server/test/suites/syntax/floats_special.h +++ b/server/test/suites/syntax/floats_special.h @@ -2,7 +2,7 @@ #define UNITTESTBOT_FLOATS_SPECIAL_H int is_nanf(float x); -int is_nan(double x); +int is_nan(long double x); int is_inf(float x); #endif //UNITTESTBOT_FLOATS_SPECIAL_H