Removed configurable number of decimal places (issues #288, #427 and #506)

This commit is contained in:
Benoit Blanchon
2017-05-20 09:06:53 +02:00
parent 639286f8b6
commit cda05aec04
33 changed files with 447 additions and 391 deletions

View File

@ -17,28 +17,28 @@ TEST_CASE("JsonArray::add()") {
REQUIRE(1U == _array.size());
}
SECTION("StoreInteger") {
SECTION("int") {
_array.add(123);
REQUIRE(123 == _array[0].as<int>());
REQUIRE(_array[0].is<int>());
REQUIRE_FALSE(_array[0].is<double>());
REQUIRE(_array[0].is<double>());
}
SECTION("StoreDouble") {
SECTION("double") {
_array.add(123.45);
REQUIRE(123.45 == _array[0].as<double>());
REQUIRE(_array[0].is<double>());
REQUIRE_FALSE(_array[0].is<int>());
REQUIRE_FALSE(_array[0].is<bool>());
}
SECTION("StoreBoolean") {
SECTION("bool") {
_array.add(true);
REQUIRE(true == _array[0].as<bool>());
REQUIRE(_array[0].is<bool>());
REQUIRE_FALSE(_array[0].is<int>());
}
SECTION("StoreString") {
SECTION("const char*") {
const char* str = "hello";
_array.add(str);
REQUIRE(str == _array[0].as<const char*>());
@ -46,7 +46,7 @@ TEST_CASE("JsonArray::add()") {
REQUIRE_FALSE(_array[0].is<int>());
}
SECTION("StoreNestedArray") {
SECTION("nested array") {
JsonArray& arr = _jsonBuffer.createArray();
_array.add(arr);
@ -56,7 +56,7 @@ TEST_CASE("JsonArray::add()") {
REQUIRE_FALSE(_array[0].is<int>());
}
SECTION("StoreNestedObject") {
SECTION("nested object") {
JsonObject& obj = _jsonBuffer.createObject();
_array.add(obj);
@ -66,7 +66,7 @@ TEST_CASE("JsonArray::add()") {
REQUIRE_FALSE(_array[0].is<int>());
}
SECTION("StoreArraySubscript") {
SECTION("array subscript") {
const char* str = "hello";
JsonArray& arr = _jsonBuffer.createArray();
arr.add(str);
@ -76,7 +76,7 @@ TEST_CASE("JsonArray::add()") {
REQUIRE(str == _array[0]);
}
SECTION("StoreObjectSubscript") {
SECTION("object subscript") {
const char* str = "hello";
JsonObject& obj = _jsonBuffer.createObject();
obj["x"] = str;

View File

@ -52,29 +52,9 @@ TEST_CASE("JsonArray::printTo()") {
check(array, "[\"hello\",\"world\"]");
}
SECTION("OneDoubleDefaultDigits") {
array.add(3.14159265358979323846);
check(array, "[3.14]");
}
SECTION("OneDoubleFourDigits") {
array.add(3.14159265358979323846, 4);
check(array, "[3.1416]");
}
SECTION("OneDoubleFourDigits_AlternativeSyntax") {
array.add(double_with_n_digits(3.14159265358979323846, 4));
check(array, "[3.1416]");
}
SECTION("OneFloatDefaultDigits") {
array.add(3.14159f);
check(array, "[3.14]");
}
SECTION("OneFloatFourDigits") {
array.add(3.14159f, 4);
check(array, "[3.1416]");
SECTION("One double") {
array.add(3.1415927);
check(array, "[3.1415927]");
}
SECTION("OneInteger") {

View File

@ -20,35 +20,35 @@ TEST_CASE("JsonArray::set()") {
REQUIRE(1U == _array.size());
}
SECTION("StoreInteger") {
SECTION("int") {
_array.set(0, 123);
REQUIRE(123 == _array[0].as<int>());
REQUIRE(_array[0].is<int>());
REQUIRE_FALSE(_array[0].is<double>());
REQUIRE_FALSE(_array[0].is<bool>());
}
SECTION("StoreDouble") {
SECTION("double") {
_array.set(0, 123.45);
REQUIRE(123.45 == _array[0].as<double>());
REQUIRE(_array[0].is<double>());
REQUIRE_FALSE(_array[0].is<int>());
}
SECTION("StoreBoolean") {
SECTION("bool") {
_array.set(0, true);
REQUIRE(true == _array[0].as<bool>());
REQUIRE(_array[0].is<bool>());
REQUIRE_FALSE(_array[0].is<int>());
}
SECTION("StoreString") {
SECTION("const char*") {
_array.set(0, "hello");
REQUIRE_THAT(_array[0].as<const char*>(), Equals("hello"));
REQUIRE(_array[0].is<const char*>());
REQUIRE_FALSE(_array[0].is<int>());
}
SECTION("StoreNestedArray") {
SECTION("nested array") {
JsonArray& arr = _jsonBuffer.createArray();
_array.set(0, arr);
@ -58,7 +58,7 @@ TEST_CASE("JsonArray::set()") {
REQUIRE_FALSE(_array[0].is<int>());
}
SECTION("StoreNestedObject") {
SECTION("nested object") {
JsonObject& obj = _jsonBuffer.createObject();
_array.set(0, obj);
@ -68,7 +68,7 @@ TEST_CASE("JsonArray::set()") {
REQUIRE_FALSE(_array[0].is<int>());
}
SECTION("StoreArraySubscript") {
SECTION("array subscript") {
JsonArray& arr = _jsonBuffer.createArray();
arr.add("hello");
@ -77,7 +77,7 @@ TEST_CASE("JsonArray::set()") {
REQUIRE_THAT(_array[0].as<char*>(), Equals("hello"));
}
SECTION("StoreObjectSubscript") {
SECTION("object subscript") {
JsonObject& obj = _jsonBuffer.createObject();
obj["x"] = "hello";

View File

@ -19,44 +19,37 @@ TEST_CASE("JsonArray::operator[]") {
REQUIRE(1U == _array.size());
}
SECTION("StoreInteger") {
SECTION("int") {
_array[0] = 123;
REQUIRE(123 == _array[0].as<int>());
REQUIRE(true == _array[0].is<int>());
REQUIRE(false == _array[0].is<double>());
REQUIRE(false == _array[0].is<bool>());
}
#if ARDUINOJSON_USE_LONG_LONG || ARDUINOJSON_USE_INT64
SECTION("StoreLongLong") {
SECTION("long long") {
_array[0] = 9223372036854775807;
REQUIRE(9223372036854775807 == _array[0].as<long long>());
REQUIRE(true == _array[0].is<int>());
REQUIRE(false == _array[0].is<double>());
REQUIRE(false == _array[0].is<bool>());
}
#endif
SECTION("StoreDouble") {
SECTION("double") {
_array[0] = 123.45;
REQUIRE(123.45 == _array[0].as<double>());
REQUIRE(true == _array[0].is<double>());
REQUIRE(false == _array[0].is<int>());
}
SECTION("StoreDoubleWithDecimals") {
_array[0].set(123.45, 2);
REQUIRE(123.45 == _array[0].as<double>());
REQUIRE(true == _array[0].is<double>());
REQUIRE(false == _array[0].is<int>());
}
SECTION("StoreBoolean") {
SECTION("bool") {
_array[0] = true;
REQUIRE(true == _array[0].as<bool>());
REQUIRE(true == _array[0].is<bool>());
REQUIRE(false == _array[0].is<int>());
}
SECTION("StoreString") {
SECTION("const char*") {
const char* str = "hello";
_array[0] = str;
@ -66,7 +59,7 @@ TEST_CASE("JsonArray::operator[]") {
REQUIRE(false == _array[0].is<int>());
}
SECTION("StoreNestedArray") {
SECTION("nested array") {
JsonArray& arr = _jsonBuffer.createArray();
_array[0] = arr;
@ -79,7 +72,7 @@ TEST_CASE("JsonArray::operator[]") {
REQUIRE(false == _array[0].is<int>());
}
SECTION("StoreNestedObject") {
SECTION("nested object") {
JsonObject& obj = _jsonBuffer.createObject();
_array[0] = obj;
@ -92,7 +85,7 @@ TEST_CASE("JsonArray::operator[]") {
REQUIRE(false == _array[0].is<int>());
}
SECTION("StoreArraySubscript") {
SECTION("array subscript") {
JsonArray& arr = _jsonBuffer.createArray();
const char* str = "hello";
@ -103,7 +96,7 @@ TEST_CASE("JsonArray::operator[]") {
REQUIRE(str == _array[0]);
}
SECTION("StoreObjectSubscript") {
SECTION("object subscript") {
JsonObject& obj = _jsonBuffer.createObject();
const char* str = "hello";

View File

@ -29,7 +29,7 @@ TEST_CASE("JsonBuffer::parse()") {
JsonVariant variant = jb.parse("-42");
REQUIRE(variant.success());
REQUIRE(variant.is<int>());
REQUIRE_FALSE(variant.is<double>());
REQUIRE_FALSE(variant.is<bool>());
REQUIRE(variant == -42);
}

View File

@ -76,17 +76,10 @@ TEST_CASE("JsonObject::printTo()") {
check(obj, "{\"a\":[1,2],\"b\":[4,5]}");
}
SECTION("TwoDoublesFourDigits") {
obj["a"] = double_with_n_digits(3.14159265358979323846, 4);
obj.set("b", 2.71828182845904523536, 4);
obj.set("c", double_with_n_digits(3.14159265358979323846, 3));
check(obj, "{\"a\":3.1416,\"b\":2.7183,\"c\":3.142}");
}
SECTION("TwoDoubleDefaultDigits") {
obj["a"] = 3.14159265358979323846;
obj.set("b", 2.71828182845904523536);
check(obj, "{\"a\":3.14,\"b\":2.72}");
SECTION("Two doubles") {
obj["a"] = 12.34;
obj.set("b", 56.78);
check(obj, "{\"a\":12.34,\"b\":56.78}");
}
SECTION("TwoNull") {

View File

@ -24,31 +24,23 @@ TEST_CASE("JsonObject::set()") {
REQUIRE(1 == _object.size());
}
SECTION("StoreInteger") {
SECTION("int") {
_object.set("hello", 123);
REQUIRE(123 == _object["hello"].as<int>());
REQUIRE(_object["hello"].is<int>());
REQUIRE_FALSE(_object["hello"].is<double>());
REQUIRE_FALSE(_object["hello"].is<bool>());
}
SECTION("StoreDouble") {
SECTION("double") {
_object.set("hello", 123.45);
REQUIRE(123.45 == _object["hello"].as<double>());
REQUIRE(_object["hello"].is<double>());
REQUIRE_FALSE(_object["hello"].is<long>());
REQUIRE_FALSE(_object["hello"].is<bool>());
}
SECTION("StoreDoubleWithDigits") {
_object.set("hello", 123.45, 2);
REQUIRE(123.45 == _object["hello"].as<double>());
REQUIRE(_object["hello"].is<double>());
REQUIRE_FALSE(_object["hello"].is<long>());
}
SECTION("StoreBoolean") {
SECTION("bool") {
_object.set("hello", true);
REQUIRE(_object["hello"].as<bool>());
@ -56,7 +48,7 @@ TEST_CASE("JsonObject::set()") {
REQUIRE_FALSE(_object["hello"].is<long>());
}
SECTION("StoreString") {
SECTION("const char*") {
_object.set("hello", "h3110");
REQUIRE(std::string("h3110") == _object["hello"].as<const char*>());
@ -64,7 +56,7 @@ TEST_CASE("JsonObject::set()") {
REQUIRE_FALSE(_object["hello"].is<long>());
}
SECTION("StoreArray") {
SECTION("nested array") {
JsonArray& arr = jb.createArray();
_object.set("hello", arr);
@ -74,7 +66,7 @@ TEST_CASE("JsonObject::set()") {
REQUIRE_FALSE(_object["hello"].is<JsonObject&>());
}
SECTION("StoreObject") {
SECTION("nested object") {
JsonObject& obj = jb.createObject();
_object.set("hello", obj);
@ -84,7 +76,7 @@ TEST_CASE("JsonObject::set()") {
REQUIRE_FALSE(_object["hello"].is<JsonArray&>());
}
SECTION("StoreArraySubscript") {
SECTION("array subscript") {
JsonArray& arr = jb.createArray();
arr.add(42);
@ -93,7 +85,7 @@ TEST_CASE("JsonObject::set()") {
REQUIRE(42 == _object["a"]);
}
SECTION("StoreObjectSubscript") {
SECTION("object subscript") {
JsonObject& obj = jb.createObject();
obj.set("x", 42);

View File

@ -23,24 +23,24 @@ TEST_CASE("JsonObject::operator[]") {
REQUIRE(1 == _object.size());
}
SECTION("StoreInteger") {
SECTION("int") {
_object["hello"] = 123;
REQUIRE(123 == _object["hello"].as<int>());
REQUIRE(true == _object["hello"].is<int>());
REQUIRE(false == _object["hello"].is<double>());
REQUIRE(false == _object["hello"].is<bool>());
}
SECTION("StoreVolatileInteger") { // issue #415
SECTION("volatile int") { // issue #415
volatile int i = 123;
_object["hello"] = i;
REQUIRE(123 == _object["hello"].as<int>());
REQUIRE(true == _object["hello"].is<int>());
REQUIRE(false == _object["hello"].is<double>());
REQUIRE(false == _object["hello"].is<bool>());
}
SECTION("StoreDouble") {
SECTION("double") {
_object["hello"] = 123.45;
REQUIRE(true == _object["hello"].is<double>());
@ -48,15 +48,7 @@ TEST_CASE("JsonObject::operator[]") {
REQUIRE(123.45 == _object["hello"].as<double>());
}
SECTION("StoreDoubleWithDigits") {
_object["hello"].set(123.45, 2);
REQUIRE(true == _object["hello"].is<double>());
REQUIRE(false == _object["hello"].is<long>());
REQUIRE(123.45 == _object["hello"].as<double>());
}
SECTION("StoreBoolean") {
SECTION("bool") {
_object["hello"] = true;
REQUIRE(true == _object["hello"].is<bool>());
@ -64,7 +56,7 @@ TEST_CASE("JsonObject::operator[]") {
REQUIRE(true == _object["hello"].as<bool>());
}
SECTION("StoreString") {
SECTION("const char*") {
_object["hello"] = "h3110";
REQUIRE(true == _object["hello"].is<const char*>());
@ -74,7 +66,7 @@ TEST_CASE("JsonObject::operator[]") {
_object["hello"].as<char*>()); // <- short hand
}
SECTION("StoreArray") {
SECTION("array") {
JsonArray& arr = _jsonBuffer.createArray();
_object["hello"] = arr;
@ -90,7 +82,7 @@ TEST_CASE("JsonObject::operator[]") {
REQUIRE(false == _object["hello"].is<JsonObject&>());
}
SECTION("StoreObject") {
SECTION("object") {
JsonObject& obj = _jsonBuffer.createObject();
_object["hello"] = obj;
@ -106,7 +98,7 @@ TEST_CASE("JsonObject::operator[]") {
REQUIRE(false == _object["hello"].is<JsonArray&>());
}
SECTION("StoreArraySubscript") {
SECTION("array subscript") {
JsonArray& arr = _jsonBuffer.createArray();
arr.add(42);
@ -115,7 +107,7 @@ TEST_CASE("JsonObject::operator[]") {
REQUIRE(42 == _object["a"]);
}
SECTION("StoreObjectSubscript") {
SECTION("object subscript") {
JsonObject& obj = _jsonBuffer.createObject();
obj.set("x", 42);

View File

@ -24,7 +24,7 @@ TEST_CASE("JsonVariant::as()") {
SECTION("DoubleAsString") {
JsonVariant variant = 4.2;
REQUIRE(std::string("4.20") == variant.as<std::string>());
REQUIRE(std::string("4.2") == variant.as<std::string>());
}
SECTION("DoubleAsLong") {

View File

@ -50,10 +50,10 @@ void checkIsFloat(JsonVariant var) {
void checkIsInteger(JsonVariant var) {
REQUIRE(var.is<long>());
REQUIRE(var.is<int>());
REQUIRE(var.is<float>());
REQUIRE(var.is<double>());
REQUIRE_FALSE(var.is<bool>());
REQUIRE_FALSE(var.is<double>());
REQUIRE_FALSE(var.is<float>());
REQUIRE_FALSE(var.is<const char*>());
REQUIRE_FALSE(var.is<JsonArray>());
REQUIRE_FALSE(var.is<JsonObject>());

View File

@ -29,48 +29,8 @@ TEST_CASE("JsonVariant::printTo()") {
check("hello", "\"hello\"");
}
SECTION("DoubleZero") {
check(0.0, "0.00");
}
SECTION("DoubleDefaultDigits") {
check(3.14159265358979323846, "3.14");
}
SECTION("DoubleFourDigits") {
check(JsonVariant(3.14159265358979323846, 4), "3.1416");
}
SECTION("Infinity") {
check(std::numeric_limits<double>::infinity(), "Infinity");
}
SECTION("MinusInfinity") {
check(-std::numeric_limits<double>::infinity(), "-Infinity");
}
SECTION("SignalingNaN") {
check(std::numeric_limits<double>::signaling_NaN(), "NaN");
}
SECTION("QuietNaN") {
check(std::numeric_limits<double>::quiet_NaN(), "NaN");
}
SECTION("VeryBigPositiveDouble") {
check(JsonVariant(3.14159265358979323846e42, 4), "3.1416e42");
}
SECTION("VeryBigNegativeDouble") {
check(JsonVariant(-3.14159265358979323846e42, 4), "-3.1416e42");
}
SECTION("VerySmallPositiveDouble") {
check(JsonVariant(3.14159265358979323846e-42, 4), "3.1416e-42");
}
SECTION("VerySmallNegativeDouble") {
check(JsonVariant(-3.14159265358979323846e-42, 4), "-3.1416e-42");
SECTION("Double") {
check(3.1415927, "3.1415927");
}
SECTION("Integer") {

View File

@ -9,82 +9,96 @@
#include <limits>
#include <string>
#include <ArduinoJson/Serialization/DynamicStringBuilder.hpp>
#include <ArduinoJson/Serialization/JsonWriter.hpp>
#include <ArduinoJson/Serialization/StaticStringBuilder.hpp>
using namespace ArduinoJson::Internals;
void check(const std::string& expected, double input, uint8_t digits = 2) {
char output[1024];
StaticStringBuilder sb(output, sizeof(output));
JsonWriter<StaticStringBuilder> writer(sb);
writer.writeFloat(input, digits);
REQUIRE(output == expected);
REQUIRE(writer.bytesWritten() == expected.size());
void check(double input, const std::string& expected) {
std::string output;
DynamicStringBuilder<std::string> sb(output);
JsonWriter<DynamicStringBuilder<std::string> > writer(sb);
writer.writeFloat(input);
REQUIRE(writer.bytesWritten() == output.size());
CHECK(expected == output);
}
TEST_CASE("JsonWriter::writeFloat()") {
SECTION("NaN") {
check("NaN", std::numeric_limits<double>::signaling_NaN());
SECTION("Pi") {
check(3.14159265359, "3.141592654");
}
SECTION("PositiveInfinity") {
check("Infinity", std::numeric_limits<double>::infinity());
SECTION("Signaling NaN") {
double nan = std::numeric_limits<double>::signaling_NaN();
check(nan, "NaN");
}
SECTION("NegativeInfinity") {
check("-Infinity", -std::numeric_limits<double>::infinity());
SECTION("Quiet NaN") {
double nan = std::numeric_limits<double>::quiet_NaN();
check(nan, "NaN");
}
SECTION("Infinity") {
double inf = std::numeric_limits<double>::infinity();
check(inf, "Infinity");
check(-inf, "-Infinity");
}
SECTION("Zero") {
check("0.00", 0);
check(0.0, "0");
check(-0.0, "0");
}
SECTION("ZeroDigits_Rounding") {
check("10", 9.5, 0);
SECTION("Espilon") {
check(2.2250738585072014E-308, "2.225073859e-308");
check(-2.2250738585072014E-308, "-2.225073859e-308");
}
SECTION("ZeroDigits_NoRounding") {
check("9", 9.4, 0);
SECTION("Max double") {
check(1.7976931348623157E+308, "1.797693135e308");
check(-1.7976931348623157E+308, "-1.797693135e308");
}
SECTION("OneDigit_Rounding") {
check("10.0", 9.95, 1);
SECTION("Big exponent") {
// this test increases coverage of normalize()
check(1e255, "1e255");
check(1e-255, "1e-255");
}
SECTION("OneDigit_NoRounding") {
check("9.9", 9.94, 1);
SECTION("Exponentation when <= 1e-5") {
check(1e-4, "0.0001");
check(1e-5, "1e-5");
check(-1e-4, "-0.0001");
check(-1e-5, "-1e-5");
}
SECTION("TwoDigits_Rounding") {
check("10.00", 9.995, 2);
SECTION("Exponentation when >= 1e7") {
check(9999999.999, "9999999.999");
check(10000000, "1e7");
check(-9999999.999, "-9999999.999");
check(-10000000, "-1e7");
}
SECTION("TwoDigits_NoRounding") {
check("9.99", 9.994, 2);
SECTION("Rounding when too many decimals") {
check(0.000099999999999, "0.0001");
check(0.0000099999999999, "1e-5");
}
SECTION("ThreeDigits_Rounding") {
check("10.000", 9.9995, 3);
SECTION("9 decimal places") {
check(0.100000001, "0.100000001");
check(0.999999999, "0.999999999");
check(9.000000001, "9.000000001");
check(9.999999999, "9.999999999");
}
SECTION("ThreeDigits_NoRounding") {
check("9.999", 9.9994, 3);
}
SECTION("10 decimal places") {
check(0.1000000001, "0.1");
check(0.9999999999, "1");
SECTION("FourDigits_Rounding") {
check("10.0000", 9.99995, 4);
}
SECTION("FourDigits_NoRounding") {
check("9.9999", 9.99994, 4);
}
SECTION("FiveDigits_Rounding") {
check("10.00000", 9.999995, 5);
}
SECTION("FiveDigits_NoRounding") {
check("9.99999", 9.999994, 5);
check(9.0000000001, "9");
check(9.9999999999, "10");
}
}

View File

@ -19,14 +19,14 @@
#endif
TEST_CASE("Deprecated functions") {
DynamicJsonBuffer jsonBuffer;
SECTION("JsonVariant::asArray()") {
DynamicJsonBuffer jsonBuffer;
JsonVariant variant = jsonBuffer.createArray();
REQUIRE(variant.asArray().success());
}
SECTION("JsonVariant::asObject()") {
DynamicJsonBuffer jsonBuffer;
JsonVariant variant = jsonBuffer.createObject();
REQUIRE(variant.asObject().success());
}
@ -37,8 +37,73 @@ TEST_CASE("Deprecated functions") {
}
SECTION("JsonArray::removeAt()") {
DynamicJsonBuffer jsonBuffer;
JsonArray& arr = jsonBuffer.createArray();
arr.removeAt(0);
}
SECTION("JsonVariant::JsonVariant(float, uint8_t)") {
JsonVariant variant(3.14f, 2);
REQUIRE(variant == 3.14f);
}
SECTION("JsonVariant::JsonVariant(double, uint8_t)") {
JsonVariant variant(3.14, 2);
REQUIRE(variant == 3.14);
}
SECTION("float_with_n_digits()") {
JsonVariant variant = float_with_n_digits(3.14f, 4);
REQUIRE(variant == 3.14f);
}
SECTION("double_with_n_digits()") {
JsonVariant variant = double_with_n_digits(3.14f, 4);
REQUIRE(variant == 3.14f);
}
SECTION("JsonArraySubscript::set(double, uint8_t)") {
JsonArray& arr = jsonBuffer.createArray();
arr.add(666);
arr[0].set(123.45, 2);
REQUIRE(123.45 == arr[0].as<double>());
REQUIRE(true == arr[0].is<double>());
REQUIRE(false == arr[0].is<int>());
}
SECTION("JsonArray::add(double, uint8_t)") {
JsonArray& arr = jsonBuffer.createArray();
arr.add(3.14159265358979323846, 4);
}
SECTION("JsonArray::add(float, uint8_t)") {
JsonArray& arr = jsonBuffer.createArray();
arr.add(3.14159265358979323846f, 4);
}
SECTION("JsonObject::set(unsigned char[], double, uint8_t)") {
unsigned char key[] = "hello";
JsonObject& obj = jsonBuffer.createObject();
obj.set(key, 3.14, 2);
REQUIRE(3.14 == obj["hello"]);
}
SECTION("JsonObject::set(const char*, double, uint8_t)") {
JsonObject& obj = jsonBuffer.createObject();
obj.set("hello", 123.45, 2);
REQUIRE(123.45 == obj["hello"].as<double>());
REQUIRE(obj["hello"].is<double>());
REQUIRE_FALSE(obj["hello"].is<long>());
}
SECTION("JsonObjectSubscript::set(double, uint8_t)") {
JsonObject& obj = jsonBuffer.createObject();
obj["hello"].set(123.45, 2);
REQUIRE(true == obj["hello"].is<double>());
REQUIRE(false == obj["hello"].is<long>());
REQUIRE(123.45 == obj["hello"].as<double>());
}
}

View File

@ -166,16 +166,6 @@ TEST_CASE("unsigned char string") {
REQUIRE(std::string("world") == obj["hello"]);
}
SECTION("JsonObject::set() key with decimals") {
unsigned char key[] = "hello";
DynamicJsonBuffer jsonBuffer;
JsonObject& obj = jsonBuffer.createObject();
obj.set(key, 3.14, 2);
REQUIRE(3.14 == obj["hello"]);
}
SECTION("JsonObject::set key&value") {
unsigned char key[] = "world";

View File

@ -214,18 +214,6 @@ TEST_CASE("Variable Length Array") {
REQUIRE(std::string("world") == obj["hello"]);
}
SECTION("JsonObject_Set_Key_WithDecimals") {
int i = 16;
char vla[i];
strcpy(vla, "hello");
DynamicJsonBuffer jsonBuffer;
JsonObject& obj = jsonBuffer.createObject();
obj.set(vla, 3.14, 2);
REQUIRE(3.14 == obj["hello"]);
}
SECTION("JsonObject_Set_KeyAndValue") {
int i = 16;
char vla[i];

View File

@ -40,9 +40,9 @@ TEST_CASE("isFloat()") {
}
SECTION("Integer") {
REQUIRE_FALSE(isFloat("14"));
REQUIRE_FALSE(isFloat("-14"));
REQUIRE_FALSE(isFloat("+14"));
REQUIRE(isFloat("14"));
REQUIRE(isFloat("-14"));
REQUIRE(isFloat("+14"));
}
SECTION("ExponentMissing") {