test_cnnflowcontroll.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <unity.h>
  2. #include <ClassFlowCNNGeneral.h>
  3. class UnderTestCNN : public ClassFlowCNNGeneral {
  4. public:
  5. using ClassFlowCNNGeneral::ZeigerEval;
  6. using ClassFlowCNNGeneral::ZeigerEvalHybrid;
  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. int result = undertest.ZeigerEval(5.2, 3);
  18. TEST_ASSERT_EQUAL(5, result);
  19. // the 5.2 is already above 5.0 and the previous digit not (9)
  20. // so the current digit shoult be reduced (4.9)
  21. TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(5.2, 9));
  22. // the 4.4 (digital100) is not above 5 and the previous digit (analog) too (9.3)
  23. TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(4.4, 9));
  24. // the 4.5 (digital100) is not above 5 and the previous digit (analog) too (9.6)
  25. TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(4.5, 0));
  26. }
  27. /**
  28. * @brief test if all combinations of digit
  29. * evaluation are running correctly
  30. */
  31. void test_ZeigerEvalHybrid() {
  32. UnderTestCNN undertest = UnderTestCNN(nullptr, Digital100);
  33. // the 5.2 and no previous should round down
  34. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.2, 0, -1));
  35. // the 5.3 and no previous should trunc to 5
  36. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.3, 0, -1));
  37. // the 5.7 and no previous should trunc to 5
  38. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.7, 0, -1));
  39. // the 5.8 and no previous should round up to 6
  40. TEST_ASSERT_EQUAL(6, undertest.ZeigerEvalHybrid(5.8, 0, -1));
  41. // the 5.7 with previous and the previous between 0.3-0.5 should round up to 6
  42. TEST_ASSERT_EQUAL(6, undertest.ZeigerEvalHybrid(5.7, 0.4, 1));
  43. // the 5.3 with previous and the previous between 0.3-0.7 should round down to 5
  44. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.3, 0.7, 1));
  45. // the 5.3 with previous and the previous <=0.5 should trunc to 5
  46. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.3, 0.1, 1));
  47. // the 5.3 with previous and the previous >=9.5 should reduce to 4
  48. TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(5.3, 9.6, 9));
  49. // the 5.7 with previous and the previous >=9.5 should trunc to 5
  50. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.7, 9.6, 9));
  51. // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6)
  52. TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.6, 0));
  53. // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6)
  54. TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.6, 9));
  55. // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5)
  56. TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.5, 9));
  57. // 59.96889 - Pre: 58.94888
  58. // 8.6 : 9.8 : 6.7
  59. // the 4.4 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5)
  60. TEST_ASSERT_EQUAL(8, undertest.ZeigerEvalHybrid(8.6, 9.8, 9));
  61. // pre = 9.9 (0.0 raw)
  62. // zahl = 1.8
  63. TEST_ASSERT_EQUAL(1, undertest.ZeigerEvalHybrid(1.8, 9.0, 9));
  64. // if a digit have an early transition and the pointer is < 9.0
  65. // prev (pointer) = 6.2, but on digital readout = 6.0 (prev is int parameter)
  66. // zahl = 4.6
  67. TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.6, 6.0, 6));
  68. // issue #879 vorgaenger is -1, zahl = 6.7
  69. //TEST_ASSERT_EQUAL(7, undertest.ZeigerEvalHybrid(6.7, -1.0, -1));
  70. }