diff --git a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp index 80b61bdd..be86c58a 100644 --- a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp @@ -547,6 +547,165 @@ void test_doFlowPP4() { } +std::string postProcess(std::vector digits, + std::vector analogs, + float analog2DigitalTransition=0.0, + int decimalShift=0) +{ + std::unique_ptr undertestPost(init_do_flow(std::move(analogs), + std::move(digits), + Digital100, + false, false, decimalShift)); + + setAnalogdigitTransistionStart(undertestPost.get(), analog2DigitalTransition); + return process_doFlow(undertestPost.get()); +} + +void test_doFlowLateTransition() +{ + // in these test cases, the last digit before comma turns 3.6 too late + float a2dt = 3.6; + + // meter shows 011.0210 but it already needs to be 012.0210, before transition + TEST_ASSERT_EQUAL_STRING("12.0210", postProcess({0.0, 1.0, 1.0}, {0.2, 2.2, 1.0, 0.0}, a2dt).c_str()); + + // meter shows 011.3210 but it already needs to be 012.3210, just before transition + TEST_ASSERT_EQUAL_STRING("12.3210", postProcess({0.0, 1.0, 1.2}, {3.3, 2.2, 1.0, 0.0}, a2dt).c_str()); + + // meter shows 012.4210 , this is after transition + TEST_ASSERT_EQUAL_STRING("12.4210", postProcess({0.0, 1.0, 2.0}, {4.3, 2.2, 1.0, 0.0}, a2dt).c_str()); + + // meter shows 012.987 + TEST_ASSERT_EQUAL_STRING("12.9870", postProcess({0.0, 1.0, 2.0}, {9.8, 8.7, 7.0, 0.0}, a2dt).c_str()); + + // meter shows 0012.003 + TEST_ASSERT_EQUAL_STRING("13.003", postProcess({0.0, 0.0, 1.0, 2.0}, {0.1, 0.3, 3.1}, a2dt).c_str()); + + // meter shows 0012.351 + TEST_ASSERT_EQUAL_STRING("13.351", postProcess({0.0, 0.0, 1.0, 2.8}, {3.5, 5.2, 1.1}, a2dt).c_str()); + + // meter shows 0013.421 + TEST_ASSERT_EQUAL_STRING("13.421", postProcess({0.0, 0.0, 1.0, 3.0}, {4.1, 2.2, 1.1}, a2dt).c_str()); +} + +void test_doFlowEarlyTransition() +{ + // in these test cases, the last digit before comma turns at around 7.5 + // start transition 7.0 end transition 8.0 + float a2dt = 7.5; + + // meter shows 011.0210 but it already needs to be 012.0210, before transition + TEST_ASSERT_EQUAL_STRING("12.6789", postProcess({0.0, 1.0, 2.0}, {6.7, 7.8, 8.9, 9.0}, a2dt).c_str()); + + TEST_ASSERT_EQUAL_STRING("12.7234", postProcess({0.0, 1.0, 2.4}, {7.2, 2.3, 3.4, 4.0}, a2dt).c_str()); + + TEST_ASSERT_EQUAL_STRING("12.7789", postProcess({0.0, 1.0, 2.7}, {7.7, 7.8, 8.9, 9.0}, a2dt).c_str()); + + TEST_ASSERT_EQUAL_STRING("12.8123", postProcess({0.0, 1.0, 3.0}, {8.1, 1.2, 2.3, 3.0}, a2dt).c_str()); + + TEST_ASSERT_EQUAL_STRING("13.1234", postProcess({0.0, 1.0, 3.0}, {1.2, 2.3, 3.4, 4.0}, a2dt).c_str()); +} + + +void test_doFlowEarlyTransitionEdgeCase() +{ + float a2dt = 8.; + + // THIS TEST FAILS and reports 9.50. Not sure yet why. Predecessor value seems to play in here. + TEST_ASSERT_EQUAL_STRING("99.50", postProcess({0.0, 0.0, 9.9, 9.0}, {5.0, 0.0}, a2dt).c_str()); + + TEST_ASSERT_EQUAL_STRING("99.95", postProcess({0.0, 1.0, 0.0, 0.0}, {9.5, 5.0}, a2dt).c_str()); +} + +void test_doFlowIssue2857() +{ + // reported by gec75 + float a2dt = 9.2; + int decimalShift = 3; + TEST_ASSERT_EQUAL_STRING("252090.0", postProcess({ 2.0, 5.0, 1.9}, { 0.8, 8.8, 9.9, 0.1}, + a2dt, decimalShift).c_str()); + + // reported by Kornelius777 + decimalShift = 0; + TEST_ASSERT_EQUAL_STRING("1017.8099", postProcess({ 0.0, 1.0, 0.0, 1.0, 7.0}, { 8.2, 0.9, 9.9, 9.8}, + a2dt, decimalShift).c_str()); + + // with hanging digit + TEST_ASSERT_EQUAL_STRING("1017.8099", postProcess({ 0.0, 1.0, 0.0, 1.0, 6.9}, { 8.2, 0.9, 9.9, 9.8}, + a2dt, decimalShift).c_str()); + + // and deccimal shift + decimalShift = -2; + TEST_ASSERT_EQUAL_STRING("10.178099", postProcess({ 0.0, 1.0, 0.0, 1.0, 6.9}, { 8.2, 0.9, 9.9, 9.8}, + a2dt, decimalShift).c_str()); + + + // reported by marcniedersachsen + decimalShift = 0; + TEST_ASSERT_EQUAL_STRING("778.1480", postProcess({ 0.0, 7.0, 7.0, 7.9}, { 1.4, 4.7, 8.0, 0.5}, + a2dt, decimalShift).c_str()); + + decimalShift = 3; + TEST_ASSERT_EQUAL_STRING("778148.0", postProcess({ 0.0, 7.0, 7.0, 7.9}, { 1.4, 4.7, 8.0, 0.5}, + a2dt, decimalShift).c_str()); + + // reported by ohkaja + decimalShift = 0; + TEST_ASSERT_EQUAL_STRING("1052.6669", postProcess({ 0.0, 1.0, 10.0, 4.9, 2.0}, { 6.7, 6.7, 6.9, 9.1}, + a2dt, decimalShift).c_str()); + + // FrankCGN01 + decimalShift = -3; + TEST_ASSERT_EQUAL_STRING("159.3659", postProcess({ 0.9, 4.8, 9.0, 3.0, 6.0, 5.0}, { 9.6}, + a2dt, decimalShift).c_str()); + + // THIS TEST FAILS + // THIS TEST CASE COULD BE INVALID + // + // Second test in https://github.com/jomjol/AI-on-the-edge-device/issues/2857#issuecomment-1937452352 + // The last digit seems to be falsely recongnized. It looks like a regular "2" (no transition) + // but it is recognized by the inference as "2.5". + // + // @TODO: Feedback required by @FrankCGN01 + decimalShift = -3; + TEST_ASSERT_EQUAL_STRING("159.5022", postProcess({ 0.9, 4.9, 9.0, 5.0, 0.0, 2.5}, { 2.2}, + a2dt, decimalShift).c_str()); + + // THIS TEST FAILS + // + // reported by penapena + // Note: this is a strange example, as the last digit (4.4) seems to have very early transition + // + // @TODO: The analog to digital value needs to be determined. Feed required by @penapena + decimalShift = 0; + TEST_ASSERT_EQUAL_STRING("124.4981", postProcess({ 0.0, 1.0, 2.0, 4.4}, { 5.1, 9.8, 8.3, 1.6}, + a2dt, decimalShift).c_str()); + + // reported by warnmat + decimalShift = 0; + TEST_ASSERT_EQUAL_STRING("51.653", postProcess({ 0.1, 0.1, 5.0, 1.0}, { 6.7, 5.4, 3.1}, + a2dt, decimalShift).c_str()); +} + + +void test_doFlowLateTransitionHanging() +{ + float a2dt = 3.6; + + // meter shows 012.4210 , this is after transition + TEST_ASSERT_EQUAL_STRING("12.4210", postProcess({0.0, 1.0, 1.9}, {4.3, 2.2, 1.0, 0.0}, a2dt).c_str()); + + TEST_ASSERT_EQUAL_STRING("12.6210", postProcess({0.0, 1.0, 1.9}, {6.3, 2.2, 1.0, 0.0}, a2dt).c_str()); + + TEST_ASSERT_EQUAL_STRING("13.1210", postProcess({0.0, 1.0, 1.9}, {1.2, 2.2, 1.0, 0.0}, a2dt).c_str()); + + TEST_ASSERT_EQUAL_STRING("13.3610", postProcess({0.0, 1.0, 2.5}, {3.5, 6.2, 1.0, 0.0}, a2dt).c_str()); + + TEST_ASSERT_EQUAL_STRING("13.4510", postProcess({0.0, 1.0, 3.0}, {4.5, 5.2, 1.0, 0.0}, a2dt).c_str()); + + TEST_ASSERT_EQUAL_STRING("13.4510", postProcess({0.0, 1.0, 2.9}, {4.5, 5.2, 1.0, 0.0}, a2dt).c_str()); +} + void test_doFlowPP_rainman110() {