From b8e7bac586db110254142bea495ad72b5d0bac15 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 25 Nov 2018 22:20:57 -0500 Subject: [PATCH] unit test for atoff() --- firmware/util/efilib.cpp | 8 ++++++-- unit_tests/main.cpp | 4 ++-- unit_tests/test_util.cpp | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/firmware/util/efilib.cpp b/firmware/util/efilib.cpp index 9b942356aa..f42ec023d9 100644 --- a/firmware/util/efilib.cpp +++ b/firmware/util/efilib.cpp @@ -209,7 +209,7 @@ int efiPow10(int param) { } /** - * string to float. NaN input is not supported + * string to float. NaN input is supported * * @return NAN in case of invalid string * todo: explicit value for error code? probably not, NaN is only returned in case of an error @@ -220,9 +220,13 @@ float atoff(const char *param) { return (float) NAN; strcpy(todofixthismesswithcopy, param); char *string = todofixthismesswithcopy; + if (indexOf(string, 'n') != -1 || indexOf(string, 'N') != -1) { + printf("NAN from [%s]\r\n", string); + return (float) NAN; + } // todo: is there a standard function? - // todo: create a unit test + // unit-tested by 'testMisc()' int dotIndex = indexOf(string, '.'); if (dotIndex == -1) { // just an integer diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index 72c7ac151b..4dff2df687 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -61,6 +61,7 @@ extern bool printTriggerDebug; int main(void) { // printTriggerDebug = true; + testMisc(); testDifferentInjectionModes(); testPidAutoZigZag(); testMissedSpark299(); @@ -76,7 +77,6 @@ int main(void) { testFasterEngineSpinningUp(); testInterpolate2d(); testGpsParser(); - testMisc(); testFuelMap(); testFuelCut(); testEngineMath(); @@ -114,7 +114,7 @@ int main(void) { testTriggerDecoder(); // resizeMap(); - printf("Success 20180120\r\n"); + printf("Success 20181120\r\n"); printAllTriggers(); // printConvertedTable(); return EXIT_SUCCESS; diff --git a/unit_tests/test_util.cpp b/unit_tests/test_util.cpp index 8bc51ca72e..05bf3714c8 100644 --- a/unit_tests/test_util.cpp +++ b/unit_tests/test_util.cpp @@ -407,6 +407,10 @@ void testMisc(void) { assertTrue(strEqual("ab", efiTrim(buff))); + { + float v = atoff("1.0"); + assertEqualsM("atoff", 1.0, v); + } { float v = atoff("nan"); assertTrueM("NaN atoff", cisnan(v));