test_flow_pp_negative.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include "test_flow_postrocess_helper.h"
  2. /**
  3. * @brief Testfall für Überprüfung allowNegatives
  4. *
  5. */
  6. void testNegative() {
  7. // Ohne decimal_shift
  8. std::vector<float> digits = { 1.2, 6.7};
  9. std::vector<float> analogs = { 9.5, 8.4};
  10. double preValue_extended = 16.985;
  11. double preValue = 16.98;
  12. const char* expected = "16.98";
  13. // extendResolution=false
  14. // da kein negativ, sollte kein Error auftreten
  15. UnderTestPost* underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  16. setAllowNegatives(underTestPost, false);
  17. setPreValue(underTestPost, preValue);
  18. std::string result = process_doFlow(underTestPost);
  19. TEST_ASSERT_EQUAL_STRING("no error", underTestPost->getReadoutError().c_str());
  20. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  21. delete underTestPost;
  22. // extendResolution=true
  23. // da negativ im Rahmen (letzte Stelle -0.2 > ergebnis), kein Error
  24. // Aber der PreValue wird gesetzt
  25. underTestPost = init_do_flow(analogs, digits, Digital100, false, true, 0);
  26. setAllowNegatives(underTestPost, false);
  27. setPreValue(underTestPost, preValue_extended);
  28. result = process_doFlow(underTestPost);
  29. TEST_ASSERT_EQUAL_STRING("no error", underTestPost->getReadoutError().c_str());
  30. TEST_ASSERT_EQUAL_STRING(RundeOutput(preValue_extended, analogs.size()+1).c_str(), result.c_str());
  31. delete underTestPost;
  32. // extendResolution=true
  33. // Tolleranz überschritten, Error wird gesetzt, kein ReturnValue
  34. preValue_extended = 16.988; // zu groß
  35. underTestPost = init_do_flow(analogs, digits, Digital100, false, true, 0);
  36. setAllowNegatives(underTestPost, false);
  37. setPreValue(underTestPost, preValue_extended);
  38. result = process_doFlow(underTestPost);
  39. TEST_ASSERT_EQUAL_STRING("Neg. Rate - Read: - Raw: 16.984 - Pre: 16.988 ", underTestPost->getReadoutError().c_str());
  40. TEST_ASSERT_EQUAL_STRING("", result.c_str());
  41. delete underTestPost;
  42. // extendResolution=false
  43. // value < (preValue -.01)
  44. preValue = 17.00; // zu groß
  45. underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  46. setAllowNegatives(underTestPost, false);
  47. setPreValue(underTestPost, preValue);
  48. result = process_doFlow(underTestPost);
  49. TEST_ASSERT_EQUAL_STRING("Neg. Rate - Read: - Raw: 16.98 - Pre: 17.00 ", underTestPost->getReadoutError().c_str());
  50. TEST_ASSERT_EQUAL_STRING("", result.c_str());
  51. delete underTestPost;
  52. // extendResolution=false
  53. // value > (preValue -.01)
  54. // ist im Rahmen der Ungenauigkeit (-1 auf letzter Stelle)
  55. preValue = 16.99; // zu groß
  56. underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  57. setAllowNegatives(underTestPost, false);
  58. setPreValue(underTestPost, preValue);
  59. result = process_doFlow(underTestPost);
  60. TEST_ASSERT_EQUAL_STRING("no error", underTestPost->getReadoutError().c_str());
  61. TEST_ASSERT_EQUAL_STRING("16.99", result.c_str());
  62. delete underTestPost;
  63. // extendResolution=false
  64. // value < preValue
  65. // Aber Prüfung abgeschaltet => kein Fehler
  66. preValue = 17.99; // zu groß
  67. underTestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  68. setAllowNegatives(underTestPost, true);
  69. setPreValue(underTestPost, preValue_extended);
  70. result = process_doFlow(underTestPost);
  71. TEST_ASSERT_EQUAL_STRING("no error", underTestPost->getReadoutError().c_str());
  72. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  73. delete underTestPost;
  74. }
  75. /**
  76. * @brief Fehlerberichte aus Issues
  77. *
  78. */
  79. void testNegative_Issues() {
  80. // Ohne decimal_shift
  81. std::vector<float> digits = { 2.0, 2.0, 0.0, 1.0, 7.2, 9.0, 8.0};
  82. std::vector<float> analogs = { };
  83. double preValue_extended = 22018.090;
  84. double preValue = 22018.09;
  85. const char* expected = "22017.98";
  86. // https://github.com/jomjol/AI-on-the-edge-device/issues/2145#issuecomment-1461899094
  87. // extendResolution=false
  88. // value < preValue
  89. // Prüfung eingeschaltet => Fehler
  90. preValue = 22018.09; // zu groß
  91. UnderTestPost* underTestPost = init_do_flow(analogs, digits, Digital100, false, false, -2);
  92. setAllowNegatives(underTestPost, false);
  93. setPreValue(underTestPost, preValue_extended);
  94. std::string result = process_doFlow(underTestPost);
  95. TEST_ASSERT_EQUAL_STRING("Neg. Rate - Read: - Raw: 22017.98 - Pre: 22018.09 ", underTestPost->getReadoutError().c_str());
  96. TEST_ASSERT_EQUAL_STRING("", result.c_str());
  97. delete underTestPost;
  98. }