From eab8a6d96b6f5b5fd8193e72ea83ca80104260f0 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Sat, 16 Jul 2022 19:37:30 +0200 Subject: [PATCH] fix false value if analog + dighybrid on last digit if previous >=9.5 --- .../jomjol_flowcontroll/ClassFlowCNNGeneral.cpp | 17 +++++++++++------ .../test_cnnflowcontroll.cpp | 11 +++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 7653a947..72bcd63b 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -181,7 +181,7 @@ int ClassFlowCNNGeneral::ZeigerEvalHybrid(float zahl, float zahl_vorgaenger, int return ((int) trunc(zahl) + 10) % 10; } - if ((zahl_vorgaenger >= 0.5 ) && (zahl_vorgaenger <= 9.5)) + if ((zahl_vorgaenger >= 0.5 ) && (zahl_vorgaenger < 9.5)) { // kein Ziffernwechsel, da Vorkomma weit genug weg ist (0+/-0.5) --> zahl wird gerundet return ((int) round(zahl) + 10) % 10; @@ -197,7 +197,9 @@ int ClassFlowCNNGeneral::ZeigerEvalHybrid(float zahl, float zahl_vorgaenger, int } else // bleibt nur >= 9.5 --> noch kein Nulldurchgang --> 2.8 --> 2, und 3.1 --> 2 { - if (ergebnis_nachkomma > 5) + // hier auf 4 reduziert, da erst ab Vorgänder 9 anfängt umzustellen. Bei 9.5 Vorgänger kann die aktuelle + // Zahl noch x.4 - x.5 sein. + if (ergebnis_nachkomma >= 4) return ergebnis_vorkomma; else return (ergebnis_vorkomma - 1 + 10) % 10; @@ -239,10 +241,11 @@ int ClassFlowCNNGeneral::ZeigerEvalHybrid(float zahl, float zahl_vorgaenger, int int ClassFlowCNNGeneral::ZeigerEval(float zahl, int ziffer_vorgaenger) -{ +{ int ergebnis_nachkomma = ((int) floor(zahl * 10) + 10) % 10; int ergebnis_vorkomma = ((int) floor(zahl) + 10) % 10; - int ergebnis, ergebnis_rating; + int ergebnis; + float ergebnis_rating; if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEval erg_v=" + std::to_string(ergebnis_vorkomma) + ", erg_n=" + std::to_string(ergebnis_nachkomma) + ", ziff_v=" + std::to_string(ziffer_vorgaenger)); if (ziffer_vorgaenger == -1) @@ -250,10 +253,12 @@ int ClassFlowCNNGeneral::ZeigerEval(float zahl, int ziffer_vorgaenger) // Ist die aktuelle Stelle schon umgesprungen und die Vorstelle noch nicht? // Akt.: 2.1, Vorstelle = 0.9 => 1.9 + // Problem sind mehrere Rundungen + // Bsp. zahl=4.5, Vorgänger= 9.6 (ziffer_vorgaenger=0) + // Tritt nur auf bei Übergang von analog auf digit ergebnis_rating = ergebnis_nachkomma - ziffer_vorgaenger; - if (ergebnis_nachkomma >= 5) - ergebnis_rating-=5; + ergebnis_rating-=5.1; else ergebnis_rating+=5; ergebnis = (int) round(zahl); diff --git a/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp b/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp index f9bd6771..18129ada 100644 --- a/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp +++ b/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp @@ -41,6 +41,9 @@ void test_ZeigerEval() // the 4.4 (digital100) is not above 5 and the previous digit (analog) too (9.3) TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(4.4, 9)); + // the 4.5 (digital100) is not above 5 and the previous digit (analog) too (9.6) + TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(4.5, 0)); + } /** @@ -77,5 +80,13 @@ void test_ZeigerEvalHybrid() { // the 5.7 with previous and the previous >=9.5 should trunc to 5 TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.7, 9.6, 9)); + // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6) + TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.6, 0)); + + // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6) + TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.6, 9)); + // the 4.4 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5) + TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.5, 9)); + }