优化了平衡,尤其对于向后倾倒的几种极限情况进行优化

This commit is contained in:
myperworld committed 2025-08-16 22:32:06 +08:00
1 parent 10aba2664d
commit fcb8af8163
693 files changed
+2427 -70

No files matched your search

@@ -0,0 +1,89 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonArray::remove()") {
DynamicJsonDocument doc(4096);
JsonArray array = doc.to<JsonArray>();
array.add(1);
array.add(2);
array.add(3);
SECTION("remove first by index") {
array.remove(0);
REQUIRE(2 == array.size());
REQUIRE(array[0] == 2);
REQUIRE(array[1] == 3);
}
SECTION("remove middle by index") {
array.remove(1);
REQUIRE(2 == array.size());
REQUIRE(array[0] == 1);
REQUIRE(array[1] == 3);
}
SECTION("remove last by index") {
array.remove(2);
REQUIRE(2 == array.size());
REQUIRE(array[0] == 1);
REQUIRE(array[1] == 2);
}
SECTION("remove first by iterator") {
JsonArray::iterator it = array.begin();
array.remove(it);
REQUIRE(2 == array.size());
REQUIRE(array[0] == 2);
REQUIRE(array[1] == 3);
}
SECTION("remove middle by iterator") {
JsonArray::iterator it = array.begin();
++it;
array.remove(it);
REQUIRE(2 == array.size());
REQUIRE(array[0] == 1);
REQUIRE(array[1] == 3);
}
SECTION("remove last bty iterator") {
JsonArray::iterator it = array.begin();
++it;
++it;
array.remove(it);
REQUIRE(2 == array.size());
REQUIRE(array[0] == 1);
REQUIRE(array[1] == 2);
}
SECTION("In a loop") {
for (JsonArray::iterator it = array.begin(); it != array.end(); ++it) {
if (*it == 2)
array.remove(it);
}
REQUIRE(2 == array.size());
REQUIRE(array[0] == 1);
REQUIRE(array[1] == 3);
}
SECTION("remove by index on unbound reference") {
JsonArray unboundArray;
unboundArray.remove(20);
}
SECTION("remove by iterator on unbound reference") {
JsonArray unboundArray;
unboundArray.remove(unboundArray.begin());
}
}