test_cnnflowcontroll.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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::ClassFlowCNNGeneral;
  8. };
  9. void setUp(void)
  10. {
  11. // set stuff up here
  12. }
  13. void tearDown(void)
  14. {
  15. // clean stuff up here
  16. }
  17. /**
  18. * @brief test if all combinations of digit
  19. * evaluation are running correctly
  20. */
  21. void test_ZeigerEval()
  22. {
  23. UnderTest undertest = UnderTest(nullptr, Digital100);
  24. // the 5.2 is already above 5.0 and the previous digit too (3)
  25. int result = undertest.ZeigerEval(5.2, 3);
  26. TEST_ASSERT_EQUAL(5, result);
  27. // the 5.2 is already above 5.0 and the previous digit not (9)
  28. // so the current digit shoult be reduced (4.9)
  29. TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(5.2, 9));
  30. // the 4.4 (digital100) is not above 5 and the previous digit (analog) too (9.3)
  31. TEST_ASSERT_EQUAL(4, undertest.ZeigerEval(4.4, 9));
  32. }
  33. /**
  34. * @brief test if all combinations of digit
  35. * evaluation are running correctly
  36. */
  37. void test_ZeigerEvalHybrid() {
  38. UnderTest undertest = UnderTest(nullptr, Digital100);
  39. // the 5.2 and no previous should round down
  40. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.2, 0, -1));
  41. // the 5.3 and no previous should trunc to 5
  42. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.3, 0, -1));
  43. // the 5.7 and no previous should trunc to 5
  44. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.7, 0, -1));
  45. // the 5.8 and no previous should round up to 6
  46. TEST_ASSERT_EQUAL(6, undertest.ZeigerEvalHybrid(5.8, 0, -1));
  47. // the 5.7 with previous and the previous between 0.3-0.7 should round up to 6
  48. TEST_ASSERT_EQUAL(6, undertest.ZeigerEvalHybrid(5.7, 0.7, 1));
  49. // the 5.3 with previous and the previous between 0.3-0.7 should round down to 5
  50. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.3, 0.7, 1));
  51. // the 5.3 with previous and the previous <=0.5 should trunc to 5
  52. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.3, 0.1, 1));
  53. // the 5.3 with previous and the previous >=9.5 should reduce to 4
  54. TEST_ASSERT_EQUAL(4, undertest.ZeigerEvalHybrid(5.3, 9.6, 9));
  55. // the 5.7 with previous and the previous >=9.5 should trunc to 5
  56. TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.7, 9.6, 9));
  57. }