Просмотр исходного кода

Fix negatives on extended resolution false #2744 (#2772)

* not extended resolution allows -1 on the lowest digit

* not extended resolution allows -1 on the lowest number

* negatives on last value digit with -1 will set to prevalue and is not an error  #2744

---------

Co-authored-by: jomjol <30766535+jomjol@users.noreply.github.com>
Frank Haverland 2 лет назад
Родитель
Сommit
6fca4d8d95

+ 10 - 6
code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp

@@ -871,12 +871,16 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
                     LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Neg: value=" + std::to_string(NUMBERS[j]->Value) 
                                                     + ", preValue=" + std::to_string(NUMBERS[j]->PreValue) 
                                                     + ", preToll=" + std::to_string(NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))));
-                }
-                // Include inaccuracy of 0.2 for isExtendedResolution.
-                if (NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))) && NUMBERS[j]->isExtendedResolution) {
-                    NUMBERS[j]->Value = NUMBERS[j]->PreValue;
-                    NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->PreValue);
-                } else {
+                } 
+
+                    // Include inaccuracy of 0.2 for isExtendedResolution.
+                if ((NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))) && NUMBERS[j]->isExtendedResolution)
+                    // not extended resolution allows -1 on the lowest digit  
+                   || (NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(1/pow(10, NUMBERS[j]->Nachkomma))) && !NUMBERS[j]->isExtendedResolution)) {
+                        NUMBERS[j]->Value = NUMBERS[j]->PreValue;
+                        NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->PreValue);
+                } 
+                else {
                     NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " "; 
                     NUMBERS[j]->Value = NUMBERS[j]->PreValue;
                     NUMBERS[j]->ReturnValue = "";

+ 21 - 10
code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp

@@ -51,21 +51,32 @@ void testNegative() {
         delete underTestPost;
 
         // extendResolution=false
-        // value < preValue
-        preValue = 16.99; // zu groß
+        // value < (preValue -.01)
+        preValue = 17.00; // zu groß
         underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
         setAllowNegatives(underTestPost, false);
-        setPreValue(underTestPost, preValue_extended);
+        setPreValue(underTestPost, preValue);
         result = process_doFlow(underTestPost);
-        TEST_ASSERT_EQUAL_STRING("Neg. Rate - Read:  - Raw: 16.98 - Pre: 16.99 ", underTestPost->getReadoutError().c_str());
+        TEST_ASSERT_EQUAL_STRING("Neg. Rate - Read:  - Raw: 16.98 - Pre: 17.00 ", underTestPost->getReadoutError().c_str());
         TEST_ASSERT_EQUAL_STRING("", result.c_str());
         delete underTestPost;
 
+        // extendResolution=false
+        // value > (preValue -.01)
+        // ist im Rahmen der Ungenauigkeit (-1 auf letzter Stelle)
+        preValue = 16.99; // zu groß
+        underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
+        setAllowNegatives(underTestPost, false);
+        setPreValue(underTestPost, preValue);
+        result = process_doFlow(underTestPost);
+        TEST_ASSERT_EQUAL_STRING("no error", underTestPost->getReadoutError().c_str());
+        TEST_ASSERT_EQUAL_STRING("16.99", result.c_str());
+        delete underTestPost;
 
         // extendResolution=false
         // value < preValue
         // Aber Prüfung abgeschaltet => kein Fehler
-        preValue = 16.99; // zu groß
+        preValue = 17.99; // zu groß
         underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
         setAllowNegatives(underTestPost, true);
         setPreValue(underTestPost, preValue_extended);
@@ -84,8 +95,8 @@ void testNegative_Issues() {
         // Ohne decimal_shift
         std::vector<float> digits = { 2.0, 2.0, 0.0, 1.0, 7.2, 9.0, 8.0};
         std::vector<float> analogs = { };
-        double preValue_extended = 22018.080;
-        double preValue = 22018.08;
+        double preValue_extended = 22018.090;
+        double preValue = 22018.09;
         
         const char* expected = "22017.98";
 
@@ -93,13 +104,13 @@ void testNegative_Issues() {
         // extendResolution=false
         // value < preValue
         // Prüfung eingeschaltet => Fehler
-        preValue = 22018.08; // zu groß
+        preValue = 22018.09; // zu groß
         UnderTestPost* underTestPost = init_do_flow(analogs, digits, Digital100, false, false, -2);
         setAllowNegatives(underTestPost, false);
         setPreValue(underTestPost, preValue_extended);
         std::string result = process_doFlow(underTestPost);
-        TEST_ASSERT_EQUAL_STRING("Neg. Rate - Read:  - Raw: 22017.98 - Pre: 22018.08 ", underTestPost->getReadoutError().c_str());
-        TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
+        TEST_ASSERT_EQUAL_STRING("Neg. Rate - Read:  - Raw: 22017.98 - Pre: 22018.09 ", underTestPost->getReadoutError().c_str());
+        TEST_ASSERT_EQUAL_STRING("", result.c_str());
         delete underTestPost;
 
 }

+ 20 - 7
code/test/test_suite_flowcontroll.cpp

@@ -149,11 +149,24 @@ void task_UnityTesting(void *pvParameter)
  */
 extern "C" void app_main()
 {
-    initGPIO();
-    Init_NVS_SDCard();
-    esp_log_level_set("*", ESP_LOG_DEBUG);        // set all components to DEBUG level
-
-    // Create dedicated testing task (heap size can be configured - large enough to handle a lot of testing cases)
-    // ********************************************
-    xTaskCreate(&task_UnityTesting, "task_UnityTesting", 12 * 1024, NULL, tskIDLE_PRIORITY+2, NULL);
+  initGPIO();
+  Init_NVS_SDCard();
+  esp_log_level_set("*", ESP_LOG_DEBUG);        // set all components to ERROR level
+
+  UNITY_BEGIN();
+    RUN_TEST(testNegative_Issues);
+   RUN_TEST(testNegative);
+   /*
+    RUN_TEST(test_analogToDigit_Standard);
+    RUN_TEST(test_analogToDigit_Transition);
+    RUN_TEST(test_doFlowPP);
+    RUN_TEST(test_doFlowPP1);
+    RUN_TEST(test_doFlowPP2);
+    RUN_TEST(test_doFlowPP3);
+    RUN_TEST(test_doFlowPP4);
+
+    // getReadoutRawString test
+    RUN_TEST(test_getReadoutRawString);
+  */
+  UNITY_END();
 }