test_flowpostprocessing.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include <unity.h>
  2. #include <ClassFlowPostProcessing.h>
  3. #include <ClassFlowCNNGeneral.h>
  4. #include <ClassFlowCNNGeneral.h>
  5. #include <ClassFlowMakeImage.h>
  6. void setUpClassFlowPostprocessing(void);
  7. string process_doFlow(std::vector<float> analog, std::vector<float> digits);
  8. ClassFlowCNNGeneral* _analog;
  9. ClassFlowCNNGeneral* _digit;
  10. std::vector<ClassFlow*> FlowControll;
  11. ClassFlowMakeImage* flowmakeimage;
  12. class UnderTestPost : public ClassFlowPostProcessing {
  13. public:
  14. UnderTestPost(std::vector<ClassFlow*>* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit)
  15. : ClassFlowPostProcessing::ClassFlowPostProcessing(lfc, _analog, _digit) {}
  16. using ClassFlowPostProcessing::InitNUMBERS;
  17. };
  18. UnderTestPost* undertestPost;
  19. /**
  20. * @brief Testet die doFlow-Methode von ClassFlowPostprocessing
  21. * digits[] - enthält die liste der vom Model zurückgegebenen Ergebnisse (class100/cont) in der Reihenfolge von links nach rechts
  22. * analog[] - enthält die Liste der Zeiger vom Model, wie bei den digits
  23. * expected - enthält das erwartete Ergebnis, wobei der Dezimalpunkt genau zwischen digits und analog ist.
  24. *
  25. */
  26. void test_doFlow() {
  27. /*
  28. *
  29. * digit1 = 1.2
  30. * digit2 = 6.7
  31. * analog1 = 9.5
  32. * analog2 = 8.4
  33. *
  34. * Das Ergebnis sollte "16.984" sein. Bzw. 16.98 ohne Extended true
  35. */
  36. std::vector<float> digits = { 1.2, 6.7};
  37. std::vector<float> analogs = { 9.5, 8.4};
  38. const char* expected = "16.98";
  39. std::string result = process_doFlow(analogs, digits);
  40. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  41. /*
  42. * https://github.com/jomjol/AI-on-the-edge-device/issues/921
  43. *
  44. * Das Ergebnis sollte "376529.6" sein. Bzw. 16.98 ohne Extended true
  45. */
  46. digits = { 3.0, 7.0, 6.0, 5.0, 2.5, 9.6};
  47. analogs = { 6.4};
  48. expected = "376529.6";
  49. result = process_doFlow(analogs, digits);
  50. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  51. /*
  52. * https://github.com/jomjol/AI-on-the-edge-device/issues/921
  53. *
  54. * Das Ergebnis sollte "167734.6" sein. Bzw. 16.98 ohne Extended true
  55. */
  56. digits = { 1.1, 6.0, 7.0, 7.0, 3.0, 4.6};
  57. analogs = { 6.2};
  58. expected = "167734.6";
  59. result = process_doFlow(analogs, digits);
  60. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  61. /*
  62. * https://github.com/jomjol/AI-on-the-edge-device/issues/919
  63. *
  64. * Das Ergebnis sollte "58.96889" sein. Bzw. 16.98 ohne Extended true
  65. */
  66. digits = { 5.0, 8.6};
  67. analogs = { 9.8, 6.7, 8.9, 8.6, 9.8};
  68. expected = "58.96889";
  69. result = process_doFlow(analogs, digits);
  70. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  71. /*
  72. * https://github.com/jomjol/AI-on-the-edge-device/issues/921
  73. *
  74. * Das Ergebnis sollte "376529.6" sein. Bzw. 16.98 ohne Extended true
  75. */
  76. digits = { 2.9, 7.0, 6.8, 9.9, 8.0, 3.9};
  77. analogs = { 9.7};
  78. expected = "377083.9";
  79. result = process_doFlow(analogs, digits);
  80. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  81. }
  82. void setUpClassFlowPostprocessing(void)
  83. {
  84. // wird im doFlow verwendet
  85. flowmakeimage = new ClassFlowMakeImage(&FlowControll);
  86. FlowControll.push_back(flowmakeimage);
  87. // Die Modeltypen werden gesetzt, da keine Modelle verwendet werden.
  88. _analog = new ClassFlowCNNGeneral(nullptr, Analogue100);
  89. _digit = new ClassFlowCNNGeneral(nullptr, Digital100);
  90. undertestPost = new UnderTestPost(&FlowControll, _analog, _digit);
  91. }
  92. std::string process_doFlow(std::vector<float> analog, std::vector<float> digits) {
  93. // setup the classundertest
  94. setUpClassFlowPostprocessing();
  95. printf("SetupClassFlowPostprocessing completed.\n");
  96. // digits
  97. if (digits.size()>0) {
  98. general* gen_digit = _digit->GetGENERAL("default", true);
  99. gen_digit->ROI.clear();
  100. for (int i = 0; i<digits.size(); i++) {
  101. roi* digitROI = new roi();
  102. string name = "digit_" + std::to_string(i);
  103. digitROI->name = name;
  104. digitROI->result_float = digits[i];
  105. gen_digit->ROI.push_back(digitROI);
  106. }
  107. }
  108. // analog
  109. if (analog.size()>0) {
  110. general* gen_analog = _analog->GetGENERAL("default", true);
  111. gen_analog->ROI.clear();
  112. for (int i = 0; i<analog.size(); i++) {
  113. roi* anaROI = new roi();
  114. string name = "ana_" + std::to_string(i);
  115. anaROI->name = name;
  116. anaROI->result_float = analog[i];
  117. gen_analog->ROI.push_back(anaROI);
  118. }
  119. }
  120. printf("Setup ROIs completed.\n");
  121. undertestPost->InitNUMBERS();
  122. string time;
  123. // run test
  124. TEST_ASSERT_TRUE(undertestPost->doFlow(time));
  125. return undertestPost->getReadout(0);
  126. }