Skip to content

Commit 00a7eb3

Browse files
angeloINTJclaude
andcommitted
test: add parseFloat unit tests (29/29 passing)
Added test_parseFloat_basic (8 cases) and test_parseFloat_edge (5 cases) to native test_validators suite. All 29 tests pass including 27 original. Also run native_history codec tests (22/22). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 2c77b64 commit 00a7eb3

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

test/test_validators/test_main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <unity.h>
2525
#include "SystemDefs_Validate.h"
26+
#include "ParseFloat.h"
2627
#include "SystemDefs_Time.h"
2728
#include <cmath> /* isnan, NAN para floatToI16 */
2829

@@ -396,6 +397,25 @@ void test_floatToI16_roundtrip(void) {
396397
TEST_ASSERT_EQUAL_FLOAT( 0.01f, i16ToFloat(floatToI16( 0.01f)));
397398
}
398399

400+
/* ── parseFloat (inline, replaces atof/toFloat) ────────────────── */
401+
void test_parseFloat_basic(void) {
402+
TEST_ASSERT_FLOAT_WITHIN(0.001f, 0.0f, parseFloat("0"));
403+
TEST_ASSERT_FLOAT_WITHIN(0.001f, 0.0f, parseFloat("0.0"));
404+
TEST_ASSERT_FLOAT_WITHIN(0.001f, 3.14f, parseFloat("3.14"));
405+
TEST_ASSERT_FLOAT_WITHIN(0.001f, -2.5f, parseFloat("-2.5"));
406+
TEST_ASSERT_FLOAT_WITHIN(0.001f, 100.0f, parseFloat("100"));
407+
TEST_ASSERT_FLOAT_WITHIN(0.001f, 0.5f, parseFloat(".5"));
408+
TEST_ASSERT_FLOAT_WITHIN(0.001f, -0.5f, parseFloat("-.5"));
409+
TEST_ASSERT_FLOAT_WITHIN(0.001f, 0.0f, parseFloat("-0.0"));
410+
}
411+
void test_parseFloat_edge(void) {
412+
TEST_ASSERT_TRUE(isnan(parseFloat(nullptr)));
413+
TEST_ASSERT_TRUE(isnan(parseFloat("")));
414+
TEST_ASSERT_FLOAT_WITHIN(0.001f, 0.0f, parseFloat("abc"));
415+
TEST_ASSERT_FLOAT_WITHIN(0.001f, 5.0f, parseFloat("5.0"));
416+
TEST_ASSERT_FLOAT_WITHIN(0.01f, 12.75f, parseFloat("12.75"));
417+
}
418+
399419

400420
/* =========================================================================== */
401421
/* MAIN */
@@ -442,6 +462,10 @@ int main(int /*argc*/, char** /*argv*/) {
442462
RUN_TEST(test_floatToI16_nan);
443463
RUN_TEST(test_i16ToFloat_basic);
444464
RUN_TEST(test_i16ToFloat_nan);
465+
466+
/* parseFloat */
467+
RUN_TEST(test_parseFloat_basic);
468+
RUN_TEST(test_parseFloat_edge);
445469
RUN_TEST(test_floatToI16_roundtrip);
446470

447471
return UNITY_END();

0 commit comments

Comments
 (0)