added testcases for #1143

cleanup the analogtodigit for better reading.
This commit is contained in:
Frank Haverland
2022-10-14 23:20:05 +02:00
parent 40e176ec28
commit 8045e0bfaf
2 changed files with 40 additions and 8 deletions

View File

@@ -234,18 +234,19 @@ int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vor
// Beispiel dig=6.8, ana=2.2 ==> dig=7 // Beispiel dig=6.8, ana=2.2 ==> dig=7
// dig=4.8, ana=5.5 => dig=4 // dig=4.8, ana=5.5 => dig=4
// Aber zwischen ziffer_vorgaenger 3..8 keine Veränderung // Vorlauf bei ergebnis_nachkomma >=0..1 und ziffer_vorgaenger 8..9
if (ergebnis_nachkomma >= 1 || (ziffer_vorgaenger>3 && ziffer_vorgaenger<8) ) { if (ergebnis_nachkomma <= 1 && ziffer_vorgaenger>=8) {
result = (ergebnis_vorkomma - 1 + 10) % 10;
} else {
// Ziffer bleibt bei x.8 oder x.9 "hängen", kommt also nicht richtig auf x.0 // Ziffer bleibt bei x.8 oder x.9 "hängen", kommt also nicht richtig auf x.0
// muss eine Rundung erfolgen // muss eine Rundung erfolgen
if (eval_vorgaenger<8 && ergebnis_nachkomma >= 7) // jedoch nicht im während der Transition (ziffer_vorgaenger>=8)
if (eval_vorgaenger<9 && ziffer_vorgaenger<8 && ergebnis_nachkomma >= 8)
result = ((int) round(zahl) + 10) % 10; result = ((int) round(zahl) + 10) % 10;
else else
result = ergebnis_vorkomma; result = ergebnis_vorkomma;
} else }
result = (ergebnis_vorkomma - 1 + 10) % 10;
if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - 9.0 --> noch kein Nulldurchgang = " + std::to_string(result) + if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - 9.0 --> noch kein Nulldurchgang = " + std::to_string(result) +
" zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe)); " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe));
return result; return result;

View File

@@ -82,7 +82,7 @@ void test_doFlow() {
TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
/* /*
* https://github.com/jomjol/AI-on-the-edge-device/issues/921 * https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1222672175
* *
* Das Ergebnis sollte "376529.6" sein. Bzw. 16.98 ohne Extended true * Das Ergebnis sollte "376529.6" sein. Bzw. 16.98 ohne Extended true
*/ */
@@ -427,6 +427,37 @@ void test_doFlow() {
result = process_doFlow(analogs, digits, Digital100, false, true, 0); result = process_doFlow(analogs, digits, Digital100, false, true, 0);
TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
// Fehler V12.0.1
// https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issue-1400807695
digits = { 7.0, 4.0, 7.0, 2.0, 7.0, 5.4, 9.4}; // 7472.749 als falsches Ergebnis
analogs = {};
expected = "7472.759";
expected_extended= "7472.7594";
// extendResolution=false
result = process_doFlow(analogs, digits, Digital100, false, false, -3);
TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
// checkConsistency=false und extendResolution=true
result = process_doFlow(analogs, digits, Digital100, false, true, -3);
TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
// Fehler V12.0.1
// https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805
digits = { 4.9, 6.9, 6.8}; // 576.8649 als falsches Ergebnis
analogs = {8.6, 6.2, 5.0, 9.0};
// fall unklar ob wirklich 577 oder 576, erst mal 577
expected = "576.8649";
expected_extended= "576.86490";
// extendResolution=false
result = process_doFlow(analogs, digits, Digital100, false, false, 0);
TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
// checkConsistency=false und extendResolution=true
result = process_doFlow(analogs, digits, Digital100, false, true, 0);
TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
} }