test_flowpostprocessing.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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, t_CNNType digType = Digital100);
  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.
  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, 9.9, 3.7, 0.8, 6.9, 8.7};
  122. analogs = { };
  123. expected = "704179";
  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 = { 9.9, 6.8, 1.1, 4.7, 2.7, 6.0, 9.0, 2.8}; // changed 3.7 --> 2.7 (see picture in issue)
  128. analogs = { };
  129. expected = "7153693";
  130. result = process_doFlow(analogs, digits);
  131. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  132. // Analoger Übergang Zähler Jomjolcom/jomjol/AI-on-the-edge-device/issues/942#issuecomment-1228343319
  133. digits = { 1.0, 9.0, 4.3}; // changed 3.7 --> 2.7 (see picture in issue)
  134. analogs = { 8.9, 0.7, 8.9, 9.4 };
  135. expected = "194.9089";
  136. result = process_doFlow(analogs, digits);
  137. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  138. // Fehler bei V11.2.0
  139. // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1229552041
  140. digits = { 2.9, 7.0, 7.0, 9.1, 8.1, 8.5}; // 376.9884(1) als falsches Ergebnis
  141. analogs = { 4.1 };
  142. expected = "377988.4";
  143. result = process_doFlow(analogs, digits);
  144. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  145. // Fehler bei V11.2.0
  146. // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1233149877
  147. digits = { 0.0, 0.0, 7.0, 8.9}; // 79.9999(6) als falsches Ergebnis
  148. analogs = { 0.1, 0.1, 0.1, 9.6};
  149. expected = "78.9999";
  150. result = process_doFlow(analogs, digits);
  151. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  152. // Fehler bei V11.2.0
  153. // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1236119370
  154. digits = { 3.1, 9.1, 5.7}; // 9.1 führt zu falscher Erkennung eines unvollständigen Übergangs
  155. analogs = { 8.8, 6.1, 3.0, 2.0};
  156. expected = "395.8632";
  157. result = process_doFlow(analogs, digits);
  158. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  159. // Fehler bei V11.2.0
  160. // https://github.com/jomjol/AI-on-the-edge-device/discussions/950#discussion-4338615
  161. digits = { 1.0, 9.0, 9.0}; // Übergang wurde um 1 erhöht (200, statt 199)
  162. analogs = { 7.1, 4.8, 8.3};
  163. expected = "199.748";
  164. result = process_doFlow(analogs, digits, Digital);
  165. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  166. }
  167. void setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType)
  168. {
  169. // wird im doFlow verwendet
  170. flowmakeimage = new ClassFlowMakeImage(&FlowControll);
  171. FlowControll.push_back(flowmakeimage);
  172. // Die Modeltypen werden gesetzt, da keine Modelle verwendet werden.
  173. _analog = new ClassFlowCNNGeneral(nullptr, anaType);
  174. _digit = new ClassFlowCNNGeneral(nullptr, digType);
  175. undertestPost = new UnderTestPost(&FlowControll, _analog, _digit);
  176. }
  177. std::string process_doFlow(std::vector<float> analog, std::vector<float> digits, t_CNNType digType) {
  178. // setup the classundertest
  179. setUpClassFlowPostprocessing(digType, Analogue100);
  180. printf("SetupClassFlowPostprocessing completed.\n");
  181. // digits
  182. if (digits.size()>0) {
  183. general* gen_digit = _digit->GetGENERAL("default", true);
  184. gen_digit->ROI.clear();
  185. for (int i = 0; i<digits.size(); i++) {
  186. roi* digitROI = new roi();
  187. string name = "digit_" + std::to_string(i);
  188. digitROI->name = name;
  189. digitROI->result_klasse = (int) digits[i];
  190. digitROI->result_float = digits[i];
  191. gen_digit->ROI.push_back(digitROI);
  192. }
  193. }
  194. // analog
  195. if (analog.size()>0) {
  196. general* gen_analog = _analog->GetGENERAL("default", true);
  197. gen_analog->ROI.clear();
  198. for (int i = 0; i<analog.size(); i++) {
  199. roi* anaROI = new roi();
  200. string name = "ana_" + std::to_string(i);
  201. anaROI->name = name;
  202. anaROI->result_float = analog[i];
  203. gen_analog->ROI.push_back(anaROI);
  204. }
  205. }
  206. printf("Setup ROIs completed.\n");
  207. undertestPost->InitNUMBERS();
  208. string time;
  209. // run test
  210. TEST_ASSERT_TRUE(undertestPost->doFlow(time));
  211. return undertestPost->getReadout(0);
  212. }