test_flow_postrocess_helper.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "test_flow_postrocess_helper.h"
  2. UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType)
  3. {
  4. ClassFlowCNNGeneral* _analog;
  5. ClassFlowCNNGeneral* _digit;
  6. std::vector<ClassFlow*> FlowControll;
  7. ClassFlowMakeImage* flowmakeimage;
  8. // wird im doFlow verwendet
  9. flowmakeimage = new ClassFlowMakeImage(&FlowControll);
  10. FlowControll.push_back(flowmakeimage);
  11. // Die Modeltypen werden gesetzt, da keine Modelle verwendet werden.
  12. _analog = new ClassFlowCNNGeneral(nullptr, anaType);
  13. _digit = new ClassFlowCNNGeneral(nullptr, digType);
  14. return new UnderTestPost(&FlowControll, _analog, _digit);
  15. }
  16. std::string process_doFlow(UnderTestPost* _underTestPost) {
  17. string time;
  18. // run test
  19. TEST_ASSERT_TRUE(_underTestPost->doFlow(time));
  20. return _underTestPost->getReadout(0);
  21. }
  22. std::string process_doFlow(std::vector<float> analog, std::vector<float> digits, t_CNNType digType,
  23. bool checkConsistency, bool extendedResolution, int decimal_shift) {
  24. // setup the classundertest
  25. UnderTestPost* _undertestPost = init_do_flow(analog, digits, digType, checkConsistency, extendedResolution, decimal_shift);
  26. printf("SetupClassFlowPostprocessing completed.\n");
  27. string time;
  28. // run test
  29. TEST_ASSERT_TRUE(_undertestPost->doFlow(time));
  30. std::string result = _undertestPost->getReadout(0);
  31. delete _undertestPost;
  32. return result;
  33. }
  34. UnderTestPost* init_do_flow(std::vector<float> analog, std::vector<float> digits, t_CNNType digType,
  35. bool checkConsistency, bool extendedResolution, int decimal_shift) {
  36. UnderTestPost* _undertestPost = setUpClassFlowPostprocessing(digType, Analogue100);
  37. // digits
  38. if (digits.size()>0) {
  39. general* gen_digit = _undertestPost->flowDigit->GetGENERAL("default", true);
  40. gen_digit->ROI.clear();
  41. for (int i = 0; i<digits.size(); i++) {
  42. roi* digitROI = new roi();
  43. string name = "digit_" + std::to_string(i);
  44. digitROI->name = name;
  45. digitROI->result_klasse = (int) digits[i];
  46. digitROI->result_float = digits[i];
  47. gen_digit->ROI.push_back(digitROI);
  48. }
  49. }
  50. // analog
  51. if (analog.size()>0) {
  52. general* gen_analog = _undertestPost->flowAnalog->GetGENERAL("default", true);
  53. gen_analog->ROI.clear();
  54. for (int i = 0; i<analog.size(); i++) {
  55. roi* anaROI = new roi();
  56. string name = "ana_" + std::to_string(i);
  57. anaROI->name = name;
  58. anaROI->result_float = analog[i];
  59. gen_analog->ROI.push_back(anaROI);
  60. }
  61. }
  62. printf("Setting up of ROIs completed.\n");
  63. _undertestPost->InitNUMBERS();
  64. setConsitencyCheck(_undertestPost, checkConsistency);
  65. setExtendedResolution(_undertestPost, extendedResolution);
  66. setDecimalShift(_undertestPost, decimal_shift);
  67. return _undertestPost;
  68. }
  69. void setPreValue(UnderTestPost* _underTestPost, double _preValue) {
  70. if (_preValue>0) {
  71. printf("preValue=%f", _preValue);
  72. std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
  73. for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
  74. (*NUMBERS)[_n]->PreValue = _preValue;
  75. }
  76. }
  77. }
  78. void setAllowNegatives(UnderTestPost* _underTestPost, bool _allowNegatives) {
  79. printf("checkConsistency=true\n");
  80. std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
  81. for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
  82. (*NUMBERS)[_n]->AllowNegativeRates = _allowNegatives;
  83. }
  84. }
  85. void setConsitencyCheck(UnderTestPost* _underTestPost, bool _checkConsistency) {
  86. if (_checkConsistency) {
  87. printf("checkConsistency=true\n");
  88. std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
  89. for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
  90. (*NUMBERS)[_n]->checkDigitIncreaseConsistency = true;
  91. }
  92. }
  93. }
  94. void setExtendedResolution(UnderTestPost* _underTestPost, bool _extendedResolution) {
  95. if (_extendedResolution ) {
  96. std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
  97. for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
  98. (*NUMBERS)[_n]->isExtendedResolution = true;
  99. }
  100. }
  101. }
  102. void setDecimalShift(UnderTestPost* _underTestPost, int _decimal_shift) {
  103. if (_decimal_shift!=0) {
  104. std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
  105. for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
  106. printf("Setting decimal shift on number: %d to %d\n", _n, _decimal_shift);
  107. (*NUMBERS)[_n]->DecimalShift = _decimal_shift;
  108. (*NUMBERS)[_n]->DecimalShiftInitial = _decimal_shift;
  109. }
  110. }
  111. }