test_cnnflowcontroll.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include <unity.h>
  2. #include <ClassFlowCNNGeneral.h>
  3. class UnderTestCNN : public ClassFlowCNNGeneral {
  4. public:
  5. using ClassFlowCNNGeneral::PointerEvalAnalogNew;
  6. using ClassFlowCNNGeneral::PointerEvalHybridNew;
  7. using ClassFlowCNNGeneral::ClassFlowCNNGeneral;
  8. };
  9. /**
  10. * @brief test if all combinations of digit
  11. * evaluation are running correctly
  12. */
  13. void test_ZeigerEval()
  14. {
  15. UnderTestCNN undertest = UnderTestCNN(nullptr, Digital100);
  16. // the 5.2 is already above 5.0 and the previous digit too (3)
  17. printf("Test 5.2, 3\n");
  18. int result = undertest.PointerEvalAnalogNew(5.2, 3);
  19. TEST_ASSERT_EQUAL(5, result);
  20. // the 5.2 is already above 5.0 and the previous digit not (9)
  21. // so the current digit shoult be reduced (4.9)
  22. printf("Test 5.2, 9\n");
  23. TEST_ASSERT_EQUAL(4, undertest.PointerEvalAnalogNew(5.2, 9));
  24. printf("Test 4.4, 9\n");
  25. // the 4.4 (digital100) is not above 5 and the previous digit (analog) too (9.3)
  26. TEST_ASSERT_EQUAL(4, undertest.PointerEvalAnalogNew(4.4, 9));
  27. printf("Test 4.5, 0\n");
  28. // the 4.5 (digital100) is not above 5 and the previous digit (analog) too (9.6)
  29. TEST_ASSERT_EQUAL(4, undertest.PointerEvalAnalogNew(4.5, 0));
  30. }
  31. /**
  32. * @brief test if all combinations of digit
  33. * evaluation are running correctly
  34. *
  35. * Desciption on call undertest.PointerEvalHybridNew(float number, float number_of_predecessors, int eval_predecessors, bool Analog_Predecessors, float digitalAnalogTransitionStart)
  36. * @param number: is the current ROI as float value from recognition
  37. * @param number_of_predecessors: is the last (lower) ROI as float from recognition
  38. * @param eval_predecessors: is the evaluated number. Sometimes a much lower value can change higer values
  39. * example: 9.8, 9.9, 0.1
  40. * 0.1 => 0 (eval_predecessors)
  41. * The 0 makes a 9.9 to 0 (eval_predecessors)
  42. * The 0 makes a 9.8 to 0
  43. * @param Analog_Predecessors false/true if the last ROI is an analog or digital ROI (default=false)
  44. * runs in special handling because analog is much less precise
  45. * @param digitalAnalogTransitionStart start of the transitionlogic begins on number_of_predecessor (default=9.2)
  46. *
  47. *
  48. *
  49. *
  50. */
  51. void test_ZeigerEvalHybrid() {
  52. UnderTestCNN undertest = UnderTestCNN(nullptr, Digital100);
  53. // the 5.2 and no previous should round down
  54. printf("PointerEvalHybridNew(5.2, 0, -1)\n");
  55. TEST_ASSERT_EQUAL(5, undertest.PointerEvalHybridNew(5.2, 0, -1));
  56. // the 5.3 and no previous should trunc to 5
  57. printf("PointerEvalHybridNew(5.3, 0, -1)\n");
  58. TEST_ASSERT_EQUAL(5, undertest.PointerEvalHybridNew(5.3, 0, -1));
  59. printf("PointerEvalHybridNew(5.7, 0, -1)\n");
  60. // the 5.7 and no previous should trunc to 5
  61. TEST_ASSERT_EQUAL(5, undertest.PointerEvalHybridNew(5.7, 0, -1, false, 9.2));
  62. // the 5.8 and no previous should round up to 6
  63. printf("PointerEvalHybridNew(5.8, 0, -1)\n");
  64. TEST_ASSERT_EQUAL(6, undertest.PointerEvalHybridNew(5.8, 8.0, 8, false, 8.0));
  65. // the 5.7 with previous and the previous between 0.3-0.5 should round up to 6
  66. TEST_ASSERT_EQUAL(6, undertest.PointerEvalHybridNew(5.7, 0.4, 1));
  67. // the 5.3 with previous and the previous between 0.3-0.7 should round down to 5
  68. TEST_ASSERT_EQUAL(5, undertest.PointerEvalHybridNew(5.3, 0.7, 1));
  69. // the 5.3 with previous and the previous <=0.5 should trunc to 5
  70. TEST_ASSERT_EQUAL(5, undertest.PointerEvalHybridNew(5.3, 0.1, 1));
  71. // the 5.2 with previous and the previous >=9.8 should reduce to 4
  72. // the digit is already over transistion, but a analog pointer runs behind
  73. TEST_ASSERT_EQUAL(4, undertest.PointerEvalHybridNew(5.2, 9.8, 9, false, 9.0));
  74. // the 5.7 with previous and the previous >=9.5 should trunc to 5
  75. TEST_ASSERT_EQUAL(5, undertest.PointerEvalHybridNew(5.7, 9.6, 9));
  76. // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6)
  77. TEST_ASSERT_EQUAL(4, undertest.PointerEvalHybridNew(4.5, 9.6, 0));
  78. // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6)
  79. TEST_ASSERT_EQUAL(4, undertest.PointerEvalHybridNew(4.5, 9.6, 9));
  80. // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5)
  81. TEST_ASSERT_EQUAL(4, undertest.PointerEvalHybridNew(4.5, 9.5, 9));
  82. // 59.96889 - Pre: 58.94888
  83. // 8.6 : 9.8 : 6.7
  84. // the 4.4 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5)
  85. TEST_ASSERT_EQUAL(8, undertest.PointerEvalHybridNew(8.6, 9.8, 9));
  86. // pre = 9.9 (0.0 raw)
  87. // zahl = 1.8
  88. TEST_ASSERT_EQUAL(2, undertest.PointerEvalHybridNew(1.8, 9.0, 9));
  89. // if a digit have an early transition and the pointer is < 9.0
  90. // prev (pointer) = 6.2, but on digital readout = 6.0 (prev is int parameter)
  91. // zahl = 4.6
  92. TEST_ASSERT_EQUAL(4, undertest.PointerEvalHybridNew(4.6, 6.0, 6));
  93. // issue #879 vorgaenger is -1, zahl = 6.7
  94. //TEST_ASSERT_EQUAL(7, undertest.ZeigerEvalHybrid(6.7, -1.0, -1));
  95. }