3-phase PV router
Loading...
Searching...
No Matches
test_main.cpp
Go to the documentation of this file.
1#include <Arduino.h>
2#include <U8g2lib.h>
3
4#include <unity.h>
5
6#include "utils_pins.h"
7#include "utils_relay.h"
8
9constexpr RelayEngine relays{ { { 2, 1000, 200, 1, 1 },
10 { 3, 100, 20, 2, 3 } } };
11
12void setUp(void)
13{
15}
16
17void tearDown(void)
18{
19 // clean stuff up here
20}
21
23{
24 relayOutput relay(4, 500, 100);
25 TEST_ASSERT_EQUAL(4, relay.get_pin());
26 TEST_ASSERT_EQUAL(-500, relay.get_surplusThreshold());
27 TEST_ASSERT_EQUAL(100, relay.get_importThreshold());
28}
29
31{
32 relayOutput relay(4, 500, 100);
33 TEST_ASSERT_EQUAL(4, relay.get_pin());
34 TEST_ASSERT_EQUAL(-500, relay.get_surplusThreshold());
35 TEST_ASSERT_EQUAL(100, relay.get_importThreshold());
36}
37
39{
40 relayOutput relay(4, -500, -100);
41 TEST_ASSERT_EQUAL(4, relay.get_pin());
42 TEST_ASSERT_EQUAL(-500, relay.get_surplusThreshold());
43 TEST_ASSERT_EQUAL(100, relay.get_importThreshold());
44}
45
46void test_get_pin(void)
47{
48 TEST_ASSERT_EQUAL(2, relays.get_relay(0).get_pin());
49 TEST_ASSERT_EQUAL(3, relays.get_relay(1).get_pin());
50}
51
53{
54 TEST_ASSERT_EQUAL(1000, relays.get_relay(0).get_surplusThreshold());
55 TEST_ASSERT_EQUAL(100, relays.get_relay(1).get_surplusThreshold());
56}
57
59{
60 TEST_ASSERT_EQUAL(200, relays.get_relay(0).get_importThreshold());
61 TEST_ASSERT_EQUAL(20, relays.get_relay(1).get_importThreshold());
62}
63
65{
66 TEST_ASSERT_EQUAL(1 * 60, relays.get_relay(0).get_minON());
67 TEST_ASSERT_EQUAL(2 * 60, relays.get_relay(1).get_minON());
68}
69
71{
72 TEST_ASSERT_EQUAL(1 * 60, relays.get_relay(0).get_minOFF());
73 TEST_ASSERT_EQUAL(3 * 60, relays.get_relay(1).get_minOFF());
74}
75
77{
78 TEST_ASSERT_FALSE(relays.get_relay(1).isRelayON());
79}
80
82{
83 const auto& my_relay{ relays.get_relay(1) };
84
85 TEST_ASSERT_FALSE(my_relay.isRelayON());
86
87 /* The relay is OFF, test the "TurnON" case */
88 const auto surplus{ -my_relay.get_surplusThreshold() - 1 };
89
90 TEST_ASSERT_FALSE(my_relay.proceed_relay(surplus));
91 delay(100);
92 TEST_ASSERT_FALSE(my_relay.isRelayON());
93
94 for (uint8_t timer = 0; timer < my_relay.get_minOFF() - 1; ++timer)
95 {
96 my_relay.inc_duration();
97 }
98 TEST_ASSERT_FALSE(my_relay.proceed_relay(surplus));
99 delay(100);
100
101 my_relay.inc_duration();
102
103 TEST_ASSERT_TRUE(my_relay.proceed_relay(surplus));
104 TEST_ASSERT_TRUE(my_relay.isRelayON());
105}
106
108{
109 const auto& my_relay{ relays.get_relay(1) };
110
111 TEST_ASSERT_TRUE(my_relay.isRelayON());
112
113 /* The relay is ON, test the "TurnOFF" case */
114 const auto consum{ my_relay.get_importThreshold() + 1 };
115
116 TEST_ASSERT_FALSE(my_relay.proceed_relay(consum));
117 delay(100);
118 TEST_ASSERT_TRUE(my_relay.isRelayON());
119
120 for (uint8_t timer = 0; timer < my_relay.get_minON() - 1; ++timer)
121 {
122 my_relay.inc_duration();
123 }
124 TEST_ASSERT_FALSE(my_relay.proceed_relay(consum));
125 delay(100);
126
127 my_relay.inc_duration();
128
129 TEST_ASSERT_TRUE(my_relay.proceed_relay(consum));
130 TEST_ASSERT_FALSE(my_relay.isRelayON());
131}
132
134{
135 RUN_TEST(test_relay_turnON);
136 delay(100);
137 RUN_TEST(test_relay_turnOFF);
138}
139
141{
142 TEST_ASSERT_EQUAL(2, relays.get_size());
143}
144
145void setup()
146{
147 delay(1000);
148
149 UNITY_BEGIN(); // IMPORTANT LINE!
150}
151
152void loop()
153{
157
158 RUN_TEST(test_get_size);
159
160 RUN_TEST(test_get_pin);
161
163 RUN_TEST(test_get_importThreshold);
164
165 RUN_TEST(test_get_minON);
166 RUN_TEST(test_get_minOFF);
167
168 RUN_TEST(test_isRelayON);
169
170 RUN_TEST(test_proceed_relay);
171
172 UNITY_END(); // stop unit testing
173}
This class implements the relay management engine.
Definition: utils_relay.h:253
constexpr auto get_size() const
Get the number of relays.
Definition: utils_relay.h:278
constexpr const auto & get_relay(uint8_t idx) const
Get the relay object.
Definition: utils_relay.h:289
void initializePins() const
Initialize the pins used by the relays.
Definition: utils_relay.h:368
Relay diversion config and engine.
Definition: utils_relay.h:30
constexpr auto get_surplusThreshold() const
Get the surplus threshold which will turns ON the relay.
Definition: utils_relay.h:85
constexpr auto get_importThreshold() const
Get the import threshold which will turns OFF the relay.
Definition: utils_relay.h:95
constexpr auto get_pin() const
Get the control pin of the relay.
Definition: utils_relay.h:75
void setup()
Definition: test_main.cpp:82
void setUp(void)
Definition: test_main.cpp:8
void tearDown(void)
Definition: test_main.cpp:13
void loop()
Definition: test_main.cpp:97
void test_get_pin(void)
Definition: test_main.cpp:46
void test_get_minOFF(void)
Definition: test_main.cpp:70
void test_proceed_relay(void)
Definition: test_main.cpp:133
constexpr RelayEngine relays
Definition: test_main.cpp:9
void test_isRelayON(void)
Definition: test_main.cpp:76
void test_relay_turnOFF(void)
Definition: test_main.cpp:107
void test_get_size(void)
Definition: test_main.cpp:140
void test_get_minON(void)
Definition: test_main.cpp:64
void test_get_surplusThreshold(void)
Definition: test_main.cpp:52
void test_relay_initialization_with_positive_thresholds(void)
Definition: test_main.cpp:30
void test_get_importThreshold(void)
Definition: test_main.cpp:58
void test_relay_initialization(void)
Definition: test_main.cpp:22
void test_relay_turnON(void)
Definition: test_main.cpp:81
void test_relay_initialization_with_negative_thresholds(void)
Definition: test_main.cpp:38
Some utility functions for pins manipulation.
Some utility functions for the relay output feature.