Skip to content

Commit

Permalink
Remove test value initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland committed May 22, 2023
1 parent 4894a34 commit 78cd508
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions test/from_chars_float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
template <typename T>
void spot_value(const std::string& buffer, T expected_value, boost::charconv::chars_format fmt = boost::charconv::chars_format::general)
{
T v = 0;
T v;
auto r = boost::charconv::from_chars(buffer.c_str(), buffer.c_str() + std::strlen(buffer.c_str()), v, fmt);
BOOST_TEST(r.ec == std::errc());
if (!BOOST_TEST_EQ(v, expected_value))
Expand Down Expand Up @@ -55,13 +55,13 @@ template <typename T>
void simple_integer_test()
{
const char* buffer1 = "12";
T v1 = 0;
T v1;
auto r1 = boost::charconv::from_chars(buffer1, buffer1 + std::strlen(buffer1), v1);
BOOST_TEST(r1.ec == std::errc());
BOOST_TEST_EQ(v1, static_cast<T>(12));

const char* buffer2 = "1200";
T v2 = 0;
T v2;
auto r2 = boost::charconv::from_chars(buffer2, buffer2 + std::strlen(buffer2), v2);
BOOST_TEST(r2.ec == std::errc());
BOOST_TEST_EQ(v2, static_cast<T>(1200));
Expand All @@ -71,7 +71,7 @@ template <typename T>
void simple_hex_integer_test()
{
const char* buffer1 = "-2a";
T v1 = 0;
T v1;
auto r1 = boost::charconv::from_chars(buffer1, buffer1 + std::strlen(buffer1), v1, boost::charconv::chars_format::hex);
BOOST_TEST(r1.ec == std::errc());
BOOST_TEST_EQ(v1, static_cast<T>(-42));
Expand All @@ -81,25 +81,25 @@ template <typename T>
void simple_scientific_test()
{
const char* buffer1 = "1e1";
T v1 = 0;
T v1;
auto r1 = boost::charconv::from_chars(buffer1, buffer1 + std::strlen(buffer1), v1);
BOOST_TEST(r1.ec == std::errc());
BOOST_TEST_EQ(v1, static_cast<T>(1e1L));

const char* buffer2 = "123456789e10";
T v2 = 0;
T v2;
auto r2 = boost::charconv::from_chars(buffer2, buffer2 + std::strlen(buffer2), v2);
BOOST_TEST(r2.ec == std::errc());
BOOST_TEST_EQ(v2, static_cast<T>(123456789e10L));

const char* buffer3 = "1.23456789e+10";
T v3 = 0;
T v3;
auto r3 = boost::charconv::from_chars(buffer3, buffer3 + std::strlen(buffer3), v3);
BOOST_TEST(r3.ec == std::errc());
BOOST_TEST_EQ(v3, static_cast<T>(1.23456789e+10L));

const char* buffer4 = "1234.56789e+10";
T v4 = 0;
T v4;
auto r4 = boost::charconv::from_chars(buffer4, buffer4 + std::strlen(buffer4), v4);
BOOST_TEST(r4.ec == std::errc());
BOOST_TEST_EQ(v4, static_cast<T>(1234.56789e+10L));
Expand All @@ -115,13 +115,13 @@ template <typename T>
void simple_hex_scientific_test()
{
const char* buffer1 = "1.3a2bp-10";
T v1 = 0;
T v1;
auto r1 = boost::charconv::from_chars(buffer1, buffer1 + std::strlen(buffer1), v1, boost::charconv::chars_format::hex);
BOOST_TEST(r1.ec == std::errc());
BOOST_TEST_EQ(v1, static_cast<T>(80427e-14L));

const char* buffer2 = "1.234p-10";
T v2 = 0;
T v2;
auto r2 = boost::charconv::from_chars(buffer2, buffer2 + std::strlen(buffer2), v2, boost::charconv::chars_format::hex);
BOOST_TEST(r2.ec == std::errc());
BOOST_TEST_EQ(v2, static_cast<T>(4660e-13L));
Expand All @@ -131,25 +131,25 @@ template <typename T>
void dot_position_test()
{
const char* buffer1 = "11.11111111";
T v1 = 0;
T v1;
auto r1 = boost::charconv::from_chars(buffer1, buffer1 + std::strlen(buffer1), v1);
BOOST_TEST(r1.ec == std::errc());
BOOST_TEST_EQ(v1, static_cast<T>(11.11111111L));

const char* buffer2 = "1111.111111";
T v2 = 0;
T v2;
auto r2 = boost::charconv::from_chars(buffer2, buffer2 + std::strlen(buffer2), v2);
BOOST_TEST(r2.ec == std::errc());
BOOST_TEST_EQ(v2, static_cast<T>(1111.111111L));

const char* buffer3 = "111111.1111";
T v3 = 0;
T v3;
auto r3 = boost::charconv::from_chars(buffer3, buffer3 + std::strlen(buffer3), v3);
BOOST_TEST(r3.ec == std::errc());
BOOST_TEST_EQ(v3, static_cast<T>(111111.1111L));

const char* buffer4 = "1111111111.";
T v4 = 0;
T v4;
auto r4 = boost::charconv::from_chars(buffer4, buffer4 + std::strlen(buffer4), v4);
BOOST_TEST(r4.ec == std::errc());
BOOST_TEST_EQ(v4, static_cast<T>(1111111111.L));
Expand All @@ -159,37 +159,37 @@ template <typename T>
void odd_strings_test()
{
const char* buffer1 = "00000000000000000000000000000000000000000005";
T v1 = 0;
T v1;
auto r1 = boost::charconv::from_chars(buffer1, buffer1 + std::strlen(buffer1), v1);
BOOST_TEST(r1.ec == std::errc());
BOOST_TEST_EQ(v1, static_cast<T>(5));

const char* buffer2 = "123456789123456789123456789";
T v2 = 0;
T v2;
auto r2 = boost::charconv::from_chars(buffer2, buffer2 + std::strlen(buffer2), v2);
BOOST_TEST(r2.ec == std::errc());
BOOST_TEST_EQ(v2, static_cast<T>(1.23456789123456789123456789e26L));

const char* buffer3 = "100000000000000000000000e5";
T v3 = 0;
T v3;
auto r3 = boost::charconv::from_chars(buffer3, buffer3 + std::strlen(buffer3), v3);
BOOST_TEST(r3.ec == std::errc());
BOOST_TEST_EQ(v3, static_cast<T>(100000000000000000000000e5L));

const char* buffer4 = "1.23456789123456789123456789123456789123456789e-5";
T v4 = 0;
T v4;
auto r4 = boost::charconv::from_chars(buffer4, buffer4 + std::strlen(buffer4), v4);
BOOST_TEST(r4.ec == std::errc());
BOOST_TEST_EQ(v4, static_cast<T>(1.23456789123456789123456789123456789123456789e-5L));

const char* buffer5 = "1.23456789123456789123456789123456789123456789e-00000000000000000005";
T v5 = 0;
T v5;
auto r5 = boost::charconv::from_chars(buffer5, buffer5 + std::strlen(buffer5), v5);
BOOST_TEST(r5.ec == std::errc());
BOOST_TEST_EQ(v5, static_cast<T>(1.23456789123456789123456789123456789123456789e-5L));

const char* buffer6 = "E01";
T v6 = 0;
T v6;
auto r6 = boost::charconv::from_chars(buffer6, buffer6 + std::strlen(buffer6), v6);
BOOST_TEST(r6.ec == std::errc::invalid_argument);
}
Expand All @@ -198,42 +198,42 @@ template <typename T>
void zero_test()
{
const char* buffer1 = "0e0";
T v1 = 0;
T v1;
auto r1 = boost::charconv::from_chars(buffer1, buffer1 + std::strlen(buffer1), v1);
BOOST_TEST(r1.ec == std::errc());
BOOST_TEST_EQ(v1, static_cast<T>(0));
BOOST_TEST(!std::signbit(v1));

const char* buffer2 = "-0e0";
T v2 = 0;
T v2;
auto r2 = boost::charconv::from_chars(buffer2, buffer2 + std::strlen(buffer2), v2);
BOOST_TEST(r2.ec == std::errc());
BOOST_TEST_EQ(v2, static_cast<T>(-0));
BOOST_TEST(std::signbit(v2));

const char* buffer3 = "0.0";
T v3 = 0;
T v3;
auto r3 = boost::charconv::from_chars(buffer3, buffer3 + std::strlen(buffer3), v3);
BOOST_TEST(r3.ec == std::errc());
BOOST_TEST_EQ(v3, static_cast<T>(0.0));
BOOST_TEST(!std::signbit(v3));

const char* buffer4 = "-0.0";
T v4 = 0;
T v4;
auto r4 = boost::charconv::from_chars(buffer4, buffer4 + std::strlen(buffer4), v4);
BOOST_TEST(r4.ec == std::errc());
BOOST_TEST_EQ(v4, static_cast<T>(-0));
BOOST_TEST(std::signbit(v4));

const char* buffer5 = "0";
T v5 = 0;
T v5;
auto r5 = boost::charconv::from_chars(buffer5, buffer5 + std::strlen(buffer5), v5);
BOOST_TEST(r5.ec == std::errc());
BOOST_TEST_EQ(v5, static_cast<T>(0));
BOOST_TEST(!std::signbit(v5));

const char* buffer6 = "-0";
T v6 = 0;
T v6;
auto r6 = boost::charconv::from_chars(buffer6, buffer6 + std::strlen(buffer6), v6);
BOOST_TEST(r6.ec == std::errc());
BOOST_TEST_EQ(v6, static_cast<T>(-0));
Expand Down

0 comments on commit 78cd508

Please sign in to comment.