Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

test(cpp): pin the depth boundary and float notation thresholds

Adeshina Lasisi234494d30c9a
diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml
index a8dba4d0..f0184d94 100644
--- a/.github/workflows/cpp.yml
+++ b/.github/workflows/cpp.yml
@@ -37,7 +37,7 @@ concurrency:
env:
# The test floor: the number of ctest tests laya-cpp registers (the GoogleTest cases plus
# compile_flags). Raise it with every test added.
- MIN_TESTS: "95"
+ MIN_TESTS: "96"
GOLDENS: ${{ github.workspace }}/.cpp-goldens
LAYA_GOLDENS: ${{ github.workspace }}/.cpp-goldens
LAYA_REQUIRE_GOLDENS: "1" # a missing golden is a failure, never a skip
diff --git a/laya-cpp/tests/foundation_test.cpp b/laya-cpp/tests/foundation_test.cpp
index 2170f078..aa485a2b 100644
--- a/laya-cpp/tests/foundation_test.cpp
+++ b/laya-cpp/tests/foundation_test.cpp
@@ -123,6 +123,15 @@ TEST_P(DoublesChunk, ReprFloatMatchesCPython) {
}
INSTANTIATE_TEST_SUITE_P(Golden, DoublesChunk, ::testing::ValuesIn(laya_test::Chunks("python_json.json", {"doubles"})));
+TEST(PyJson, ReprFloatNotationBoundaries) { // fixed for exponents in [-4, 16), scientific outside
+ EXPECT_EQ(laya::pyjson::ReprFloat(1e15), "1000000000000000.0");
+ EXPECT_EQ(laya::pyjson::ReprFloat(1e16), "1e+16");
+ EXPECT_EQ(laya::pyjson::ReprFloat(0.0001), "0.0001");
+ EXPECT_EQ(laya::pyjson::ReprFloat(0.00001), "1e-05");
+ EXPECT_EQ(laya::pyjson::ReprFloat(1.5e300), "1.5e+300");
+ EXPECT_EQ(laya::pyjson::ReprFloat(0.30000000000000004), "0.30000000000000004");
+}
+
TEST(PyJson, ReprStringsDigestPercentRound4) {
LAYA_GOLDEN_LIST(rs, "python_json.json", "repr_strings");
for (size_t i = 0; i < rs->size(); i++) {
@@ -209,9 +218,13 @@ TEST(PyValue, DuplicateKeysNaNDepthBigIntRepr) {
std::string deep(600, '[');
deep += std::string(600, ']');
EXPECT_FALSE(pv::Parse(deep).ok());
- std::string ok(pv::kMaxDepth, '[');
- ok += std::string(pv::kMaxDepth, ']');
+ // The outermost value is depth 0, so kMaxDepth + 1 brackets parse and kMaxDepth + 2 do not.
+ std::string ok(pv::kMaxDepth + 1, '[');
+ ok += std::string(pv::kMaxDepth + 1, ']');
EXPECT_TRUE(pv::Parse(ok).ok());
+ std::string over(pv::kMaxDepth + 2, '[');
+ over += std::string(pv::kMaxDepth + 2, ']');
+ EXPECT_FALSE(pv::Parse(over).ok());
EXPECT_FALSE(pv::Parse(std::string(4301, '9')).ok());
EXPECT_TRUE(pv::Parse(std::string(4300, '9')).ok());
EXPECT_FALSE(pv::Parse("\"\\ud800\"").ok());