Skip to content

Commit

Permalink
Update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Slider0007 committed Jun 16, 2024
1 parent 92f0494 commit c239c3b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "esp_log.h"


static const char *TAG = "POSTPROC_TEST";
static const char *TAG_PPTEST = "POSTPROC_TEST";


UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType)
Expand All @@ -30,7 +30,7 @@ UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType

std::string process_doFlow(UnderTestPost* _underTestPost)
{
std::string time;
std::string time;

// run test
TEST_ASSERT_TRUE(_underTestPost->doFlow(time));
Expand All @@ -44,7 +44,7 @@ std::string process_doFlow(std::vector<float> analog, std::vector<float> digits,
{
// setup the classundertest
UnderTestPost* _undertestPost = init_do_flow(analog, digits, digType, checkConsistency, extendedResolution, decimal_shift);
ESP_LOGD(TAG, "SetupClassFlowPostprocessing completed.");
ESP_LOGD(TAG_PPTEST, "SetupClassFlowPostprocessing completed.");

std::string time;
// run test
Expand Down Expand Up @@ -94,7 +94,7 @@ UnderTestPost* init_do_flow(std::vector<float> analog, std::vector<float> digits
} else {
_undertestPost->flowAnalog = NULL;
}
ESP_LOGD(TAG, "Setting up of ROIs completed.");
ESP_LOGD(TAG_PPTEST, "Setting up of ROIs completed.");

_undertestPost->InitNUMBERS();

Expand All @@ -111,7 +111,7 @@ UnderTestPost* init_do_flow(std::vector<float> analog, std::vector<float> digits
void SetFallbackValue(UnderTestPost* _underTestPost, double _fallbackValue)
{
if (_fallbackValue > 0) {
ESP_LOGD(TAG, "fallbackValue=%f", _fallbackValue);
ESP_LOGD(TAG_PPTEST, "fallbackValue=%f", _fallbackValue);
std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
(*NUMBERS)[_n]->fallbackValue = _fallbackValue;
Expand All @@ -124,7 +124,7 @@ void SetFallbackValue(UnderTestPost* _underTestPost, double _fallbackValue)

void setAllowNegatives(UnderTestPost* _underTestPost, bool _allowNegatives)
{
ESP_LOGD(TAG, "checkConsistency=true");
ESP_LOGD(TAG_PPTEST, "checkConsistency=true");
std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
(*NUMBERS)[_n]->allowNegativeRates = _allowNegatives;
Expand All @@ -136,7 +136,7 @@ void setAllowNegatives(UnderTestPost* _underTestPost, bool _allowNegatives)
void setConsitencyCheck(UnderTestPost* _underTestPost, bool _checkConsistency)
{
if (_checkConsistency) {
ESP_LOGD(TAG, "checkConsistency=true");
ESP_LOGD(TAG_PPTEST, "checkConsistency=true");
std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
(*NUMBERS)[_n]->checkDigitIncreaseConsistency = true;
Expand All @@ -161,7 +161,7 @@ void setDecimalShift(UnderTestPost* _underTestPost, int _decimal_shift)
if (_decimal_shift!=0) {
std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
ESP_LOGD(TAG, "Setting decimal shift on number: %d to %d", _n, _decimal_shift);
ESP_LOGD(TAG_PPTEST, "Setting decimal shift on number: %d to %d", _n, _decimal_shift);
(*NUMBERS)[_n]->decimalShift = _decimal_shift;
}
}
Expand All @@ -173,7 +173,7 @@ void setAnalogdigitTransistionStart(UnderTestPost* _underTestPost, float _analog
if (_analogdigitTransistionStart!=0) {
std::vector<NumberPost*>* NUMBERS = _underTestPost->GetNumbers();
for (int _n = 0; _n < (*NUMBERS).size(); ++_n) {
ESP_LOGD(TAG, "Setting decimal shift on number: %d to %f", _n, _analogdigitTransistionStart);
ESP_LOGD(TAG_PPTEST, "Setting decimal shift on number: %d to %f", _n, _analogdigitTransistionStart);
(*NUMBERS)[_n]->analogDigitalTransitionStart = _analogdigitTransistionStart;
}
}
Expand Down
30 changes: 20 additions & 10 deletions code/test/components/openmetrics/test_openmetrics.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <unity.h>
#include "openmetrics.h"
#include "openmetrics.cpp"


void test_createMetric()
{
// simple happy path
const char *expected = "# HELP metric_name short description\n# TYPE metric_name gauge\nmetric_name 123.456\n";
std::string result = createMetric("metric_name", "short description", "gauge", "123.456");
const char *expected = "# TYPE metric_name gauge\n# HELP metric_name short description\nmetric_name 123.456\n";
std::string result = createMetric("metric_name", "gauge", "short description", "123.456");
TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
}

Expand Down Expand Up @@ -40,23 +40,33 @@ void test_createSequenceMetrics()
NumberPost *number_1 = new NumberPost;
number_1->name = "main";
number_1->sActualValue = "123.456";
number_1->sRatePerMin = "0.001";
sequences.push_back(number_1);

const std::string metricNamePrefix = "ai_on_the_edge_device";
const std::string metricName = metricNamePrefix + "_flow_value";
const std::string metricNamePrefix = "ai_on_the_edge_device_";

std::string expected1 = "# HELP " + metricName + " current value of meter readout\n# TYPE " + metricName + " gauge\n" +
metricName + "{sequence=\"" + number_1->name + "\"} " + number_1->sActualValue + "\n";
std::string expected1 = "# TYPE " + metricNamePrefix + "actual_value gauge\n# HELP " + metricNamePrefix +
"actual_value Actual value of meter\n" + metricNamePrefix + "actual_value{sequence=\"" +
number_1->name + "\"} " + number_1->sActualValue + "\n" +
"# TYPE " + metricNamePrefix + "rate_per_minute gauge\n# HELP " + metricNamePrefix +
"rate_per_minute Rate per minute of meter\n" + metricNamePrefix + "rate_per_minute{sequence=\"" +
number_1->name + "\"} " + number_1->sRatePerMin + "\n";
TEST_ASSERT_EQUAL_STRING(expected1.c_str(), createSequenceMetrics(metricNamePrefix, sequences).c_str());

NumberPost *number_2 = new NumberPost;
number_2->name = "secondary";
number_2->sActualValue = "1.0";
number_2->sRatePerMin = "0.0";
sequences.push_back(number_2);

std::string expected2 = "# HELP " + metricName + " current value of meter readout\n# TYPE " + metricName + " gauge\n" +
metricName + "{sequence=\"" + number_1->name + "\"} " + number_1->sActualValue + "\n" +
metricName + "{sequence=\"" + number_2->name + "\"} " + number_2->sActualValue + "\n";
std::string expected2 = "# TYPE " + metricNamePrefix + "actual_value gauge\n# HELP " + metricNamePrefix +
"actual_value Actual value of meter\n" + metricNamePrefix + "actual_value{sequence=\"" +
number_1->name + "\"} " + number_1->sActualValue + "\n" + metricNamePrefix + "actual_value{sequence=\"" +
number_2->name + "\"} " + number_2->sActualValue + "\n" +
"# TYPE " + metricNamePrefix + "rate_per_minute gauge\n# HELP " + metricNamePrefix +
"rate_per_minute Rate per minute of meter\n" + metricNamePrefix + "rate_per_minute{sequence=\"" +
number_1->name + "\"} " + number_1->sRatePerMin + "\n" + metricNamePrefix + "rate_per_minute{sequence=\"" +
number_2->name + "\"} " + number_2->sRatePerMin + "\n";
TEST_ASSERT_EQUAL_STRING(expected2.c_str(), createSequenceMetrics(metricNamePrefix, sequences).c_str());
}

Expand Down

0 comments on commit c239c3b

Please sign in to comment.