test_PointerEvalAnalogToDigitNew.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #include <unity.h>
  2. #include <ClassFlowCNNGeneral.h>
  3. class UnderTestCNNGeneral : public ClassFlowCNNGeneral {
  4. public:
  5. UnderTestCNNGeneral( ClassFlowAlignment *_flowalign, t_CNNType _cnntype) :
  6. ClassFlowCNNGeneral(_flowalign, _cnntype) {};
  7. using ClassFlowCNNGeneral::PointerEvalAnalogToDigitNew;
  8. };
  9. /**
  10. * @brief
  11. *
  12. * Transition = x.8 - x.2 here no transition in the test cases.
  13. * Offset = dig=x.n, ana= n.y: no offset, because both "n" are the same
  14. */
  15. void test_analogToDigit_Standard() {
  16. UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digit100);
  17. // 4.8 is a "hanging" 5, i.e. it has not jumped over to 5.0.
  18. // A "hanging digit" should still be rounded from Transition.
  19. // Transition = yes
  20. // Offset = no
  21. TEST_ASSERT_EQUAL_INT(5, undertest->PointerEvalAnalogToDigitNew(4.8, 8.0, 8, 9.2));
  22. // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issue-1344032217
  23. // Default: dig=9.6, ana=6.8 => erg=9
  24. // Transition = no
  25. // Offset = no
  26. TEST_ASSERT_EQUAL_INT(9, undertest->PointerEvalAnalogToDigitNew( 9.6, 6.8, 6, 9.2));
  27. // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1220365920
  28. // Default: dig=4.6, ana=6.2 => erg=4
  29. // Transition = no
  30. // Offset = no
  31. TEST_ASSERT_EQUAL_INT(4, undertest->PointerEvalAnalogToDigitNew( 4.6, 6.2, 6, 9.2));
  32. // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805
  33. // Hanging digit ()
  34. // Default: dig=6.8, ana=8.6 => erg=7
  35. // Transition = no
  36. // Offset = no
  37. TEST_ASSERT_EQUAL_INT(7, undertest->PointerEvalAnalogToDigitNew( 6.8, 8.6, 6, 9.2));
  38. // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805
  39. // Also hanging digit () with small pointer after 0 pass.
  40. // Default: dig=6.8, ana=1.0 => erg=7
  41. // Transition = no
  42. // Offset = no
  43. TEST_ASSERT_EQUAL_INT(7, undertest->PointerEvalAnalogToDigitNew( 6.8, 1.0, 1, 9.2));
  44. }
  45. void test_analogToDigit_Transition() {
  46. UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digit100);
  47. // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1222672175
  48. // Default: dig=3.9, ana=9.7 => erg=3
  49. // Transition = yes
  50. // Zero crossing = no
  51. // Offset = no
  52. TEST_ASSERT_EQUAL_INT(3, undertest->PointerEvalAnalogToDigitNew( 3.9, 9.7, 9, 9.2));
  53. // without reference
  54. // Default: dig=4.0, ana=9.1 => erg=4
  55. // Transition = yes
  56. // Zero crossing = no
  57. // Offset = no
  58. // Special feature: Digit has not yet started at analogue 9.1
  59. TEST_ASSERT_EQUAL_INT(4, undertest->PointerEvalAnalogToDigitNew( 4.0, 9.1, 9, 9.2));
  60. // without reference
  61. // Default: dig=9.8, ana=0.1, ana_2=9.9 => erg=9
  62. // transition = yes
  63. // Zero crossing = no
  64. // Offset = no
  65. // Special feature: analogue is set back to 9 by previous analogue
  66. TEST_ASSERT_EQUAL_INT(9, undertest->PointerEvalAnalogToDigitNew( 9.8, 0.1, 9, 9.2));
  67. // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1277425333
  68. // Default: dig=5.9, ana=9.4 => erg=9
  69. // Transition = yes
  70. // Zero crossing = no
  71. // Offset = no
  72. // Special feature:
  73. TEST_ASSERT_EQUAL_INT(5, undertest->PointerEvalAnalogToDigitNew( 5.9, 9.4, 9, 9.2));
  74. // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030
  75. // Default: dig=1.8, ana=7.8 => erg=9
  76. // Transition = yes
  77. // Zero crossing = no
  78. // Offset = no
  79. // Special feature: Digit runs with analogue. Therefore 1.8 (vs. 7.8)
  80. TEST_ASSERT_EQUAL_INT(1, undertest->PointerEvalAnalogToDigitNew( 1.8, 7.8, 7, 7.7));
  81. }
  82. /**
  83. * @brief Last digit drum geared continuously to the first analog pointer
  84. * (drum = digit + pointer/10), evaluated with ContinuousLastDigit = true.
  85. *
  86. * Readings from a meter with such a drum (dig-cont / ana-cont models):
  87. * the drum reads x.6 at pointer 6, x.8 at pointer 8 and a clean (x+1).0
  88. * at pointer 9.5 .. 9.99, before the pointer has passed 0.
  89. */
  90. void test_analogToDigit_ContinuousLastDigit() {
  91. UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digit100);
  92. // Drum already shows the next number while the pointer is just before 0.
  93. // Default: dig=8.0, ana=9.88 => erg=8 (raw value 1 m³ too high)
  94. TEST_ASSERT_EQUAL_INT(8, undertest->PointerEvalAnalogToDigitNew( 8.0, 9.88, 9, 9.2));
  95. // Continuous: 8.0 - 0.988 = 7.01 => erg=7
  96. TEST_ASSERT_EQUAL_INT(7, undertest->PointerEvalAnalogToDigitNew( 8.0, 9.88, 9, 9.2, true));
  97. // Mid-turn, drum at x.6 .. x.8 with the pointer at 6 .. 7
  98. // Default with AnalogToDigitTransitionStart 9.2: dig=7.8, ana=6.3 => erg=8
  99. TEST_ASSERT_EQUAL_INT(8, undertest->PointerEvalAnalogToDigitNew( 7.8, 6.3, 6, 9.2));
  100. TEST_ASSERT_EQUAL_INT(7, undertest->PointerEvalAnalogToDigitNew( 7.8, 6.3, 6, 9.2, true));
  101. TEST_ASSERT_EQUAL_INT(7, undertest->PointerEvalAnalogToDigitNew( 7.6, 6.0, 6, 9.2, true));
  102. // After the pointer passed 0 the drum shows the new number
  103. TEST_ASSERT_EQUAL_INT(8, undertest->PointerEvalAnalogToDigitNew( 8.0, 0.1, 0, 9.2, true));
  104. TEST_ASSERT_EQUAL_INT(8, undertest->PointerEvalAnalogToDigitNew( 8.2, 2.2, 2, 9.2, true));
  105. // Wrap around 9 <-> 0 in both directions
  106. // Drum just below 0, pointer just past 0 => erg=0
  107. TEST_ASSERT_EQUAL_INT(0, undertest->PointerEvalAnalogToDigitNew( 9.996, 0.05, 0, 9.2, true));
  108. // Drum just past 0, pointer not yet at 0 => erg=9
  109. TEST_ASSERT_EQUAL_INT(9, undertest->PointerEvalAnalogToDigitNew( 0.02, 9.9, 9, 9.2, true));
  110. // AnalogToDigitTransitionStart has no effect in this mode
  111. TEST_ASSERT_EQUAL_INT(7, undertest->PointerEvalAnalogToDigitNew( 8.0, 9.88, 9, 6.0, true));
  112. // Pointer read on the wrong side of 0; the analog evaluation (eval_predecessors) decides the side
  113. // Pointer reads 9.8 but has passed 0 (eval 0): 9.0 - (-0.02) => erg=9 (not 8)
  114. TEST_ASSERT_EQUAL_INT(9, undertest->PointerEvalAnalogToDigitNew( 9.0, 9.8, 0, 9.2, true));
  115. TEST_ASSERT_EQUAL_INT(0, undertest->PointerEvalAnalogToDigitNew( 0.0, 9.8, 0, 9.2, true));
  116. // Pointer reads 0.0 but has not passed 0 yet (eval 9): 8.98 - 1.0 => erg=8 (not 9)
  117. TEST_ASSERT_EQUAL_INT(8, undertest->PointerEvalAnalogToDigitNew( 8.98, 0.0, 9, 9.2, true));
  118. TEST_ASSERT_EQUAL_INT(9, undertest->PointerEvalAnalogToDigitNew( 9.98, 0.1, 9, 9.2, true));
  119. }