test_flowpostprocessing.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. digits = { 1.1, 9.0, 4.0};
  82. analogs = { 6.1, 2.6, 6.25, 9.7};
  83. expected = "194.6259";
  84. result = process_doFlow(analogs, digits);
  85. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  86. digits = { 1.1, 9.0, 4.0};
  87. analogs = { 8.1, 2.6, 6.25, 9.7};
  88. expected = "194.8259";
  89. result = process_doFlow(analogs, digits);
  90. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  91. digits = { 1.1, 9.0, 4.0};
  92. analogs = { 9.1, 2.6, 6.25, 9.7};
  93. expected = "193.9259";
  94. result = process_doFlow(analogs, digits);
  95. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  96. // https://github.com/jomjol/AI-on-the-edge-device/discussions/950
  97. digits = { 1.0, 9.0, 9.0};
  98. analogs = { 7.1, 4.8, 8.3};
  99. expected = "199.748";
  100. result = process_doFlow(analogs, digits);
  101. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  102. // https://github.com/jomjol/AI-on-the-edge-device/issues/948
  103. digits = { 1.0, 9.0, 9.0};
  104. analogs = { 7.1, 4.8, 8.3};
  105. expected = "199.748";
  106. result = process_doFlow(analogs, digits);
  107. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  108. // https://github.com/jomjol/AI-on-the-edge-device/issues/942#issuecomment-1226966346
  109. digits = { 0.0, 2.9, 3.0, 2.9, 3.5, 9.5};
  110. analogs = { };
  111. expected = "33330";
  112. result = process_doFlow(analogs, digits);
  113. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  114. // https://github.com/jomjol/AI-on-the-edge-device/issues/942#issuecomment-1226966346
  115. digits = { 9.9, 2.8, 2.9, 2.9, 3.7, 9.7};
  116. analogs = { };
  117. expected = "33340";
  118. result = process_doFlow(analogs, digits);
  119. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  120. // https://github.com/jomjol/AI-on-the-edge-device/issues/942
  121. digits = { 0.0, 9.9, 6.8, 3.7, 0.8, 6.9, 8.7};
  122. analogs = { };
  123. expected = "73179";
  124. result = process_doFlow(analogs, digits);
  125. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  126. // https://github.com/jomjol/AI-on-the-edge-device/issues/942#issuecomment-1228343319
  127. digits = { 0.0, 7.0, 1.1, 4.7, 3.7, 5.9, 9.0, 2.7};
  128. analogs = { };
  129. expected = "7153693";
  130. result = process_doFlow(analogs, digits);
  131. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  132. }
  133. void setUpClassFlowPostprocessing(void)
  134. {
  135. // wird im doFlow verwendet
  136. flowmakeimage = new ClassFlowMakeImage(&FlowControll);
  137. FlowControll.push_back(flowmakeimage);
  138. // Die Modeltypen werden gesetzt, da keine Modelle verwendet werden.
  139. _analog = new ClassFlowCNNGeneral(nullptr, Analogue100);
  140. _digit = new ClassFlowCNNGeneral(nullptr, Digital100);
  141. undertestPost = new UnderTestPost(&FlowControll, _analog, _digit);
  142. }
  143. std::string process_doFlow(std::vector<float> analog, std::vector<float> digits) {
  144. // setup the classundertest
  145. setUpClassFlowPostprocessing();
  146. printf("SetupClassFlowPostprocessing completed.\n");
  147. // digits
  148. if (digits.size()>0) {
  149. general* gen_digit = _digit->GetGENERAL("default", true);
  150. gen_digit->ROI.clear();
  151. for (int i = 0; i<digits.size(); i++) {
  152. roi* digitROI = new roi();
  153. string name = "digit_" + std::to_string(i);
  154. digitROI->name = name;
  155. digitROI->result_float = digits[i];
  156. gen_digit->ROI.push_back(digitROI);
  157. }
  158. }
  159. // analog
  160. if (analog.size()>0) {
  161. general* gen_analog = _analog->GetGENERAL("default", true);
  162. gen_analog->ROI.clear();
  163. for (int i = 0; i<analog.size(); i++) {
  164. roi* anaROI = new roi();
  165. string name = "ana_" + std::to_string(i);
  166. anaROI->name = name;
  167. anaROI->result_float = analog[i];
  168. gen_analog->ROI.push_back(anaROI);
  169. }
  170. }
  171. printf("Setup ROIs completed.\n");
  172. undertestPost->InitNUMBERS();
  173. string time;
  174. // run test
  175. TEST_ASSERT_TRUE(undertestPost->doFlow(time));
  176. return undertestPost->getReadout(0);
  177. }