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