Added tests for trim_zeroes()

This commit is contained in:
Joseph Lenox 2018-07-04 16:59:27 -05:00 committed by Joseph Lenox
parent 9f83da9519
commit d18b975195
2 changed files with 30 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,27 @@
#include <catch.hpp>
#include "misc_ui.hpp"
#include <string>
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);
}
}