From d18b97519560fbbabc28b118a7a16a1b7c998e12 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 4 Jul 2018 16:59:27 -0500 Subject: [PATCH] Added tests for trim_zeroes() --- src/CMakeLists.txt | 3 +++ src/test/GUI/test_misc_ui.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/test/GUI/test_misc_ui.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 08bbed83c..e08eaa6ef 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -182,6 +182,8 @@ set(UI_TEST_SOURCES ${GUI_TESTDIR}/test_field_choice.cpp ${GUI_TESTDIR}/test_field_numchoice.cpp ${GUI_TESTDIR}/test_field_point.cpp + ${GUI_TESTDIR}/test_field_point3.cpp + ${GUI_TESTDIR}/test_misc_ui.cpp ) set(SLIC3R_TEST_SOURCES ${TESTDIR}/test_harness.cpp @@ -263,6 +265,7 @@ IF(wxWidgets_FOUND) ${GUI_LIBDIR}/OptionsGroup/UI_NumChoice.cpp ${GUI_LIBDIR}/OptionsGroup/UI_Choice.cpp ${GUI_LIBDIR}/OptionsGroup/UI_Point.cpp + ${GUI_LIBDIR}/OptionsGroup/UI_Point3.cpp ) target_compile_features(slic3r_gui PUBLIC cxx_std_14) #only build GUI lib if building with wx diff --git a/src/test/GUI/test_misc_ui.cpp b/src/test/GUI/test_misc_ui.cpp new file mode 100644 index 000000000..46a1da0f9 --- /dev/null +++ b/src/test/GUI/test_misc_ui.cpp @@ -0,0 +1,27 @@ +#include +#include "misc_ui.hpp" +#include + +using namespace std::string_literals; +using namespace Slic3r::GUI; + +SCENARIO( "trim_zeroes leaves parsable numbers.") { + auto n192 {"19.200000000"s}; + auto n00 {"0.0"s}; + auto n0 {"0."s}; + REQUIRE(trim_zeroes(n00) == "0.0"s); + REQUIRE(trim_zeroes(n0) == "0.0"s); + REQUIRE(trim_zeroes(n192) == "19.2"s); +} + +SCENARIO ( "trim_zeroes doesn't reduce precision.") { + GIVEN( "A number with a long string of zeroes and a 0") { + auto n12 {"19.200000002"s}; + auto n120 {"19.2000000020"s}; + auto n1200 {"19.20000000200"s}; + + REQUIRE(trim_zeroes(n12) == "19.200000002"s); + REQUIRE(trim_zeroes(n120) == "19.200000002"s); + REQUIRE(trim_zeroes(n1200) == "19.200000002"s); + } +}