test_cnnflowcontroll.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include <unity.h>
  2. #include <ClassFlowCNNGeneral.h>
  3. class UnderTest : public ClassFlowCNNGeneral {
  4. public:
  5. using ClassFlowCNNGeneral::ZeigerEval;
  6. using ClassFlowCNNGeneral::ZeigerEvalHybrid;
  7. using ClassFlowCNNGeneral::ZeigerEvalDigital;
  8. using ClassFlowCNNGeneral::ClassFlowCNNGeneral;
  9. };
  10. void setUp(void)
  11. {
  12. // set stuff up here
  13. }
  14. void tearDown(void)
  15. {
  16. // clean stuff up here
  17. }
  18. /**
  19. * @brief test if all combinations of digit
  20. * evaluation are running correctly
  21. */
  22. void test_ZeigerEval()
  23. {
  24. UnderTest undertest = UnderTest(nullptr, Digital100);
  25. // the 5.2 is already above 5.0 and the previous digit too (3)
  26. int result = undertest.ZeigerEval(5.2, 3);
  27. TEST_ASSERT_EQUAL(5, result);
  28. // the 5.2 is already above 5.0 and the previous digit not (9)
  29. // so the current digit shoult be reduced (4.9)
  30. TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(5.2, 9));
  31. // the 4.4 (digital100) is not above 5 and the previous digit (analog) too (9.3)
  32. TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(4.4, 9));
  33. // the 4.5 (digital100) is not above 5 and the previous digit (analog) too (9.6)
  34. TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(4.5, 0));
  35. // the 5.5 (digital100) is not above 6 and the previous digit (analog) not over Zero (9.7)
  36. TEST_ASSERT_EQUAL(5, undertest.ZeigerEval(5.5, 9));
  37. // the 5.0 (digital100) and the previous digit (analog) not over Zero (9.5). The transition is not completed
  38. TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(5.0, 9));
  39. }
  40. /**
  41. * @brief test if all combinations of digit
  42. * evaluation are running correctly
  43. */
  44. void test_ZeigerEvalHybrid() {
  45. UnderTest undertest = UnderTest(nullptr, Digital100);
  46. // the 5.2 and no previous should round down
  47. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.2, 0, -1));
  48. // the 5.3 and no previous should trunc to 5
  49. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.3, 0, -1));
  50. // the 5.7 and no previous should trunc to 5
  51. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.7, 0, -1));
  52. // the 5.8 and no previous should round up to 6
  53. TEST_ASSERT_EQUAL(6, undertest.ZeigerEvalHybrid(5.8, 0, -1));
  54. // the 5.7 with previous and the previous between 0.3-0.7 should round up to 6
  55. TEST_ASSERT_EQUAL(6, undertest.ZeigerEvalHybrid(5.7, 0.7, 1));
  56. // the 5.3 with previous and the previous between 0.3-0.7 should round down to 5
  57. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.3, 0.7, 1));
  58. // the 5.3 with previous and the previous <=0.5 should trunc to 5
  59. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.3, 0.1, 1));
  60. // the 5.3 with previous and the previous >=9.5 should reduce to 4
  61. TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(5.3, 9.6, 9));
  62. // the 5.7 with previous and the previous >=9.5 should trunc to 5
  63. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.7, 9.6, 9));
  64. // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6)
  65. TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.6, 0));
  66. // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.6)
  67. TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.6, 9));
  68. // the 4.5 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5)
  69. TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(4.5, 9.5, 9));
  70. //56.95797
  71. // the 4.4 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5)
  72. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.5, 9.7, 9));
  73. // the 5.0 (digital100) and the previous digit (analog) not over Zero (9.5). The transition is not completed
  74. TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(5.0, 9.7, 9));
  75. }
  76. void test_ZeigerEvalDigital() {
  77. UnderTest undertest = UnderTest(nullptr, Digital);
  78. // the 4.4 (digital100) is not above 5 and the previous digit (analog) not over Zero (9.5)
  79. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalDigital(5.0, 9.7, 9));
  80. }