1-phase PV router
Loading...
Searching...
No Matches
test_main.cpp
Go to the documentation of this file.
1
11
12#include <Arduino.h>
13#include <U8g2lib.h>
14
15#include <unity.h>
16
17#include "utils_pins.h"
18#include "utils_relay.h"
19
20constexpr RelayEngine relays{ { { 2, 1000, 200, 1, 1 },
21 { 3, 100, 20, 2, 3 } } };
22
26void setUp(void)
27{
28 relays.initializePins();
29}
30
34void tearDown(void)
35{
36 // clean stuff up here
37}
38
43{
44 relayOutput relay(4, 500, 100);
45 TEST_ASSERT_EQUAL(4, relay.get_pin());
46 TEST_ASSERT_EQUAL(500, relay.get_surplusThreshold());
47 TEST_ASSERT_EQUAL(100, relay.get_importThreshold());
48}
49
54{
55 relayOutput relay(4, 500, 100);
56 TEST_ASSERT_EQUAL(4, relay.get_pin());
57 TEST_ASSERT_EQUAL(500, relay.get_surplusThreshold());
58 TEST_ASSERT_EQUAL(100, relay.get_importThreshold());
59}
60
65{
66 relayOutput relay(4, -500, -100);
67 TEST_ASSERT_EQUAL(4, relay.get_pin());
68 TEST_ASSERT_EQUAL(500, relay.get_surplusThreshold());
69 TEST_ASSERT_EQUAL(100, relay.get_importThreshold());
70}
71
75void test_get_pin(void)
76{
77 TEST_ASSERT_EQUAL(2, relays.get_relay(0).get_pin());
78 TEST_ASSERT_EQUAL(3, relays.get_relay(1).get_pin());
79}
80
85{
86 TEST_ASSERT_EQUAL(1000, relays.get_relay(0).get_surplusThreshold());
87 TEST_ASSERT_EQUAL(100, relays.get_relay(1).get_surplusThreshold());
88}
89
94{
95 TEST_ASSERT_EQUAL(200, relays.get_relay(0).get_importThreshold());
96 TEST_ASSERT_EQUAL(20, relays.get_relay(1).get_importThreshold());
97}
98
103{
104 TEST_ASSERT_EQUAL(1 * 60, relays.get_relay(0).get_minON());
105 TEST_ASSERT_EQUAL(2 * 60, relays.get_relay(1).get_minON());
106}
107
112{
113 TEST_ASSERT_EQUAL(1 * 60, relays.get_relay(0).get_minOFF());
114 TEST_ASSERT_EQUAL(3 * 60, relays.get_relay(1).get_minOFF());
115}
116
121{
122 TEST_ASSERT_FALSE(relays.get_relay(1).isRelayON());
123}
124
129{
130 const auto& my_relay{ relays.get_relay(1) };
131
132 TEST_ASSERT_FALSE(my_relay.isRelayON());
133
134 /* The relay is OFF, test the "TurnON" case */
135 const auto surplus{ -my_relay.get_surplusThreshold() - 1 };
136
137 TEST_ASSERT_FALSE(my_relay.proceed_relay(surplus));
138 delay(100);
139 TEST_ASSERT_FALSE(my_relay.isRelayON());
140
141 for (uint8_t timer = 0; timer < my_relay.get_minOFF() - 1; ++timer)
142 {
143 my_relay.inc_duration();
144 }
145 TEST_ASSERT_FALSE(my_relay.proceed_relay(surplus));
146 delay(100);
147
148 my_relay.inc_duration();
149
150 TEST_ASSERT_TRUE(my_relay.proceed_relay(surplus));
151 TEST_ASSERT_TRUE(my_relay.isRelayON());
152}
153
158{
159 const auto& my_relay{ relays.get_relay(1) };
160
161 TEST_ASSERT_TRUE(my_relay.isRelayON());
162
163 /* The relay is ON, test the "TurnOFF" case */
164 const auto consum{ my_relay.get_importThreshold() + 1 };
165
166 TEST_ASSERT_FALSE(my_relay.proceed_relay(consum));
167 delay(100);
168 TEST_ASSERT_TRUE(my_relay.isRelayON());
169
170 for (uint8_t timer = 0; timer < my_relay.get_minON() - 1; ++timer)
171 {
172 my_relay.inc_duration();
173 }
174 TEST_ASSERT_FALSE(my_relay.proceed_relay(consum));
175 delay(100);
176
177 my_relay.inc_duration();
178
179 TEST_ASSERT_TRUE(my_relay.proceed_relay(consum));
180 TEST_ASSERT_FALSE(my_relay.isRelayON());
181}
182
187{
188 RUN_TEST(test_relay_turnON);
189 delay(100);
190 RUN_TEST(test_relay_turnOFF);
191}
192
197{
198 TEST_ASSERT_EQUAL(2, relays.get_size());
199}
200
201void setup()
202{
203 delay(1000);
204
205 UNITY_BEGIN(); // IMPORTANT LINE!
206}
207
208void loop()
209{
213
214 RUN_TEST(test_get_size);
215
216 RUN_TEST(test_get_pin);
217
219 RUN_TEST(test_get_importThreshold);
220
221 RUN_TEST(test_get_minON);
222 RUN_TEST(test_get_minOFF);
223
224 RUN_TEST(test_isRelayON);
225
226 RUN_TEST(test_proceed_relay);
227
228 UNITY_END(); // stop unit testing
229}
Manages a collection of relays and their behavior based on surplus and import thresholds.
Represents a single relay configuration and its behavior.
Definition utils_relay.h:42
constexpr auto get_surplusThreshold() const
Get the surplus threshold which will turns ON the relay.
Definition utils_relay.h:97
constexpr auto get_importThreshold() const
Get the import threshold which will turns OFF the relay.
constexpr auto get_pin() const
Get the control pin of the relay.
Definition utils_relay.h:87
constexpr RelayEngine relays
Definition config.h:79
void setup()
void setUp(void)
Definition test_main.cpp:6
void tearDown(void)
Definition test_main.cpp:11
void loop()
void test_get_pin(void)
Definition test_main.cpp:75
void test_get_minOFF(void)
void test_proceed_relay(void)
void test_isRelayON(void)
void test_relay_turnOFF(void)
void test_get_size(void)
void test_get_minON(void)
void test_get_surplusThreshold(void)
Definition test_main.cpp:84
void test_relay_initialization_with_positive_thresholds(void)
Definition test_main.cpp:53
void test_get_importThreshold(void)
Definition test_main.cpp:93
void test_relay_initialization(void)
Definition test_main.cpp:42
void test_relay_turnON(void)
void test_relay_initialization_with_negative_thresholds(void)
Definition test_main.cpp:64
Some utility functions for pins manipulation.
Some utility functions for the relay output feature.