Skip to content

Commit 2e76a17

Browse files
committed
iox-#2055 Add tests of decimal notation
Signed-off-by: Dennis Liu <[email protected]>
1 parent 26e351d commit 2e76a17

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

iceoryx_hoofs/test/moduletests/test_utility_convert.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <cmath>
2525
#include <cstdint>
26+
#include <tuple>
2627
namespace
2728
{
2829
using namespace ::testing;
@@ -813,6 +814,81 @@ TEST_F(convert_test, fromString_LongDouble_EdgeCase_Inf_Success)
813814
}
814815
}
815816

817+
TEST_F(convert_test, fromString_Float_EdgeCase_ZeroDecimalNotation_Success)
818+
{
819+
::testing::Test::RecordProperty("TEST_ID", "4ac285f9-e107-4d74-8aca-5d87032794db");
820+
821+
std::vector<std::string> decimal_notation_vec = {"0", "-0", ".0", "-.0", "0.0", "-0.0", "0.", "-0."};
822+
823+
for (const auto& v : decimal_notation_vec)
824+
{
825+
auto decimal_ret = iox::convert::from_string<float>(v.c_str());
826+
ASSERT_THAT(decimal_ret.has_value(), Eq(true));
827+
ASSERT_THAT(decimal_ret.value(), Eq(0.0F));
828+
}
829+
}
830+
831+
TEST_F(convert_test, fromString_Double_EdgeCase_ZeroDecimalNotation_Success)
832+
{
833+
::testing::Test::RecordProperty("TEST_ID", "98938eaa-c472-4338-a153-5c2de9eb4940");
834+
835+
std::vector<std::string> decimal_notation_vec = {"0", "-0", ".0", "-.0", "0.0", "-0.0", "0.", "-0."};
836+
837+
for (const auto& v : decimal_notation_vec)
838+
{
839+
auto decimal_ret = iox::convert::from_string<double>(v.c_str());
840+
ASSERT_THAT(decimal_ret.has_value(), Eq(true));
841+
ASSERT_THAT(decimal_ret.value(), Eq(0.0));
842+
}
843+
}
844+
845+
TEST_F(convert_test, fromString_LongDouble_EdgeCase_ZeroDecimalNotation_Success)
846+
{
847+
::testing::Test::RecordProperty("TEST_ID", "49fc0812-47c0-4815-8a15-a94a81493ea0");
848+
849+
std::vector<std::string> decimal_notation_vec = {"0", "-0", ".0", "-.0", "0.0", "-0.0", "0.", "-0."};
850+
851+
for (const auto& v : decimal_notation_vec)
852+
{
853+
auto decimal_ret = iox::convert::from_string<long double>(v.c_str());
854+
ASSERT_THAT(decimal_ret.has_value(), Eq(true));
855+
ASSERT_THAT(decimal_ret.value(), Eq(0.0L));
856+
}
857+
}
858+
859+
TEST_F(convert_test, fromString_Float_EdgeCase_OtherDecimalNotation_Success)
860+
{
861+
::testing::Test::RecordProperty("TEST_ID", "278ff5af-28bd-4c11-839e-160e148c5a64");
862+
863+
std::string source = ".1";
864+
865+
auto decimal_ret = iox::convert::from_string<float>(source.c_str());
866+
ASSERT_THAT(decimal_ret.has_value(), Eq(true));
867+
ASSERT_THAT(decimal_ret.value(), Eq(0.1F));
868+
}
869+
870+
TEST_F(convert_test, fromString_Double_EdgeCase_OtherDecimalNotation_Success)
871+
{
872+
::testing::Test::RecordProperty("TEST_ID", "a8539f9a-1c7a-4d81-9a88-ef8a6630f065");
873+
874+
std::string source = ".1";
875+
876+
auto decimal_ret = iox::convert::from_string<double>(source.c_str());
877+
ASSERT_THAT(decimal_ret.has_value(), Eq(true));
878+
ASSERT_THAT(decimal_ret.value(), Eq(0.1));
879+
}
880+
881+
TEST_F(convert_test, fromString_LongDouble_EdgeCase_OtherDecimalNotation_Success)
882+
{
883+
::testing::Test::RecordProperty("TEST_ID", "d71ec687-aaab-45d5-aee5-2ec9a51602d0");
884+
885+
std::string source = ".1";
886+
887+
auto decimal_ret = iox::convert::from_string<long double>(source.c_str());
888+
ASSERT_THAT(decimal_ret.has_value(), Eq(true));
889+
ASSERT_THAT(decimal_ret.value(), Eq(0.1L));
890+
}
891+
816892
/// SPECIAL FLOATING POINT TYPE EDGE CASES END
817893

818894
TEST_F(convert_test, fromString_ioxString)

0 commit comments

Comments
 (0)