Update deps (#482)

This commit is contained in:
iranl
2024-10-09 15:06:50 +02:00
committed by GitHub
parent 3207cde395
commit 3f0ef34c9e
95 changed files with 2250 additions and 797 deletions

View File

@@ -4,8 +4,9 @@
add_executable(NumbersTests
convertNumber.cpp
parseFloat.cpp
decomposeFloat.cpp
parseDouble.cpp
parseFloat.cpp
parseInteger.cpp
parseNumber.cpp
)

View File

@@ -0,0 +1,42 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License
#include <ArduinoJson/Numbers/FloatParts.hpp>
#include <catch.hpp>
using namespace ArduinoJson::detail;
TEST_CASE("decomposeFloat()") {
SECTION("1.7976931348623157E+308") {
auto parts = decomposeFloat(1.7976931348623157E+308, 9);
REQUIRE(parts.integral == 1);
REQUIRE(parts.decimal == 797693135);
REQUIRE(parts.decimalPlaces == 9);
REQUIRE(parts.exponent == 308);
}
SECTION("4.94065645841247e-324") {
auto parts = decomposeFloat(4.94065645841247e-324, 9);
REQUIRE(parts.integral == 4);
REQUIRE(parts.decimal == 940656458);
REQUIRE(parts.decimalPlaces == 9);
REQUIRE(parts.exponent == -324);
}
SECTION("3.4E+38") {
auto parts = decomposeFloat(3.4E+38f, 6);
REQUIRE(parts.integral == 3);
REQUIRE(parts.decimal == 4);
REQUIRE(parts.decimalPlaces == 1);
REQUIRE(parts.exponent == 38);
}
SECTION("1.17549435e38") {
auto parts = decomposeFloat(1.17549435e-38f, 6);
REQUIRE(parts.integral == 1);
REQUIRE(parts.decimal == 175494);
REQUIRE(parts.decimalPlaces == 6);
REQUIRE(parts.exponent == -38);
}
}

View File

@@ -2,7 +2,6 @@
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License
#define ARDUINOJSON_USE_DOUBLE 0
#define ARDUINOJSON_ENABLE_NAN 1
#define ARDUINOJSON_ENABLE_INFINITY 1
@@ -13,7 +12,9 @@ using namespace ArduinoJson::detail;
void checkFloat(const char* input, float expected) {
CAPTURE(input);
REQUIRE(parseNumber<float>(input) == Approx(expected));
auto result = parseNumber(input);
REQUIRE(result.type() == NumberType::Float);
REQUIRE(result.asFloat() == Approx(expected));
}
void checkFloatNaN(const char* input) {
@@ -59,27 +60,15 @@ TEST_CASE("parseNumber<float>()") {
SECTION("VeryLong") {
checkFloat("0.00000000000000000000000000000001", 1e-32f);
checkFloat("100000000000000000000000000000000.0", 1e+32f);
checkFloat(
"100000000000000000000000000000000.00000000000000000000000000000",
1e+32f);
}
SECTION("MantissaTooLongToFit") {
checkFloat("0.340282346638528861111111111111", 0.34028234663852886f);
checkFloat("34028234663852886.11111111111111", 34028234663852886.0f);
checkFloat("34028234.66385288611111111111111", 34028234.663852886f);
checkFloat("-0.340282346638528861111111111111", -0.34028234663852886f);
checkFloat("-34028234663852886.11111111111111", -34028234663852886.0f);
checkFloat("-34028234.66385288611111111111111", -34028234.663852886f);
}
SECTION("ExponentTooBig") {
checkFloatInf("1e39", false);
checkFloatInf("-1e39", true);
checkFloatInf("1e255", false);
checkFloat("1e-255", 0.0f);
// The following don't work because they have many digits so parseNumber()
// treats them as double. But it's not an issue because JsonVariant will use
// a float to store them.
//
// checkFloat("100000000000000000000000000000000.0", 1e+32f);
// checkFloat(
// "100000000000000000000000000000000.00000000000000000000000000000",
// 1e+32f);
}
SECTION("NaN") {
@@ -94,8 +83,5 @@ TEST_CASE("parseNumber<float>()") {
checkFloatInf("inf", false);
checkFloatInf("+inf", false);
checkFloatInf("-inf", true);
checkFloatInf("1e300", false);
checkFloatInf("-1e300", true);
}
}

View File

@@ -9,45 +9,55 @@ using namespace ArduinoJson;
using namespace ArduinoJson::detail;
TEST_CASE("Test unsigned integer overflow") {
VariantData first, second;
Number first, second;
// Avoids MSVC warning C4127 (conditional expression is constant)
size_t integerSize = sizeof(JsonInteger);
if (integerSize == 8) {
parseNumber("18446744073709551615", first);
parseNumber("18446744073709551616", second);
first = parseNumber("18446744073709551615");
second = parseNumber("18446744073709551616");
} else {
parseNumber("4294967295", first);
parseNumber("4294967296", second);
first = parseNumber("4294967295");
second = parseNumber("4294967296");
}
REQUIRE(first.type() == uint8_t(VALUE_IS_UNSIGNED_INTEGER));
REQUIRE(second.type() == uint8_t(VALUE_IS_FLOAT));
REQUIRE(first.type() == NumberType::UnsignedInteger);
REQUIRE(second.type() == NumberType::Double);
}
TEST_CASE("Test signed integer overflow") {
VariantData first, second;
Number first, second;
// Avoids MSVC warning C4127 (conditional expression is constant)
size_t integerSize = sizeof(JsonInteger);
if (integerSize == 8) {
parseNumber("-9223372036854775808", first);
parseNumber("-9223372036854775809", second);
first = parseNumber("-9223372036854775808");
second = parseNumber("-9223372036854775809");
} else {
parseNumber("-2147483648", first);
parseNumber("-2147483649", second);
first = parseNumber("-2147483648");
second = parseNumber("-2147483649");
}
REQUIRE(first.type() == uint8_t(VALUE_IS_SIGNED_INTEGER));
REQUIRE(second.type() == uint8_t(VALUE_IS_FLOAT));
REQUIRE(first.type() == NumberType::SignedInteger);
REQUIRE(second.type() == NumberType::Double);
}
TEST_CASE("Invalid value") {
VariantData result;
auto result = parseNumber("6a3");
parseNumber("6a3", result);
REQUIRE(result.type() == uint8_t(VALUE_IS_NULL));
REQUIRE(result.type() == NumberType::Invalid);
}
TEST_CASE("float") {
auto result = parseNumber("3.402823e38");
REQUIRE(result.type() == NumberType::Float);
}
TEST_CASE("double") {
auto result = parseNumber("1.7976931348623157e308");
REQUIRE(result.type() == NumberType::Double);
}