1
1
#include < ArduinoUnitTests.h>
2
2
#include < Arduino.h>
3
+ #include " fibonacciClock.h"
3
4
4
-
5
- unittest (pin_read_history) {
6
- PinHistory<int > phi;
5
+ unittest (pin_read_history_int) {
6
+ PinHistory<int > phi; // pin history int
7
7
8
8
const int future[6 ] = {33 , 22 , 55 , 11 , 44 , 66 };
9
9
assertEqual (0 , phi.queueSize ());
@@ -16,8 +16,10 @@ unittest(pin_read_history) {
16
16
17
17
// assert end of history works
18
18
assertEqual (future[5 ], phi.retrieve ());
19
+ }
19
20
20
- PinHistory<bool > phb;
21
+ unittest (pin_read_history_bool_to_ascii) {
22
+ PinHistory<bool > phb; // pin history bool
21
23
phb.fromAscii (" Yo" , true );
22
24
23
25
// digitial history as serial data, big-endian
@@ -32,7 +34,19 @@ unittest(pin_read_history) {
32
34
assertEqual (" Yo" , phb.toAscii (0 , true ));
33
35
}
34
36
35
- unittest (ascii_stuff) {
37
+ unittest (assignment_dumps_queue) {
38
+ PinHistory<bool > phb; // pin history bool
39
+ assertEqual (0 , phb.queueSize ());
40
+ assertEqual (0 , phb.historySize ());
41
+ phb.fromAscii (" Yo" , true );
42
+ assertEqual (16 , phb.queueSize ());
43
+ assertEqual (0 , phb.historySize ());
44
+ phb = false ;
45
+ assertEqual (0 , phb.queueSize ());
46
+ assertEqual (1 , phb.historySize ());
47
+ }
48
+
49
+ unittest (ascii_to_bool_and_back) {
36
50
PinHistory<bool > phb;
37
51
assertEqual (0 , phb.historySize ());
38
52
phb.reset (false );
@@ -50,4 +64,106 @@ unittest(ascii_stuff) {
50
64
assertEqual (" hi" , phb.toAscii (1 , true ));
51
65
}
52
66
67
+ unittest (write_history) {
68
+ PinHistory<int > phi; // pin history int
69
+ int expectedA[6 ] = {0 , 11 , 22 , 33 , 44 , 55 };
70
+ for (int i = 0 ; i < 6 ; ++i)
71
+ {
72
+ assertEqual (i, phi.historySize ());
73
+ phi = expectedA[i];
74
+ assertEqual (i + 1 , phi.historySize ());
75
+ assertEqual (0 , phi.queueSize ());
76
+ assertEqual (phi, expectedA[i]);
77
+ }
78
+
79
+ int actualA[6 ];
80
+ int numMoved = phi.toArray (actualA, 6 );
81
+ assertEqual (6 , numMoved);
82
+ // assert non-destructive by repeating the operation
83
+ numMoved = phi.toArray (actualA, 6 );
84
+ assertEqual (6 , numMoved);
85
+ for (int i = 0 ; i < 6 ; ++i)
86
+ {
87
+ assertEqual (expectedA[i], actualA[i]);
88
+ }
89
+ }
90
+
91
+ unittest (null_timing) {
92
+ PinHistory<int > phi; // pin history int
93
+ int expectedA[6 ] = {0 , 11 , 22 , 33 , 44 , 55 };
94
+ for (int i = 0 ; i < 6 ; ++i)
95
+ {
96
+ phi = expectedA[i];
97
+ }
98
+
99
+ unsigned long tStamps[6 ];
100
+ int numMoved = phi.toTimestampArray (tStamps, 6 );
101
+ assertEqual (6 , numMoved);
102
+ // assert non-destructive by repeating the operation
103
+ numMoved = phi.toTimestampArray (tStamps, 6 );
104
+ assertEqual (6 , numMoved);
105
+ for (int i = 0 ; i < 6 ; ++i)
106
+ {
107
+ assertEqual (0 , tStamps[i]);
108
+ }
109
+ }
110
+
111
+ unittest (actual_timing_set_in_constructor) {
112
+ resetFibClock ();
113
+ PinHistory<int > phi (fibMicros); // pin history int
114
+ for (int i = 0 ; i < 6 ; ++i)
115
+ {
116
+ phi = 0 ;
117
+ }
118
+
119
+ int expectedT[6 ] = {1 , 1 , 2 , 3 , 5 , 8 };
120
+ unsigned long tStamps[6 ];
121
+ int numMoved = phi.toTimestampArray (tStamps, 6 );
122
+ assertEqual (6 , numMoved);
123
+ for (int i = 0 ; i < 6 ; ++i)
124
+ {
125
+ assertEqual (expectedT[i], tStamps[i]);
126
+ }
127
+ }
128
+
129
+ unittest (actual_timing_set_after_constructor) {
130
+ resetFibClock ();
131
+ PinHistory<int > phi; // pin history int
132
+ phi.setMicrosRetriever (fibMicros);
133
+ for (int i = 0 ; i < 6 ; ++i)
134
+ {
135
+ phi = 0 ;
136
+ }
137
+
138
+ int expectedT[6 ] = {1 , 1 , 2 , 3 , 5 , 8 };
139
+ unsigned long tStamps[6 ];
140
+ int numMoved = phi.toTimestampArray (tStamps, 6 );
141
+ assertEqual (6 , numMoved);
142
+ for (int i = 0 ; i < 6 ; ++i)
143
+ {
144
+ assertEqual (expectedT[i], tStamps[i]);
145
+ }
146
+ }
147
+
148
+ unittest (event_history) {
149
+ resetFibClock ();
150
+ PinHistory<int > phi (fibMicros); // pin history int
151
+ for (int i = 0 ; i < 6 ; ++i)
152
+ {
153
+ phi = i;
154
+ }
155
+
156
+ int expectedT[6 ] = {1 , 1 , 2 , 3 , 5 , 8 };
157
+ MockEventQueue<int >::Event event[6 ];
158
+ int numMoved = phi.toEventArray (event, 6 );
159
+ assertEqual (6 , numMoved);
160
+ for (int i = 0 ; i < 6 ; ++i)
161
+ {
162
+ assertEqual (i, event[i].data );
163
+ assertEqual (expectedT[i], event[i].micros );
164
+ }
165
+ }
166
+
167
+
168
+
53
169
unittest_main ()
0 commit comments