test_flowpostprocessing.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. #include "test_flow_postrocess_helper.h"
  2. #include <memory>
  3. /**
  4. * ACHTUNG! Die Test laufen aktuell nur mit ausgeschaltetem Debug in ClassFlowCNNGeneral
  5. *
  6. *
  7. * @brief Testet die doFlow-Methode von ClassFlowPostprocessing
  8. * digits[] - enthält die liste der vom Model zurückgegebenen Ergebnisse (class100/cont) in der Reihenfolge von links nach rechts
  9. * analog[] - enthält die Liste der Zeiger vom Model, wie bei den digits
  10. * expected - enthält das erwartete Ergebnis, wobei der Dezimalpunkt genau zwischen digits und analog ist.
  11. *
  12. */
  13. void test_doFlowPP() {
  14. /*
  15. *
  16. * digit1 = 1.2
  17. * digit2 = 6.7
  18. * analog1 = 9.5
  19. * analog2 = 8.4
  20. *
  21. * Das Ergebnis sollte "16.984" sein. Bzw. 16.98 ohne Extended true
  22. */
  23. std::vector<float> digits = { 1.2, 6.7};
  24. std::vector<float> analogs = { 9.5, 8.4};
  25. const char* expected = "16.98";
  26. //const char* expected_extended = "16.984";
  27. std::string result = process_doFlow(analogs, digits);
  28. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  29. /*
  30. * https://github.com/jomjol/AI-on-the-edge-device/issues/921#issue-1344032217
  31. *
  32. * Das Ergebnis sollte "376529.6" sein.
  33. */
  34. digits = { 3.0, 7.0, 6.0, 5.0, 2.5, 9.6};
  35. analogs = { 6.4};
  36. expected = "376529.6";
  37. result = process_doFlow(analogs, digits);
  38. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  39. /*
  40. * https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1220365920
  41. *
  42. * Das Ergebnis sollte "167734.6" sein. Bzw. 16.98 ohne Extended true
  43. */
  44. digits = { 1.1, 6.0, 7.0, 7.0, 3.0, 4.6};
  45. analogs = { 6.2};
  46. expected = "167734.6";
  47. result = process_doFlow(analogs, digits);
  48. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  49. /*
  50. * https://github.com/jomjol/AI-on-the-edge-device/issues/919
  51. *
  52. * Das Ergebnis sollte "58.96889" sein. Bzw. 16.98 ohne Extended true
  53. */
  54. digits = { 5.0, 8.6};
  55. analogs = { 9.8, 6.7, 8.9, 8.6, 9.8};
  56. expected = "58.96889";
  57. result = process_doFlow(analogs, digits);
  58. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  59. /*
  60. * https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1222672175
  61. *
  62. * Das Ergebnis sollte "376529.6" sein. Bzw. 16.98 ohne Extended true
  63. */
  64. digits = { 2.9, 7.0, 6.8, 9.9, 8.0, 3.9};
  65. analogs = { 9.7};
  66. expected = "377083.9";
  67. result = process_doFlow(analogs, digits);
  68. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  69. digits = { 1.1, 9.0, 4.0};
  70. analogs = { 6.1, 2.6, 6.25, 9.7};
  71. expected = "194.6259";
  72. result = process_doFlow(analogs, digits);
  73. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  74. digits = { 1.1, 9.0, 4.0};
  75. analogs = { 8.1, 2.6, 6.25, 9.7};
  76. expected = "194.8259";
  77. result = process_doFlow(analogs, digits);
  78. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  79. digits = { 1.1, 9.0, 4.0};
  80. analogs = { 9.1, 2.6, 6.25, 9.7};
  81. expected = "194.9259";
  82. result = process_doFlow(analogs, digits);
  83. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  84. // https://github.com/jomjol/AI-on-the-edge-device/discussions/950
  85. digits = { 1.0, 9.0, 9.0};
  86. analogs = { 7.1, 4.8, 8.3};
  87. expected = "199.748";
  88. result = process_doFlow(analogs, digits);
  89. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  90. // https://github.com/jomjol/AI-on-the-edge-device/issues/948
  91. digits = { 1.0, 9.0, 9.0};
  92. analogs = { 7.1, 4.8, 8.3};
  93. expected = "199.748";
  94. result = process_doFlow(analogs, digits);
  95. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  96. }
  97. void test_doFlowPP1() {
  98. // https://github.com/jomjol/AI-on-the-edge-device/issues/942#issuecomment-1226966346
  99. std::vector<float> digits = { 0.0, 2.9, 3.0, 2.9, 3.5, 9.5};
  100. std::vector<float> analogs = { };
  101. const char* expected = "33339";
  102. std::string result = process_doFlow(analogs, digits);
  103. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  104. // https://github.com/jomjol/AI-on-the-edge-device/issues/942#issuecomment-1226966346
  105. digits = { 9.9, 2.8, 2.9, 2.9, 3.7, 9.7};
  106. analogs = { };
  107. expected = "33339";
  108. result = process_doFlow(analogs, digits);
  109. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  110. // https://github.com/jomjol/AI-on-the-edge-device/issues/942
  111. digits = { 0.0, 9.9, 6.8, 9.9, 3.7, 0.8, 6.9, 8.7};
  112. analogs = { };
  113. expected = "704178";
  114. result = process_doFlow(analogs, digits);
  115. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  116. // https://github.com/jomjol/AI-on-the-edge-device/issues/942#issuecomment-1228343319
  117. 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)
  118. analogs = { };
  119. expected = "7153692";
  120. result = process_doFlow(analogs, digits);
  121. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  122. // Analoger Übergang Zähler Jomjolcom/jomjol/AI-on-the-edge-device/issues/942#issuecomment-1228343319
  123. digits = { 1.0, 9.0, 4.3}; // changed 3.7 --> 2.7 (see picture in issue)
  124. analogs = { 8.9, 0.7, 8.9, 9.4 };
  125. expected = "194.9089";
  126. result = process_doFlow(analogs, digits);
  127. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  128. // Fehler bei V11.2.0
  129. // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1229552041
  130. digits = { 2.9, 7.0, 7.0, 9.1, 8.1, 8.5}; // 376.9884(1) als falsches Ergebnis
  131. analogs = { 4.1 };
  132. expected = "377988.4";
  133. result = process_doFlow(analogs, digits);
  134. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  135. // Fehler bei V11.2.0
  136. // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1233149877
  137. digits = { 0.0, 0.0, 7.0, 8.9}; // 79.9999(6) als falsches Ergebnis
  138. analogs = { 0.1, 0.1, 0.1, 9.6};
  139. expected = "78.9999";
  140. result = process_doFlow(analogs, digits);
  141. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  142. // Fehler bei V11.2.0
  143. // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1236119370
  144. digits = { 3.1, 9.1, 5.7}; // 9.1 führt zu falscher Erkennung eines unvollständigen Übergangs
  145. analogs = { 8.8, 6.1, 3.0, 2.0};
  146. expected = "395.8632";
  147. result = process_doFlow(analogs, digits);
  148. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  149. }
  150. void test_doFlowPP2() {
  151. // Fehler bei V11.2.0
  152. // https://github.com/jomjol/AI-on-the-edge-device/discussions/950#discussion-4338615
  153. std::vector<float> digits = { 1.0, 9.0, 9.0}; // Übergang wurde um 1 erhöht (200, statt 199)
  154. std::vector<float> analogs = { 7.1, 4.8, 8.3};
  155. const char* expected = "199.748";
  156. std::string result = process_doFlow(analogs, digits, Digital);
  157. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  158. // Fehler bei Rolling (2002-09-09)
  159. // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1242730397
  160. digits = { 3.0, 2.0, 2.0, 8.0, 9.0, 4.0, 1.7, 9.8}; // falscher Wert 32290.420
  161. analogs = { };
  162. expected = "32289.419";
  163. const char* expected_extended= "32289.4198";
  164. // FALSCH! wegen ungenügender Präzision von NUMBERS->Value
  165. // expected_extended= "32289.4198";
  166. // extendResolution=false, checkConsistency=false
  167. result = process_doFlow(analogs, digits, Digital100, false, false, -3);
  168. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  169. // extendResolution=true
  170. result = process_doFlow(analogs, digits, Digital100, false, true, -3);
  171. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  172. // checkConsistency=true und extendResolution=true
  173. result = process_doFlow(analogs, digits, Digital100, false, true, -3);
  174. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  175. // Fehler Rolling (2022-09-10)
  176. // not documented as issue
  177. digits = { 0.0, 0.0, 7.9, 3.8}; // 84.99401 als falsches Ergebnis
  178. analogs = { 0.0, 9.4, 4.1, 0.1};
  179. expected = "83.9940";
  180. expected_extended= "83.99401";
  181. // checkConsistency=false
  182. result = process_doFlow(analogs, digits, Digital100, false);
  183. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  184. // checkConsistency=true
  185. result = process_doFlow(analogs, digits, Digital100, true);
  186. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  187. // extendResolution=true
  188. result = process_doFlow(analogs, digits, Digital100, false, true);
  189. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  190. // checkConsistency=true und extendResolution=true
  191. result = process_doFlow(analogs, digits, Digital100, false, true);
  192. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  193. // Fehler Rolling (2022-09-10)
  194. // https://github.com/jomjol/AI-on-the-edge-device/issues/994#issue-1368570945
  195. digits = { 0.0, 0.0, 1.0, 2.0, 2.8, 1.9, 2.8, 5.6}; // 123245.6 als falsches Ergebnis
  196. analogs = { };
  197. expected = "123235";
  198. expected_extended= "123235.6";
  199. // checkConsistency=true
  200. result = process_doFlow(analogs, digits, Digital100, false, false);
  201. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  202. // checkConsistency=true
  203. result = process_doFlow(analogs, digits, Digital100, true, false);
  204. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  205. // extendResolution=true
  206. result = process_doFlow(analogs, digits, Digital100, false, true);
  207. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  208. // Fehler bei V11.2.0
  209. // https://github.com/jomjol/AI-on-the-edge-device/discussions/950#discussioncomment-3661982
  210. digits = { 3.0, 2.0, 4.1, 9.0, 4.0, 6.3, 9.2}; // 3249.459 als falsches Ergebnis
  211. analogs = { };
  212. expected = "3249.469";
  213. expected_extended= "3249.4692";
  214. // checkConsistency=true
  215. result = process_doFlow(analogs, digits, Digital100, false, false, -3);
  216. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  217. // extendResolution=true
  218. result = process_doFlow(analogs, digits, Digital100, false, true, -3);
  219. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  220. // Fehler bei V11.2.0
  221. // https://github.com/jomjol/AI-on-the-edge-device/issues/1020#issue-1375648891
  222. digits = { 0.0, 2.0, 6.1, 9.2}; // 259.9227 als falsches Ergebnis
  223. analogs = { 9.0, 2.5, 2.9, 7.2};
  224. expected = "269.9227";
  225. expected_extended= "269.92272";
  226. // extendResolution=true
  227. result = process_doFlow(analogs, digits, Digital100, false, false);
  228. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  229. // checkConsistency=false und extendResolution=true
  230. result = process_doFlow(analogs, digits, Digital100, false, true);
  231. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  232. // Fehler bei V11.3.1
  233. // https://github.com/jomjol/AI-on-the-edge-device/issues/1028#issuecomment-1250239481
  234. digits = { 1.1, 6.0, 9.1, 3.0, 5.3, 9.4}; // 169.3493 als falsches Ergebnis
  235. analogs = { 3.5};
  236. expected = "169.3593";
  237. expected_extended= "169.35935";
  238. // extendResolution=false
  239. result = process_doFlow(analogs, digits, Digital100, false, false, -3);
  240. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  241. // checkConsistency=false und extendResolution=true
  242. result = process_doFlow(analogs, digits, Digital100, false, true, -3);
  243. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  244. // Fehler bei V12.0.1
  245. // Lokal
  246. digits = { 9.8, 9.8, 1.9, 0.9, 0.9, 9.9, 2.9, 4.8}; // 211.0345 als falsches Ergebnis
  247. analogs = { 5.5};
  248. expected = "211.0355";
  249. expected_extended= "211.03555";
  250. // extendResolution=false
  251. result = process_doFlow(analogs, digits, Digital100, false, false, -3);
  252. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  253. // checkConsistency=false und extendResolution=true
  254. result = process_doFlow(analogs, digits, Digital100, false, true, -3);
  255. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  256. // Fehler bei V12.0.1
  257. // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1277425333
  258. digits = { 2.2, 4.5, 5.9}; // 245.938 als falsches Ergebnis
  259. analogs = { 9.4, 3.8, 8.6};
  260. expected = "245.938";
  261. expected_extended= "245.9386";
  262. // extendResolution=false
  263. result = process_doFlow(analogs, digits, Digital100, false, false, 0);
  264. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  265. // checkConsistency=false und extendResolution=true
  266. result = process_doFlow(analogs, digits, Digital100, false, true, 0);
  267. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  268. // Fehler bei V12.0.1
  269. // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1277425333
  270. digits = { 2.2, 4.5, 5.9}; // 245.938 kein Fehler. Aber Grenzfall, deshalb mit als Test aufgenommen.
  271. analogs = { 9.4, 3.8, 8.6};
  272. expected = "245.938";
  273. expected_extended= "245.9386";
  274. // extendResolution=false
  275. result = process_doFlow(analogs, digits, Digital100, false, false, 0);
  276. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  277. // checkConsistency=false und extendResolution=true
  278. result = process_doFlow(analogs, digits, Digital100, false, true, 0);
  279. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  280. }
  281. void test_doFlowPP3() {
  282. // Fehler bei V12.0.1
  283. // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1265523710
  284. std::vector<float> digits = { 2.0, 4.0, 6.8}; // 246.2045 als falsches Ergebnis
  285. std::vector<float> analogs = { 2.2, 0.1, 4.5};
  286. const char* expected = "247.204";
  287. const char* expected_extended= "247.2045";
  288. // extendResolution=false
  289. std::string result = process_doFlow(analogs, digits, Digital100, false, false, 0);
  290. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  291. // checkConsistency=false und extendResolution=true
  292. result = process_doFlow(analogs, digits, Digital100, false, true, 0);
  293. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  294. // Fehler bei V12.0.1
  295. // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issue-1391153343
  296. digits = { 1.0, 4.0, 2.0}; // 141.9269 als falsches Ergebnis
  297. analogs = { 9.2, 2.5, 6.8, 9.0};
  298. expected = "142.9269";
  299. expected_extended= "142.92690";
  300. // extendResolution=false
  301. result = process_doFlow(analogs, digits, Digital100, false, false, 0);
  302. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  303. // checkConsistency=false und extendResolution=true
  304. result = process_doFlow(analogs, digits, Digital100, false, true, 0);
  305. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  306. // Fehler bei V12.0.1
  307. // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1262626388
  308. digits = { 1.2, 6.8, 0.0, 0.0, 5.0, 2.8}; //170.05387 als falsches Ergebnis
  309. // letztes digit läuft mit analog zeiger mit. Hier nur lösbar mit setAnalogdigitTransistionStart=7.7
  310. analogs = { 8.7};
  311. expected = "170.0528";
  312. expected_extended= "170.05287";
  313. // extendResolution=false
  314. UnderTestPost* undertestPost = init_do_flow(analogs, digits, Digital100, false, false, -3);
  315. setAnalogdigitTransistionStart(undertestPost, 7.7);
  316. result = process_doFlow(undertestPost);
  317. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  318. delete undertestPost;
  319. // checkConsistency=false und extendResolution=true
  320. undertestPost = init_do_flow(analogs, digits, Digital100, false, true, -3);
  321. setAnalogdigitTransistionStart(undertestPost, 7.7);
  322. result = process_doFlow(undertestPost);
  323. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  324. delete undertestPost;
  325. // Fehler bei rolling post V12.0.1
  326. // lokal watermeter1
  327. digits = { 0.0, 0.0, 9.0, 1.0}; //90.88174 als falsches Ergebnis
  328. analogs = {9.0, 8.0, 1.8, 7.4};
  329. expected = "91.8817";
  330. expected_extended= "91.88174";
  331. // extendResolution=false
  332. result = process_doFlow(analogs, digits, Digital100, false, false, 0);
  333. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  334. // checkConsistency=false und extendResolution=true
  335. result = process_doFlow(analogs, digits, Digital100, false, true, 0);
  336. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  337. // Fehler bei rolling post V12.0.1
  338. // lokal watermeter1
  339. digits = { 0.0, 0.0, 9.0, 1.9}; //91.38403 als falsches Ergebnis
  340. analogs = {3.6, 8.2, 3.2, 2.0};
  341. expected = "92.3832";
  342. expected_extended= "92.38320";
  343. // extendResolution=false
  344. result = process_doFlow(analogs, digits, Digital100, false, false, 0);
  345. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  346. // checkConsistency=false und extendResolution=true
  347. result = process_doFlow(analogs, digits, Digital100, false, true, 0);
  348. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  349. // Fehler V11.3.0
  350. // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issue-1400807695
  351. digits = { 7.0, 4.0, 7.0, 2.0, 7.0, 5.4, 9.4}; // 7472.749 als falsches Ergebnis
  352. analogs = {};
  353. expected = "7472.759";
  354. expected_extended= "7472.7594";
  355. // extendResolution=false
  356. result = process_doFlow(analogs, digits, Digital100, false, false, -3);
  357. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  358. // checkConsistency=false und extendResolution=true
  359. result = process_doFlow(analogs, digits, Digital100, false, true, -3);
  360. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  361. // Fehler V12.0.1
  362. // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805
  363. digits = { 4.9, 6.9, 6.8}; // 576.8649 als falsches Ergebnis
  364. analogs = {8.6, 6.2, 5.0, 9.0};
  365. expected = "577.8649";
  366. expected_extended= "577.86490";
  367. // extendResolution=false
  368. result = process_doFlow(analogs, digits, Digital100, false, false, 0);
  369. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  370. // checkConsistency=false und extendResolution=true
  371. result = process_doFlow(analogs, digits, Digital100, false, true, 0);
  372. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  373. // Fehler V12.0.1 "TODO 00211.03480 vs 00211.03580"
  374. // Lokal "Hängendes Digit"
  375. digits = { 2.0, 1.0, 1.0, 0.0, 3.0, 4.8}; // 00211.03480 als falsches Ergebnis
  376. analogs = {8.0};
  377. expected = "211.0358";
  378. expected_extended= "211.03580";
  379. // extendResolution=false
  380. result = process_doFlow(analogs, digits, Digital100, false, false, -3);
  381. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  382. // checkConsistency=false und extendResolution=true
  383. result = process_doFlow(analogs, digits, Digital100, false, true, -3);
  384. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  385. // Fehler V12.0.1
  386. // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1281231468
  387. digits = { 1.0, 1.9, 6.0}; // 125.923 als falsches Ergebnis
  388. analogs = {9.3, 2.3, 3.1};
  389. expected = "126.923";
  390. expected_extended= "126.9231";
  391. // extendResolution=false
  392. undertestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  393. setAnalogdigitTransistionStart(undertestPost, 9.4); // Extreme late transition
  394. result = process_doFlow(undertestPost);
  395. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  396. delete undertestPost;
  397. // checkConsistency=false und extendResolution=true
  398. undertestPost = init_do_flow(analogs, digits, Digital100, false, true, 0);
  399. setAnalogdigitTransistionStart(undertestPost, 9.4); // Extreme late transition
  400. result = process_doFlow(undertestPost);
  401. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  402. delete undertestPost;
  403. // Fehler V12.0.1
  404. // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030
  405. digits = { 3.0, 8.1, 5.9, 0.0, 5.0, 6.7}; // 386.05672 als richtiges Ergebnis. Letztes digit schein mit dem Analogzeiger mitzulaufen
  406. analogs = {7.2};
  407. expected = "386.0567";
  408. expected_extended= "386.05672";
  409. // extendResolution=false
  410. result = process_doFlow(analogs, digits, Digital100, false, false, -3);
  411. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  412. // checkConsistency=false und extendResolution=true
  413. result = process_doFlow(analogs, digits, Digital100, false, true, -3);
  414. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  415. // Fehler V12.0.1
  416. // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030
  417. digits = { 1.2, 7.0, 1.2, 2.0, 4.0, 1.8}; // 171.24278 als falsches Ergebnis.
  418. // Test ist nur erfolgreich mit Veränderung des AnalogdigitTransistionStart
  419. analogs = {7.8};
  420. expected = "171.2417";
  421. expected_extended= "171.24178";
  422. // extendResolution=false
  423. undertestPost = init_do_flow(analogs, digits, Digital100, false, false, -3);
  424. setAnalogdigitTransistionStart(undertestPost, 7.7);
  425. result = process_doFlow(undertestPost);
  426. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  427. delete undertestPost;
  428. // checkConsistency=false und extendResolution=true
  429. undertestPost = init_do_flow(analogs, digits, Digital100, false, true, -3);
  430. setAnalogdigitTransistionStart(undertestPost, 7.7);
  431. result = process_doFlow(undertestPost);
  432. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  433. delete undertestPost;
  434. }
  435. void test_doFlowPP4() {
  436. // Fehler V13.0.4
  437. // https://github.com/jomjol/AI-on-the-edge-device/issues/1503#issuecomment-1343335855
  438. std::vector<float> digits = { 0.0, 0.0, 6.9, 1.0, 6.6}; // 716.0199 als falsches Ergebnis.
  439. // Test ist nur erfolgreich mit Veränderung des AnalogdigitTransistionStart
  440. std::vector<float> analogs = {9.9, 1.8, 6.6, 5.8};
  441. const char* expected = "717.0165";
  442. const char* expected_extended= "717.01658";
  443. // extendResolution=false
  444. std::string result = process_doFlow(analogs, digits, Digital100, false, false);
  445. TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
  446. // checkConsistency=false und extendResolution=true
  447. result = process_doFlow(analogs, digits, Digital100, false, true);
  448. TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
  449. }
  450. std::string postProcess(std::vector<float> digits,
  451. std::vector<float> analogs,
  452. float analog2DigitalTransition=0.0,
  453. int decimalShift=0)
  454. {
  455. std::unique_ptr<UnderTestPost> undertestPost(init_do_flow(std::move(analogs),
  456. std::move(digits),
  457. Digital100,
  458. false, false, decimalShift));
  459. setAnalogdigitTransistionStart(undertestPost.get(), analog2DigitalTransition);
  460. return process_doFlow(undertestPost.get());
  461. }
  462. void test_doFlowLateTransition()
  463. {
  464. // in these test cases, the last digit before comma turns 3.6 too late
  465. float a2dt = 3.4; // value when last digit reaches x.8 region
  466. // Questionable? (Meter shows 011.0210 but it already needs to be 012.0210, before transition)
  467. // Slider0007: In my opionion this series starts clearly with 11.x
  468. // As I remember right, this is a real series from rainman110, therefore the following cases
  469. // also needs to be corrected the same way
  470. TEST_ASSERT_EQUAL_STRING("11.0210", postProcess({0.0, 1.0, 1.0}, {0.2, 2.2, 1.0, 0.0}, a2dt).c_str());
  471. // meter shows 011.3210 but it already needs to be 012.3210, just before transition
  472. TEST_ASSERT_EQUAL_STRING("11.3210", postProcess({0.0, 1.0, 1.2}, {3.3, 2.2, 1.0, 0.0}, a2dt).c_str());
  473. // meter shows 012.4210 , this is after transition
  474. TEST_ASSERT_EQUAL_STRING("11.4210", postProcess({0.0, 1.0, 2.0}, {4.3, 2.2, 1.0, 0.0}, a2dt).c_str());
  475. // meter shows 012.987
  476. TEST_ASSERT_EQUAL_STRING("11.9870", postProcess({0.0, 1.0, 2.0}, {9.8, 8.7, 7.0, 0.0}, a2dt).c_str());
  477. // meter shows 0012.003
  478. TEST_ASSERT_EQUAL_STRING("12.003", postProcess({0.0, 0.0, 1.0, 2.0}, {0.1, 0.3, 3.1}, a2dt).c_str());
  479. // meter shows 0012.351
  480. TEST_ASSERT_EQUAL_STRING("12.351", postProcess({0.0, 0.0, 1.0, 2.8}, {3.5, 5.2, 1.1}, a2dt).c_str());
  481. // meter shows 0013.421
  482. TEST_ASSERT_EQUAL_STRING("12.421", postProcess({0.0, 0.0, 1.0, 3.0}, {4.1, 2.2, 1.1}, a2dt).c_str());
  483. }
  484. void test_doFlowEarlyTransition()
  485. {
  486. // in these test cases, the last digit before comma turns at around 7.5
  487. // start transition 7.0 end transition 8.0
  488. float a2dt = 7.8; // value when last digit reaches x.8 region
  489. TEST_ASSERT_EQUAL_STRING("12.6789", postProcess({0.0, 1.0, 2.0}, {6.7, 7.8, 8.9, 9.0}, a2dt).c_str());
  490. TEST_ASSERT_EQUAL_STRING("12.7234", postProcess({0.0, 1.0, 2.4}, {7.2, 2.3, 3.4, 4.0}, a2dt).c_str());
  491. TEST_ASSERT_EQUAL_STRING("12.7789", postProcess({0.0, 1.0, 2.7}, {7.7, 7.8, 8.9, 9.0}, a2dt).c_str());
  492. TEST_ASSERT_EQUAL_STRING("12.8123", postProcess({0.0, 1.0, 3.0}, {8.1, 1.2, 2.3, 3.0}, a2dt).c_str());
  493. TEST_ASSERT_EQUAL_STRING("13.1234", postProcess({0.0, 1.0, 3.0}, {1.2, 2.3, 3.4, 4.0}, a2dt).c_str());
  494. }
  495. void test_doFlowEarlyTransitionEdgeCase()
  496. {
  497. float a2dt = 8.;
  498. // Silder0007: In my opinion this is a unrealistic case {0.0, **0.0**, 9.9, 9,0}, {5.0, 0.0}
  499. // More realistic values: {0.0, 0.9, 9.9, 9,0}, {5.0, 0.0}
  500. TEST_ASSERT_EQUAL_STRING("99.50", postProcess({0.0, 0.0, 9.0, 9.0}, {5.0, 0.0}, a2dt).c_str());
  501. // fails with 99.50
  502. TEST_ASSERT_EQUAL_STRING("199.50", postProcess({0.0, 1.0, 9.0, 9.0}, {5.0, 0.0}, a2dt).c_str());
  503. TEST_ASSERT_EQUAL_STRING("99.95", postProcess({0.0, 1.0, 0.0, 0.0}, {9.5, 5.0}, a2dt).c_str());
  504. }
  505. void test_doFlowIssue2857()
  506. {
  507. // reported by gec75
  508. float a2dt = 9.2;
  509. int decimalShift = 3;
  510. TEST_ASSERT_EQUAL_STRING("252090.0", postProcess({ 2.0, 5.0, 1.9}, { 0.8, 8.8, 9.9, 0.1},
  511. a2dt, decimalShift).c_str());
  512. // reported by Kornelius777
  513. decimalShift = 0;
  514. TEST_ASSERT_EQUAL_STRING("1017.8099", postProcess({ 0.0, 1.0, 0.0, 1.0, 7.0}, { 8.2, 0.9, 9.9, 9.8},
  515. a2dt, decimalShift).c_str());
  516. // with hanging digit
  517. TEST_ASSERT_EQUAL_STRING("1017.8099", postProcess({ 0.0, 1.0, 0.0, 1.0, 6.9}, { 8.2, 0.9, 9.9, 9.8},
  518. a2dt, decimalShift).c_str());
  519. // and deccimal shift
  520. decimalShift = -2;
  521. TEST_ASSERT_EQUAL_STRING("10.178099", postProcess({ 0.0, 1.0, 0.0, 1.0, 6.9}, { 8.2, 0.9, 9.9, 9.8},
  522. a2dt, decimalShift).c_str());
  523. // reported by marcniedersachsen
  524. decimalShift = 0;
  525. TEST_ASSERT_EQUAL_STRING("778.1480", postProcess({ 0.0, 7.0, 7.0, 7.9}, { 1.4, 4.7, 8.0, 0.5},
  526. a2dt, decimalShift).c_str());
  527. decimalShift = 3;
  528. TEST_ASSERT_EQUAL_STRING("778148.0", postProcess({ 0.0, 7.0, 7.0, 7.9}, { 1.4, 4.7, 8.0, 0.5},
  529. a2dt, decimalShift).c_str());
  530. // reported by ohkaja
  531. decimalShift = 0;
  532. TEST_ASSERT_EQUAL_STRING("1052.6669", postProcess({ 0.0, 1.0, 10.0, 4.9, 2.0}, { 6.7, 6.7, 6.9, 9.1},
  533. a2dt, decimalShift).c_str());
  534. // FrankCGN01
  535. decimalShift = -3;
  536. a2dt = 9.7;
  537. TEST_ASSERT_EQUAL_STRING("159.3659", postProcess({ 0.9, 4.8, 8.9, 3.0, 6.0, 5.0}, { 9.6},
  538. a2dt, decimalShift).c_str());
  539. // Second test in https://github.com/jomjol/AI-on-the-edge-device/issues/2857#issuecomment-1937452352
  540. // The last digit seems to be falsely recongnized. It looks like a regular "2" (no transition)
  541. // but it is recognized by the inference as "2.5".
  542. decimalShift = -3;
  543. TEST_ASSERT_EQUAL_STRING("159.5022", postProcess({ 0.9, 4.9, 8.9, 5.0, 0.0, 2.5}, { 2.2},
  544. a2dt, decimalShift).c_str());
  545. // reported by penapena
  546. // Note: this is a strange example, as the last digit (4.4) seems to have very early transition
  547. decimalShift = 0;
  548. TEST_ASSERT_EQUAL_STRING("124.4981", postProcess({ 0.0, 1.0, 2.0, 4.4}, { 5.1, 9.8, 8.3, 1.6},
  549. a2dt, decimalShift).c_str());
  550. // reported by warnmat
  551. decimalShift = 0;
  552. TEST_ASSERT_EQUAL_STRING("51.653", postProcess({ 0.1, 0.1, 5.0, 1.0}, { 6.7, 5.4, 3.1},
  553. a2dt, decimalShift).c_str());
  554. }
  555. void test_doFlowLateTransitionHanging()
  556. {
  557. float a2dt = 3.6;
  558. // haverland: this is the case if the analog pointer is a bit before the digit.
  559. // It's the normal late transition up to 2.0 on analog must the digit transition ends
  560. // After 2.0 on analog it named "hanging digit" by me. It never reach the x.0 until the next
  561. // transition begins.
  562. // BUT. It makes the issue you have later, because all other unter 3.6 are negative values now.
  563. TEST_ASSERT_EQUAL_STRING("12.1210", postProcess({0.0, 1.0, 1.9}, {1.2, 2.2, 1.0, 0.0}, a2dt).c_str());
  564. // Questionable? (meter shows 012.4210 , this is after transition)
  565. // Slider0007: In my opionion this series starts with 11.x with this a2dt value
  566. // As I remember right, this is a real series from rainman110, therefore the following cases
  567. // also needs to be corrected the same way
  568. TEST_ASSERT_EQUAL_STRING("11.4210", postProcess({0.0, 1.0, 1.9}, {4.3, 2.2, 1.0, 0.0}, a2dt).c_str());
  569. TEST_ASSERT_EQUAL_STRING("11.6210", postProcess({0.0, 1.0, 1.9}, {6.3, 2.2, 1.0, 0.0}, a2dt).c_str());
  570. TEST_ASSERT_EQUAL_STRING("12.3610", postProcess({0.0, 1.0, 2.5}, {3.5, 6.2, 1.0, 0.0}, a2dt).c_str());
  571. TEST_ASSERT_EQUAL_STRING("12.4510", postProcess({0.0, 1.0, 3.0}, {4.5, 5.2, 1.0, 0.0}, a2dt).c_str());
  572. TEST_ASSERT_EQUAL_STRING("12.4510", postProcess({0.0, 1.0, 2.9}, {4.5, 5.2, 1.0, 0.0}, a2dt).c_str());
  573. }
  574. void test_doFlowPP_rainman110()
  575. {
  576. // https://github.com/jomjol/AI-on-the-edge-device/issues/2743
  577. // --> Extreme early digit transition. AnanlogDigitTransition needs to set to 3.5 (was limited to 6)
  578. std::vector<float> digits = {4.0, 1.0, 1.8}; // wrong result: 412.3983
  579. std::vector<float> analogs = {3.6, 9.9, 8.1, 3.5};
  580. UnderTestPost* undertestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  581. setAnalogdigitTransistionStart(undertestPost, 3.5);
  582. TEST_ASSERT_EQUAL_STRING("411.3983", process_doFlow(undertestPost).c_str());
  583. delete undertestPost;
  584. // https://github.com/jomjol/AI-on-the-edge-device/pull/2887
  585. // --> Extreme early digit transition. AnanlogDigitTransition needs to set to 3.5 (was limited to 6)
  586. digits = {4.0, 1.0, 7.9}; // wrong result: 417.2579
  587. analogs = {2.5, 5.8, 7.7, 9.0};
  588. undertestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  589. setAnalogdigitTransistionStart(undertestPost, 3.5);
  590. TEST_ASSERT_EQUAL_STRING("418.2579", process_doFlow(undertestPost).c_str());
  591. delete undertestPost;
  592. // Edge Case
  593. digits = {9.9, 9.4};
  594. analogs = {5.0, 0.0};
  595. undertestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  596. setAnalogdigitTransistionStart(undertestPost, 8.0);
  597. TEST_ASSERT_EQUAL_STRING("99.50", process_doFlow(undertestPost).c_str());
  598. delete undertestPost;
  599. // Edge Case
  600. digits = {1.0, 0.0, 0.0};
  601. analogs = {9.5, 5.0};
  602. undertestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  603. setAnalogdigitTransistionStart(undertestPost, 8.0);
  604. TEST_ASSERT_EQUAL_STRING("99.95", process_doFlow(undertestPost).c_str());
  605. delete undertestPost;
  606. // https://github.com/jomjol/AI-on-the-edge-device/pull/2887
  607. // Discussion 149365.9 vs. 149364.9
  608. digits = {0.9, 4.8, 9.0, 3.0, 6.0, 5.0};
  609. analogs = {9.6};
  610. undertestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  611. setAnalogdigitTransistionStart(undertestPost, 9.2);
  612. TEST_ASSERT_EQUAL_STRING("149364.9", process_doFlow(undertestPost).c_str());
  613. delete undertestPost;
  614. }
  615. void test_doFlowPP_rainman110_transition()
  616. {
  617. // https://github.com/jomjol/AI-on-the-edge-device/pull/2887
  618. // Edge cases
  619. std::vector<float> digits = {4.0, 1.0, 7.9};
  620. std::vector<float> analogs = {1.4, 5.8, 7.7, 9.0};
  621. UnderTestPost* undertestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  622. setAnalogdigitTransistionStart(undertestPost, 3.5);
  623. std::string result = process_doFlow(undertestPost);
  624. TEST_ASSERT_EQUAL_STRING("418.1579", result.c_str());
  625. delete undertestPost;
  626. // https://github.com/jomjol/AI-on-the-edge-device/pull/2887
  627. // Edge cases
  628. digits = {4.0, 1.0, 7.9};
  629. analogs = {3.4, 5.8, 7.7, 9.0};
  630. undertestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  631. setAnalogdigitTransistionStart(undertestPost, 3.5);
  632. result = process_doFlow(undertestPost);
  633. TEST_ASSERT_EQUAL_STRING("418.3579", result.c_str());
  634. delete undertestPost;
  635. // https://github.com/jomjol/AI-on-the-edge-device/pull/2887
  636. // Edge cases
  637. digits = {4.0, 1.0, 8.5};
  638. analogs = {3.7, 5.8, 7.7, 9.0};
  639. undertestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  640. setAnalogdigitTransistionStart(undertestPost, 3.5);
  641. result = process_doFlow(undertestPost);
  642. TEST_ASSERT_EQUAL_STRING("418.3579", result.c_str());
  643. delete undertestPost;
  644. // https://github.com/jomjol/AI-on-the-edge-device/pull/2887
  645. // Edge cases
  646. digits = {4.0, 1.0, 8.9};
  647. analogs = {4.0, 5.8, 7.7, 9.0};
  648. undertestPost = init_do_flow(analogs, digits, Digital100, false, false, 0);
  649. setAnalogdigitTransistionStart(undertestPost, 3.5);
  650. result = process_doFlow(undertestPost);
  651. TEST_ASSERT_EQUAL_STRING("418.4579", result.c_str());
  652. delete undertestPost;
  653. }