3-phase PV router
Loading...
Searching...
No Matches
test_main.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
14
15#include <unity.h>
16
17#include "relay_engine.h" // Real header - pure C++
18
19namespace
20{
21// ----------------------------------------------------------------------------
22// An output that records the switches
23// ----------------------------------------------------------------------------
24struct Switch
25{
26 uint8_t pin;
27 bool on;
28};
29
30Switch switches[16];
31uint8_t switchCount{ 0 };
32
33struct Recorder
34{
35 static void switched(const uint8_t pin, const bool on)
36 {
37 if (switchCount < sizeof(switches) / sizeof(switches[0]))
38 {
39 switches[switchCount] = { pin, on };
40 }
41 ++switchCount;
42 }
43};
44
46
47// a 1-minute sliding average: 12 datalogs of 5 s, quick to settle
48template< uint8_t N >
50
51constexpr uint16_t NO_OVERRIDE{ 0 };
52
53constexpr uint16_t forced(const uint8_t pin)
54{
55 return static_cast< uint16_t >(1U << pin);
56}
57
58void assertSwitch(const uint8_t i, const uint8_t pin, const bool on)
59{
60 TEST_ASSERT_TRUE_MESSAGE(i < switchCount, "switch not recorded");
61 TEST_ASSERT_EQUAL_UINT8(pin, switches[i].pin);
62 TEST_ASSERT_EQUAL(on, switches[i].on);
63}
64
66void age(const Relay& r, uint32_t n)
67{
68 while (n--)
69 {
70 r.inc_duration();
71 }
72}
73
78template< uint8_t N >
79void setAverage(const int16_t power)
80{
81 for (uint16_t i = 0; i < 1000; ++i)
82 {
83 Engine< N >::update_average(power);
84 }
85 TEST_ASSERT_EQUAL_INT32(power, Engine< N >::get_average());
86}
87
89template< uint8_t N >
90void seconds(const Engine< N >& e, uint16_t n, const uint16_t overrideBitmask = NO_OVERRIDE, const bool diversionEnabled = true)
91{
92 while (n--)
93 {
94 e.inc_duration();
95 e.proceed_relays(overrideBitmask, diversionEnabled);
96 }
97}
98
100template< uint8_t N >
101void skipStartUp(const Engine< N >& e)
102{
103 for (uint8_t i = 0; i < 60; ++i)
104 {
105 e.inc_duration();
106 }
107}
108
110template< uint8_t N >
111void allOn(const Engine< N >& e)
112{
113 setAverage< N >(-10000);
114 skipStartUp(e);
115 seconds(e, 60 * N);
116 for (uint8_t i = 0; i < 60; ++i)
117 {
118 e.inc_duration();
119 }
120 for (uint8_t i = 0; i < N; ++i)
121 {
122 TEST_ASSERT_TRUE(e.get_relay(i).isRelayON());
123 }
124 switchCount = 0;
125}
126} // namespace
127
128void setUp(void)
129{
130 switchCount = 0;
131}
132
133void tearDown(void) {}
134
135// ============================================================================
136// Relay: configuration
137// ============================================================================
138
140{
141 const Relay r{ 4, 500, 100, 2, 3 };
142
143 TEST_ASSERT_EQUAL_UINT16(120, r.get_minON());
144 TEST_ASSERT_EQUAL_UINT16(180, r.get_minOFF());
145}
146
148{
149 // 1093 min = 65580 s does not fit in 16 bits: kept as UINT16_MAX, which no number of
150 // minutes gives (it is no multiple of 60), so that validation.h can refuse it
151 const Relay r{ 5, 1000, 200, 1093, 1092 };
152 TEST_ASSERT_EQUAL_UINT16(UINT16_MAX, r.get_minON());
153 TEST_ASSERT_EQUAL_UINT16(65520, r.get_minOFF());
154 TEST_ASSERT_TRUE(r.hasValidMinimumTimes() == false);
155
156 const Relay s{ 5, 1000, 200, 1092, 1092 };
157 TEST_ASSERT_TRUE(s.hasValidMinimumTimes());
158}
159
161{
162 const Relay plus{ 4, 500, 100 };
163 const Relay minus{ 4, -500, -100 };
164
165 TEST_ASSERT_EQUAL_INT16(500, plus.get_surplusThreshold());
166 TEST_ASSERT_EQUAL_INT16(500, minus.get_surplusThreshold());
167 // the import threshold keeps its sign: negative is the battery mode
168 TEST_ASSERT_EQUAL_INT16(100, plus.get_importThreshold());
169 TEST_ASSERT_EQUAL_INT16(-100, minus.get_importThreshold());
170}
171
173{
174 const Relay r{ 4 };
175
176 TEST_ASSERT_EQUAL_UINT8(4, r.get_pin());
177 TEST_ASSERT_EQUAL_INT16(1000, r.get_surplusThreshold());
178 TEST_ASSERT_EQUAL_INT16(200, r.get_importThreshold());
179 TEST_ASSERT_EQUAL_UINT16(300, r.get_minON());
180 TEST_ASSERT_EQUAL_UINT16(300, r.get_minOFF());
181 TEST_ASSERT_FALSE(r.isRelayON());
182}
183
184// ============================================================================
185// Relay: thresholds
186// ============================================================================
187
189{
190 const Relay r{ 5, 1000, 200, 0, 0 };
191
192 TEST_ASSERT_FALSE(r.proceed_relay(-1000, NO_OVERRIDE));
193 TEST_ASSERT_FALSE(r.isRelayON());
194 TEST_ASSERT_EQUAL_UINT8(0, switchCount);
195
196 TEST_ASSERT_TRUE(r.proceed_relay(-1001, NO_OVERRIDE));
197 TEST_ASSERT_TRUE(r.isRelayON());
198 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
199 assertSwitch(0, 5, true);
200}
201
203{
204 const Relay r{ 5, 1000, 200, 0, 0 };
205 r.proceed_relay(-2000, NO_OVERRIDE);
206 switchCount = 0;
207
208 TEST_ASSERT_FALSE(r.proceed_relay(200, NO_OVERRIDE));
209 TEST_ASSERT_TRUE(r.isRelayON());
210
211 TEST_ASSERT_TRUE(r.proceed_relay(201, NO_OVERRIDE));
212 TEST_ASSERT_FALSE(r.isRelayON());
213 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
214 assertSwitch(0, 5, false);
215}
216
218{
219 const Relay off{ 5, 1000, 200, 0, 0 };
220 const Relay on{ 6, 1000, 200, 0, 0 };
221 on.proceed_relay(-2000, NO_OVERRIDE);
222 switchCount = 0;
223
224 const int32_t powers[]{ -1000, -999, -1, 0, 1, 199, 200 };
225 for (const auto power : powers)
226 {
227 TEST_ASSERT_FALSE(off.proceed_relay(power, NO_OVERRIDE));
228 TEST_ASSERT_FALSE(on.proceed_relay(power, NO_OVERRIDE));
229 }
230 TEST_ASSERT_FALSE(off.isRelayON());
231 TEST_ASSERT_TRUE(on.isRelayON());
232 TEST_ASSERT_EQUAL_UINT8(0, switchCount);
233}
234
236{
237 // battery mode: OFF when the surplus drops below 50 W
238 const Relay r{ 5, 1000, -50, 0, 0 };
239 r.proceed_relay(-2000, NO_OVERRIDE);
240
241 TEST_ASSERT_FALSE(r.proceed_relay(-50, NO_OVERRIDE));
242 TEST_ASSERT_TRUE(r.isRelayON());
243
244 TEST_ASSERT_TRUE(r.proceed_relay(-49, NO_OVERRIDE));
245 TEST_ASSERT_FALSE(r.isRelayON());
246}
247
248// ============================================================================
249// Relay: minimum ON and OFF times
250// ============================================================================
251
253{
254 // at start-up, the relay is OFF since 0 s
255 const Relay r{ 5, 1000, 200, 2, 3 };
256
257 age(r, 179);
258 TEST_ASSERT_FALSE(r.proceed_relay(-2000, NO_OVERRIDE));
259 TEST_ASSERT_EQUAL_UINT8(0, switchCount);
260
261 age(r, 1);
262 TEST_ASSERT_TRUE(r.proceed_relay(-2000, NO_OVERRIDE));
263 TEST_ASSERT_TRUE(r.isRelayON());
264}
265
267{
268 const Relay r{ 5, 1000, 200, 2, 3 };
269 age(r, 180);
270 r.proceed_relay(-2000, NO_OVERRIDE);
271 switchCount = 0;
272
273 age(r, 119);
274 TEST_ASSERT_FALSE(r.proceed_relay(5000, NO_OVERRIDE));
275 TEST_ASSERT_TRUE(r.isRelayON());
276
277 age(r, 1);
278 TEST_ASSERT_TRUE(r.proceed_relay(5000, NO_OVERRIDE));
279 TEST_ASSERT_FALSE(r.isRelayON());
280}
281
283{
284 const Relay r{ 5, 1000, 200, 2, 3 };
285 age(r, 180);
286 r.proceed_relay(-2000, NO_OVERRIDE);
287 age(r, 120);
288 r.proceed_relay(5000, NO_OVERRIDE);
289 switchCount = 0;
290
291 age(r, 179);
292 TEST_ASSERT_FALSE(r.proceed_relay(-2000, NO_OVERRIDE));
293
294 age(r, 1);
295 TEST_ASSERT_TRUE(r.proceed_relay(-2000, NO_OVERRIDE));
296}
297
299{
300 // 100 minutes OFF minimum: 6000 s; a wrapped duration would be back to 100 s
301 const Relay r{ 5, 1000, 200, 1, 100 };
302
303 age(r, 65536UL + 100);
304 TEST_ASSERT_TRUE(r.proceed_relay(-2000, NO_OVERRIDE));
305}
306
307// ============================================================================
308// Relay: override
309// ============================================================================
310
312{
313 const Relay r{ 5, 1000, 200, 0, 0 };
314
315 // the bit of the pin (5), not that of the index (0) or of a neighbour
316 TEST_ASSERT_FALSE(r.proceed_relay(5000, forced(0)));
317 TEST_ASSERT_FALSE(r.proceed_relay(5000, forced(4) | forced(6)));
318 TEST_ASSERT_FALSE(r.isRelayON());
319
320 TEST_ASSERT_TRUE(r.proceed_relay(5000, forced(5)));
321 TEST_ASSERT_TRUE(r.isRelayON());
322 assertSwitch(0, 5, true);
323}
324
326{
327 const Relay r{ 5, 1000, 200, 0, 0 };
328 r.proceed_relay(5000, forced(5));
329
330 TEST_ASSERT_FALSE(r.proceed_relay(5000, forced(5)));
331 TEST_ASSERT_TRUE(r.isRelayON());
332
333 // released: the import turns it OFF
334 TEST_ASSERT_TRUE(r.proceed_relay(5000, NO_OVERRIDE));
335 TEST_ASSERT_FALSE(r.isRelayON());
336}
337
339{
340 const Relay r{ 5, 1000, 200, 1, 2 };
341
342 age(r, 119);
343 TEST_ASSERT_FALSE(r.proceed_relay(0, forced(5)));
344 TEST_ASSERT_FALSE(r.proceed_forced_only(forced(5)));
345
346 age(r, 1);
347 TEST_ASSERT_TRUE(r.proceed_relay(0, forced(5)));
348}
349
351{
352 const Relay r{ 5, 1000, 200, 1, 0 };
353 TEST_ASSERT_TRUE(r.proceed_forced_only(forced(5)));
354 TEST_ASSERT_FALSE(r.proceed_forced_only(forced(5)));
355
356 // released: OFF, whatever the power, once ON for 60 s
357 age(r, 59);
358 TEST_ASSERT_FALSE(r.proceed_forced_only(NO_OVERRIDE));
359 age(r, 1);
360 TEST_ASSERT_TRUE(r.proceed_forced_only(NO_OVERRIDE));
361 TEST_ASSERT_FALSE(r.isRelayON());
362
363 TEST_ASSERT_EQUAL_UINT8(2, switchCount);
364 assertSwitch(0, 5, true);
365 assertSwitch(1, 5, false);
366}
367
368// ============================================================================
369// Engine: settle time
370// ============================================================================
371
373{
374 const Engine< 2 > e{ { { 5, 1000, 200, 0, 0 }, { 6, 1000, 200, 0, 0 } } };
375 setAverage< 2 >(-5000);
376
377 seconds(e, 59);
378 TEST_ASSERT_EQUAL_UINT8(0, switchCount);
379
380 seconds(e, 1);
381 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
382 assertSwitch(0, 5, true);
383}
384
386{
387 const Engine< 2 > e{ { { 5, 1000, 200, 0, 0 }, { 6, 1000, 200, 0, 0 } } };
388 setAverage< 2 >(-5000);
389 skipStartUp(e);
390
391 seconds(e, 1); // relay #1 ON
392 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
393
394 seconds(e, 59);
395 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
396 TEST_ASSERT_FALSE(e.get_relay(1).isRelayON());
397
398 seconds(e, 1); // relay #2 ON
399 TEST_ASSERT_EQUAL_UINT8(2, switchCount);
400 assertSwitch(1, 6, true);
401}
402
404{
405 const Engine< 2 > e{ { { 5, 1000, 200, 0, 0 }, { 6, 3000, 200, 0, 0 } } };
406 setAverage< 2 >(-5000);
407 skipStartUp(e);
408 seconds(e, 1); // relay #1 ON
409 switchCount = 0;
410
411 setAverage< 2 >(5000);
412 seconds(e, 59);
413 TEST_ASSERT_TRUE(e.get_relay(0).isRelayON());
414
415 seconds(e, 1);
416 TEST_ASSERT_FALSE(e.get_relay(0).isRelayON());
417}
418
420{
421 const Engine< 2 > e{ { { 5, 1000, 200, 0, 0 }, { 6, 1000, 200, 0, 0 } } };
422 setAverage< 2 >(0);
423 skipStartUp(e);
424
425 seconds(e, 10); // nothing to switch
426 seconds(e, 10, NO_OVERRIDE, false);
427 TEST_ASSERT_EQUAL_UINT8(0, switchCount);
428
429 setAverage< 2 >(-5000);
430 e.proceed_relays(NO_OVERRIDE);
431 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
432}
433
434// ============================================================================
435// Engine: order
436// ============================================================================
437
439{
440 const Engine< 3 > e{ { { 7, 500, 100, 0, 0 }, { 5, 500, 100, 0, 0 }, { 6, 500, 100, 0, 0 } } };
441 setAverage< 3 >(-5000);
442 skipStartUp(e);
443
444 e.proceed_relays(NO_OVERRIDE);
445 e.proceed_relays(NO_OVERRIDE); // held by the settle time
446 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
447
448 seconds(e, 120);
449 TEST_ASSERT_EQUAL_UINT8(3, switchCount);
450 assertSwitch(0, 7, true);
451 assertSwitch(1, 5, true);
452 assertSwitch(2, 6, true);
453}
454
456{
457 const Engine< 3 > e{ { { 7, 500, 100, 0, 0 }, { 5, 500, 100, 0, 0 }, { 6, 500, 100, 0, 0 } } };
458 allOn(e);
459
460 setAverage< 3 >(5000);
461 e.proceed_relays(NO_OVERRIDE);
462 e.proceed_relays(NO_OVERRIDE); // held by the settle time
463 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
464
465 // the settle time after a switch OFF: 60 s too
466 seconds(e, 59);
467 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
468 seconds(e, 1);
469 TEST_ASSERT_EQUAL_UINT8(2, switchCount);
470
471 seconds(e, 60);
472 TEST_ASSERT_EQUAL_UINT8(3, switchCount);
473 assertSwitch(0, 6, false);
474 assertSwitch(1, 5, false);
475 assertSwitch(2, 7, false);
476}
477
479{
480 const Engine< 2 > e{ { { 5, 500, 100, 0, 3 }, { 6, 500, 100, 0, 0 } } };
481 setAverage< 2 >(-5000);
482 skipStartUp(e);
483
484 e.proceed_relays(NO_OVERRIDE);
485 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
486 assertSwitch(0, 6, true);
487 TEST_ASSERT_FALSE(e.get_relay(0).isRelayON());
488}
489
491{
492 const Engine< 2 > e{ { { 5, 500, 100, 0, 0 }, { 6, 500, 100, 2, 0 } } };
493 allOn(e); // relay #2 ON for 119 s, 1 s short of its minimum ON time
494
495 setAverage< 2 >(5000);
496 e.proceed_relays(NO_OVERRIDE);
497 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
498 assertSwitch(0, 5, false);
499 TEST_ASSERT_TRUE(e.get_relay(1).isRelayON());
500}
501
503{
504 const Engine< 2 > e{ { { 5, 2000, 100, 0, 0 }, { 6, 500, 100, 0, 0 } } };
505 setAverage< 2 >(-1000);
506 skipStartUp(e);
507
508 seconds(e, 120);
509 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
510 assertSwitch(0, 6, true);
511}
512
514{
515 // Battery mode, both ON: on a surplus below 100 W, at 0 W, or on an import, the last relay
516 // goes out first, as on an import in normal mode.
517 const Engine< 2 > d{ { { 5, 500, -100, 0, 0 }, { 6, 500, -100, 0, 0 } } };
518 allOn(d);
519
520 setAverage< 2 >(-50);
521 d.proceed_relays(NO_OVERRIDE);
522 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
523 assertSwitch(0, 6, false);
524
525 const Engine< 2 > e{ { { 5, 500, -100, 0, 0 }, { 6, 500, -100, 0, 0 } } };
526 allOn(e);
527
528 setAverage< 2 >(0);
529 e.proceed_relays(NO_OVERRIDE);
530 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
531 assertSwitch(0, 6, false);
532
533 const Engine< 2 > f{ { { 5, 500, -100, 0, 0 }, { 6, 500, -100, 0, 0 } } };
534 allOn(f);
535
536 setAverage< 2 >(1);
537 f.proceed_relays(NO_OVERRIDE);
538 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
539 assertSwitch(0, 6, false);
540}
541
542// ============================================================================
543// Engine: override
544// ============================================================================
545
547{
548 const Engine< 3 > e{ { { 5, 500, 100, 0, 0 }, { 6, 500, 100, 0, 0 }, { 7, 500, 100, 0, 0 } } };
549 setAverage< 3 >(5000);
550 skipStartUp(e);
551
552 e.proceed_relays(forced(6));
553 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
554 assertSwitch(0, 6, true);
555}
556
558{
559 const Engine< 3 > e{ { { 5, 500, 100, 0, 0 }, { 6, 500, 100, 0, 0 }, { 7, 500, 100, 0, 0 } } };
560 allOn(e);
561
562 setAverage< 3 >(5000);
563 seconds(e, 180, forced(6));
564 TEST_ASSERT_EQUAL_UINT8(2, switchCount);
565 assertSwitch(0, 7, false);
566 assertSwitch(1, 5, false);
567 TEST_ASSERT_TRUE(e.get_relay(1).isRelayON());
568}
569
571{
572 const Engine< 2 > e{ { { 5, 500, 100, 0, 0 }, { 6, 500, 100, 0, 0 } } };
573 setAverage< 2 >(5000);
574 skipStartUp(e);
575 seconds(e, 60, forced(6));
576 TEST_ASSERT_TRUE(e.get_relay(1).isRelayON());
577
578 // released between the thresholds: stays ON
579 setAverage< 2 >(0);
580 seconds(e, 120);
581 TEST_ASSERT_TRUE(e.get_relay(1).isRelayON());
582
583 // then an import: OFF
584 setAverage< 2 >(5000);
585 e.proceed_relays(NO_OVERRIDE);
586 TEST_ASSERT_FALSE(e.get_relay(1).isRelayON());
587}
588
589// ============================================================================
590// Engine: diversion disabled
591// ============================================================================
592
594{
595 const Engine< 3 > e{ { { 5, 500, 100, 0, 0 }, { 6, 500, 100, 0, 0 }, { 7, 500, 100, 0, 0 } } };
596 allOn(e);
597
598 // even on a surplus
599 e.proceed_relays(forced(6), false);
600 TEST_ASSERT_EQUAL_UINT8(2, switchCount);
601 assertSwitch(0, 7, false);
602 assertSwitch(1, 5, false);
603 TEST_ASSERT_TRUE(e.get_relay(1).isRelayON());
604}
605
607{
608 const Engine< 3 > e{ { { 5, 500, 100, 0, 0 }, { 6, 500, 100, 0, 0 }, { 7, 500, 100, 0, 0 } } };
609 setAverage< 3 >(-5000);
610 skipStartUp(e);
611
612 seconds(e, 120, NO_OVERRIDE, false);
613 TEST_ASSERT_EQUAL_UINT8(0, switchCount);
614
615 // both forced relays in one go
616 e.proceed_relays(forced(5) | forced(7), false);
617 TEST_ASSERT_EQUAL_UINT8(2, switchCount);
618 assertSwitch(0, 7, true);
619 assertSwitch(1, 5, true);
620}
621
623{
624 const Engine< 2 > e{ { { 5, 500, 100, 0, 0 }, { 6, 500, 100, 2, 0 } } };
625 allOn(e); // relay #2 ON for 119 s, 1 s short of its minimum ON time
626
627 // relay #1 OFF at once, relay #2 held by its minimum ON time
628 e.proceed_relays(NO_OVERRIDE, false);
629 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
630 assertSwitch(0, 5, false);
631
632 // relay #2 may go OFF 1 s later, but the change of relay #1 holds it for 60 s
633 seconds(e, 59, NO_OVERRIDE, false);
634 TEST_ASSERT_TRUE(e.get_relay(1).isRelayON());
635 seconds(e, 1, NO_OVERRIDE, false);
636 TEST_ASSERT_FALSE(e.get_relay(1).isRelayON());
637
638 // and that change holds a forced relay for 60 s
639 seconds(e, 59, forced(5), false);
640 TEST_ASSERT_FALSE(e.get_relay(0).isRelayON());
641 seconds(e, 1, forced(5), false);
642 TEST_ASSERT_TRUE(e.get_relay(0).isRelayON());
643}
644
645// ============================================================================
646// Engine: sliding average
647// ============================================================================
648
650{
651 const Engine< 1 > e{ { { 5, 1000, 200, 0, 0 } } };
652 setAverage< 1 >(0);
653 skipStartUp(e);
654
655 // one datalog of twice the surplus threshold: the average stays above -1000 W
656 Engine< 1 >::update_average(-2000);
657 TEST_ASSERT_TRUE(Engine< 1 >::get_average() > -1000);
658 TEST_ASSERT_TRUE(Engine< 1 >::get_average() < 0);
659 e.proceed_relays(NO_OVERRIDE);
660 TEST_ASSERT_EQUAL_UINT8(0, switchCount);
661
662 // a lasting one: ON
663 setAverage< 1 >(-2000);
664 e.proceed_relays(NO_OVERRIDE);
665 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
666}
667
669{
670 const Engine< 1 > e{ { { 5, 1000, 200, 0, 0 } } };
671 setAverage< 1 >(0);
672 skipStartUp(e);
673
674 // One datalog of -4000 W: the triple EMA (TEMA) takes about 30 % of a step at once,
675 // -1188 W; a plain EMA, 1/8 of it, -500 W, would leave the relay OFF.
676 Engine< 1 >::update_average(-4000);
677 TEST_ASSERT_EQUAL_INT32(-1188, Engine< 1 >::get_average());
678 e.proceed_relays(NO_OVERRIDE);
679 TEST_ASSERT_EQUAL_UINT8(1, switchCount);
680}
681
682int main(void)
683{
684 UNITY_BEGIN();
685
689 RUN_TEST(test_the_defaults);
690
695
700
705
710
717
721
725
728
729 return UNITY_END();
730}
A collection of relays, switched one at a time from a sliding average.
The state of one relay, and its decisions.
void setUp(void)
Definition test_main.cpp:27
void tearDown(void)
Definition test_main.cpp:28
uint8_t i
int main(void)
void test_the_duration_stops_at_its_maximum_instead_of_wrapping(void)
void test_the_surplus_threshold_is_positive_whatever_its_sign_in_the_config(void)
void test_the_defaults(void)
void test_on_an_import_the_relays_go_out_one_at_a_time_by_decreasing_index(void)
void test_the_engine_decides_on_the_average_not_on_the_last_value(void)
void test_the_engine_decides_on_the_triple_ema(void)
void test_a_change_of_any_relay_holds_every_relay_for_a_minute(void)
void test_forced_only_turns_an_unforced_relay_off_after_its_minimum_on_time(void)
void test_the_settle_time_holds_a_switch_off_after_a_switch_on(void)
void test_between_the_thresholds_nothing_changes(void)
void test_diversion_off_ignores_the_surplus_and_forces_on(void)
void test_a_forced_relay_is_not_turned_off_by_an_import(void)
void test_a_released_relay_is_left_to_the_engine(void)
void test_a_new_relay_waits_its_minimum_off_time(void)
void test_the_minimum_on_time_ends_after_exactly_min_on_seconds(void)
void test_battery_relays_go_out_by_decreasing_index_on_a_small_surplus(void)
void test_a_relay_held_by_its_minimum_off_time_lets_the_next_one_in(void)
void test_a_minimum_time_beyond_1092_minutes_is_marked_for_validation(void)
void test_on_a_surplus_the_relays_come_in_one_at_a_time_by_increasing_index(void)
void test_a_negative_import_threshold_turns_off_on_a_small_surplus(void)
void test_a_relay_held_by_its_minimum_on_time_lets_the_previous_one_out(void)
void test_each_relay_comes_in_at_its_own_threshold(void)
void test_a_forced_relay_waits_its_minimum_off_time(void)
void test_a_forced_relay_comes_in_during_an_import(void)
void test_exactly_the_surplus_threshold_does_not_turn_on(void)
void test_the_minimum_times_are_given_in_minutes_and_kept_in_seconds(void)
void test_the_minimum_off_time_restarts_at_each_switch_off(void)
void test_exactly_the_import_threshold_does_not_turn_off(void)
void test_a_forced_relay_stays_on_while_the_others_go_out(void)
void test_no_change_starts_no_settle_time(void)
void test_a_forced_relay_turns_on_whatever_the_power(void)
void test_diversion_off_turns_every_unforced_relay_off_in_one_go(void)
void test_diversion_off_keeps_the_minimum_times_and_the_settle_time(void)
void test_nothing_switches_during_the_first_minute(void)
Decisions of the relay diversion: which relay switches, and when.