3-phase PV router
Loading...
Searching...
No Matches
Mk2_3phase_RFdatalog_temp
test
native
test_ewma_avg
test_main.cpp
Go to the documentation of this file.
1
2
#include <unity.h>
3
#include "
ewma_avg.hpp
"
// Include the EWMA_average class
4
5
// 120 should be for around 10 minutes of data (period in minutes * 60 / datalog period in seconds)
6
void
test_initial_values
()
7
{
8
EWMA_average< 120 >
avg;
// Initialize with default smoothing factor
9
TEST_ASSERT_EQUAL_INT32(0, avg.
getAverageS
());
// EMA should start at 0
10
TEST_ASSERT_EQUAL_INT32(0, avg.
getAverageD
());
// DEMA should start at 0
11
TEST_ASSERT_EQUAL_INT32(0, avg.
getAverageT
());
// TEMA should start at 0
12
}
13
14
void
test_single_value_update
()
15
{
16
EWMA_average< 120 >
avg;
17
avg.
addValue
(100);
// Add a single value
18
TEST_ASSERT_EQUAL_INT32(100, avg.
getAverageS
());
// EMA should match the input
19
TEST_ASSERT_EQUAL_INT32(100, avg.
getAverageD
());
// DEMA should match the input
20
TEST_ASSERT_EQUAL_INT32(100, avg.
getAverageT
());
// TEMA should match the input
21
}
22
23
void
test_multiple_value_updates
()
24
{
25
EWMA_average< 120 >
avg;
26
avg.
addValue
(100);
// Add first value
27
avg.
addValue
(200);
// Add second value
28
TEST_ASSERT_GREATER_THAN(100, avg.
getAverageS
());
// EMA should be between 100 and 200
29
TEST_ASSERT_LESS_THAN(200, avg.
getAverageS
());
// EMA should be less than 200
30
TEST_ASSERT_GREATER_THAN(100, avg.
getAverageD
());
// DEMA should be between 100 and 200
31
TEST_ASSERT_LESS_THAN(200, avg.
getAverageD
());
// DEMA should be less than 200
32
TEST_ASSERT_GREATER_THAN(100, avg.
getAverageT
());
// TEMA should be between 100 and 200
33
TEST_ASSERT_LESS_THAN(200, avg.
getAverageT
());
// TEMA should be less than 200
34
}
35
36
void
test_peak_response
()
37
{
38
EWMA_average< 120 >
avg;
39
avg.
addValue
(100);
40
avg.
addValue
(1000);
// Add a peak value
41
TEST_ASSERT_GREATER_THAN(100, avg.
getAverageS
());
// EMA should increase
42
TEST_ASSERT_GREATER_THAN(avg.
getAverageS
(), avg.
getAverageD
());
// EMA > DEMA
43
TEST_ASSERT_GREATER_THAN(avg.
getAverageD
(), avg.
getAverageT
());
// DEMA > TEMA
44
}
45
46
void
test_reset_behavior
()
47
{
48
EWMA_average< 120 >
avg;
49
avg.
addValue
(100);
50
avg.
addValue
(200);
51
avg =
EWMA_average< 120 >
();
// Reset by reinitializing
52
TEST_ASSERT_EQUAL_INT32(0, avg.
getAverageS
());
// EMA should reset to 0
53
TEST_ASSERT_EQUAL_INT32(0, avg.
getAverageD
());
// DEMA should reset to 0
54
TEST_ASSERT_EQUAL_INT32(0, avg.
getAverageT
());
// TEMA should reset to 0
55
}
56
57
int
main
()
58
{
59
UNITY_BEGIN();
60
61
RUN_TEST(
test_initial_values
);
62
RUN_TEST(
test_single_value_update
);
63
RUN_TEST(
test_multiple_value_updates
);
64
RUN_TEST(
test_peak_response
);
65
RUN_TEST(
test_reset_behavior
);
66
67
return
UNITY_END();
68
}
EWMA_average
Implements an Exponentially Weighted Moving Average (EWMA).
Definition
ewma_avg.hpp:80
EWMA_average::addValue
void addValue(int32_t input)
Add a new value and update the EMA, DEMA, and TEMA.
Definition
ewma_avg.hpp:90
EWMA_average::getAverageD
auto getAverageD() const
Get the Double Exponentially Weighted Moving Average (DEMA).
Definition
ewma_avg.hpp:117
EWMA_average::getAverageT
auto getAverageT() const
Get the Triple Exponentially Weighted Moving Average (TEMA).
Definition
ewma_avg.hpp:127
EWMA_average::getAverageS
auto getAverageS() const
Get the Exponentially Weighted Moving Average (EMA).
Definition
ewma_avg.hpp:107
ewma_avg.hpp
This file implements an Exponentially Weighted Moving Average template class.
test_reset_behavior
void test_reset_behavior()
Definition
test_main.cpp:46
test_initial_values
void test_initial_values()
Definition
test_main.cpp:6
test_single_value_update
void test_single_value_update()
Definition
test_main.cpp:14
test_multiple_value_updates
void test_multiple_value_updates()
Definition
test_main.cpp:23
main
int main()
Definition
test_main.cpp:57
test_peak_response
void test_peak_response()
Definition
test_main.cpp:36
Generated by
1.13.2