Skip to content

Commit 94ab7de

Browse files
include and add test for assertions from collection
1 parent ca57b2e commit 94ab7de

File tree

1 file changed

+292
-0
lines changed

1 file changed

+292
-0
lines changed

code/tests/test_tdd.c

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
*/
1515
#include <fossil/unittest/framework.h>
1616

17+
// list of include headers that extends
18+
// the framework assertion collection.
19+
#include <fossil/unittest/assert.h>
20+
#include <fossil/unittest/assume.h>
21+
#include <fossil/unittest/expect.h>
22+
1723
// * * * * * * * * * * * * * * * * * * * * * * * *
1824
// * Fossil Logic Test Utilites
1925
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -91,6 +97,270 @@ FOSSIL_TEST(xassert_run_of_int64) {
9197
TEST_ASSERT((int64_t)y <= (int64_t)x, "Should have passed the test case");
9298
} // end case
9399

100+
FOSSIL_TEST(xassert_run_of_int8_shortcut) {
101+
int8_t x = 42;
102+
int8_t y = 20;
103+
104+
// Test cases
105+
ASSERT_ITS_EQUAL_I8((int8_t)x, 42);
106+
ASSERT_ITS_EQUAL_I8((int8_t)y, 20);
107+
ASSERT_NOT_EQUAL_I8((int8_t)x, (int8_t)y);
108+
ASSERT_ITS_LESS_THAN_I8((int8_t)y, (int8_t)x);
109+
ASSERT_ITS_LESS_OR_EQUAL_I8((int8_t)y, (int8_t)x);
110+
} // end case
111+
112+
FOSSIL_TEST(xassert_run_of_int16_shortcut) {
113+
int16_t x = 42;
114+
int16_t y = 20;
115+
116+
// Test cases
117+
ASSERT_ITS_EQUAL_I16((int16_t)x, 42);
118+
ASSERT_ITS_EQUAL_I16((int16_t)y, 20);
119+
ASSERT_NOT_EQUAL_I16((int16_t)x, (int16_t)y);
120+
ASSERT_ITS_LESS_THAN_I16((int16_t)y, (int16_t)x);
121+
ASSERT_ITS_LESS_OR_EQUAL_I16((int16_t)y, (int16_t)x);
122+
} // end case
123+
124+
FOSSIL_TEST(xassert_run_of_int32_shortcut) {
125+
int32_t x = 42;
126+
int32_t y = 20;
127+
128+
// Test cases
129+
ASSERT_ITS_EQUAL_I32((int32_t)x, 42);
130+
ASSERT_ITS_EQUAL_I32((int32_t)y, 20);
131+
ASSERT_NOT_EQUAL_I32((int32_t)x, (int32_t)y);
132+
ASSERT_ITS_LESS_THAN_I32((int32_t)y, (int32_t)x);
133+
ASSERT_ITS_LESS_OR_EQUAL_I32((int32_t)y, (int32_t)x);
134+
} // end case
135+
136+
FOSSIL_TEST(xassert_run_of_int64_shortcut) {
137+
int64_t x = 42;
138+
int64_t y = 20;
139+
140+
// Test cases
141+
ASSERT_ITS_EQUAL_I64((int64_t)x, 42);
142+
ASSERT_ITS_EQUAL_I64((int64_t)y, 20);
143+
ASSERT_NOT_EQUAL_I64((int64_t)x, (int64_t)y);
144+
ASSERT_ITS_LESS_THAN_I64((int64_t)y, (int64_t)x);
145+
ASSERT_ITS_LESS_OR_EQUAL_I64((int64_t)y, (int64_t)x);
146+
} // end case
147+
148+
FOSSIL_TEST(xassume_run_of_int) {
149+
int x = 42;
150+
int y = 20;
151+
152+
// Test cases
153+
TEST_ASSUME(x == 42, "Should have passed the test case");
154+
TEST_ASSUME(y == 20, "Should have passed the test case");
155+
TEST_ASSUME(x != y, "Should have passed the test case");
156+
TEST_ASSUME(y < x, "Should have passed the test case");
157+
TEST_ASSUME(y <= x, "Should have passed the test case");
158+
} // end case
159+
160+
FOSSIL_TEST(xassume_run_of_int8) {
161+
int8_t x = 42;
162+
int8_t y = 20;
163+
164+
// Test cases
165+
TEST_ASSUME((int8_t)x == 42, "Should have passed the test case");
166+
TEST_ASSUME((int8_t)y == 20, "Should have passed the test case");
167+
TEST_ASSUME((int8_t)x != (int8_t)y, "Should have passed the test case");
168+
TEST_ASSUME((int8_t)y < (int8_t)x, "Should have passed the test case");
169+
TEST_ASSUME((int8_t)y <= (int8_t)x, "Should have passed the test case");
170+
} // end case
171+
172+
FOSSIL_TEST(xassume_run_of_int16) {
173+
int16_t x = 42;
174+
int16_t y = 20;
175+
176+
// Test cases
177+
TEST_ASSUME((int16_t)x == 42, "Should have passed the test case");
178+
TEST_ASSUME((int16_t)y == 20, "Should have passed the test case");
179+
TEST_ASSUME((int16_t)x != (int16_t)y, "Should have passed the test case");
180+
TEST_ASSUME((int16_t)y < (int16_t)x, "Should have passed the test case");
181+
TEST_ASSUME((int16_t)y <= (int16_t)x, "Should have passed the test case");
182+
} // end case
183+
184+
FOSSIL_TEST(xassume_run_of_int32) {
185+
int32_t x = 42;
186+
int32_t y = 20;
187+
188+
// Test cases
189+
TEST_ASSUME((int32_t)x == 42, "Should have passed the test case");
190+
TEST_ASSUME((int32_t)y == 20, "Should have passed the test case");
191+
TEST_ASSUME((int32_t)x != (int32_t)y, "Should have passed the test case");
192+
TEST_ASSUME((int32_t)y < (int32_t)x, "Should have passed the test case");
193+
TEST_ASSUME((int32_t)y <= (int32_t)x, "Should have passed the test case");
194+
} // end case
195+
196+
FOSSIL_TEST(xassume_run_of_int64) {
197+
int64_t x = 42;
198+
int64_t y = 20;
199+
200+
// Test cases
201+
TEST_ASSUME((int64_t)x == 42, "Should have passed the test case");
202+
TEST_ASSUME((int64_t)y == 20, "Should have passed the test case");
203+
TEST_ASSUME((int64_t)x != (int64_t)y, "Should have passed the test case");
204+
TEST_ASSUME((int64_t)y < (int64_t)x, "Should have passed the test case");
205+
TEST_ASSUME((int64_t)y <= (int64_t)x, "Should have passed the test case");
206+
} // end case
207+
208+
FOSSIL_TEST(xassume_run_of_int8_shortcut) {
209+
int8_t x = 42;
210+
int8_t y = 20;
211+
212+
// Test cases
213+
ASSUME_ITS_EQUAL_I8((int8_t)x, 42);
214+
ASSUME_ITS_EQUAL_I8((int8_t)y, 20);
215+
ASSUME_NOT_EQUAL_I8((int8_t)x, (int8_t)y);
216+
ASSUME_ITS_LESS_THAN_I8((int8_t)y, (int8_t)x);
217+
ASSUME_ITS_LESS_OR_EQUAL_I8((int8_t)y, (int8_t)x);
218+
} // end case
219+
220+
FOSSIL_TEST(xassume_run_of_int16_shortcut) {
221+
int16_t x = 42;
222+
int16_t y = 20;
223+
224+
// Test cases
225+
ASSUME_ITS_EQUAL_I16((int16_t)x, 42);
226+
ASSUME_ITS_EQUAL_I16((int16_t)y, 20);
227+
ASSUME_NOT_EQUAL_I16((int16_t)x, (int16_t)y);
228+
ASSUME_ITS_LESS_THAN_I16((int16_t)y, (int16_t)x);
229+
ASSUME_ITS_LESS_OR_EQUAL_I16((int16_t)y, (int16_t)x);
230+
} // end case
231+
232+
FOSSIL_TEST(xassume_run_of_int32_shortcut) {
233+
int32_t x = 42;
234+
int32_t y = 20;
235+
236+
// Test cases
237+
ASSUME_ITS_EQUAL_I32((int32_t)x, 42);
238+
ASSUME_ITS_EQUAL_I32((int32_t)y, 20);
239+
ASSUME_NOT_EQUAL_I32((int32_t)x, (int32_t)y);
240+
ASSUME_ITS_LESS_THAN_I32((int32_t)y, (int32_t)x);
241+
ASSUME_ITS_LESS_OR_EQUAL_I32((int32_t)y, (int32_t)x);
242+
} // end case
243+
244+
FOSSIL_TEST(xassume_run_of_int64_shortcut) {
245+
int64_t x = 42;
246+
int64_t y = 20;
247+
248+
// Test cases
249+
ASSUME_ITS_EQUAL_I64((int64_t)x, 42);
250+
ASSUME_ITS_EQUAL_I64((int64_t)y, 20);
251+
ASSUME_NOT_EQUAL_I64((int64_t)x, (int64_t)y);
252+
ASSUME_ITS_LESS_THAN_I64((int64_t)y, (int64_t)x);
253+
ASSUME_ITS_LESS_OR_EQUAL_I64((int64_t)y, (int64_t)x);
254+
} // end case
255+
256+
FOSSIL_TEST(xexpect_run_of_int) {
257+
int x = 42;
258+
int y = 20;
259+
260+
// Test cases
261+
TEST_EXPECT(x == 42, "Should have passed the test case");
262+
TEST_EXPECT(y == 20, "Should have passed the test case");
263+
TEST_EXPECT(x != y, "Should have passed the test case");
264+
TEST_EXPECT(y < x, "Should have passed the test case");
265+
TEST_EXPECT(y <= x, "Should have passed the test case");
266+
} // end case
267+
268+
FOSSIL_TEST(xexpect_run_of_int8) {
269+
int8_t x = 42;
270+
int8_t y = 20;
271+
272+
// Test cases
273+
TEST_EXPECT((int8_t)x == 42, "Should have passed the test case");
274+
TEST_EXPECT((int8_t)y == 20, "Should have passed the test case");
275+
TEST_EXPECT((int8_t)x != (int8_t)y, "Should have passed the test case");
276+
TEST_EXPECT((int8_t)y < (int8_t)x, "Should have passed the test case");
277+
TEST_EXPECT((int8_t)y <= (int8_t)x, "Should have passed the test case");
278+
} // end case
279+
280+
FOSSIL_TEST(xexpect_run_of_int16) {
281+
int16_t x = 42;
282+
int16_t y = 20;
283+
284+
// Test cases
285+
TEST_EXPECT((int16_t)x == 42, "Should have passed the test case");
286+
TEST_EXPECT((int16_t)y == 20, "Should have passed the test case");
287+
TEST_EXPECT((int16_t)x != (int16_t)y, "Should have passed the test case");
288+
TEST_EXPECT((int16_t)y < (int16_t)x, "Should have passed the test case");
289+
TEST_EXPECT((int16_t)y <= (int16_t)x, "Should have passed the test case");
290+
} // end case
291+
292+
FOSSIL_TEST(xexpect_run_of_int32) {
293+
int32_t x = 42;
294+
int32_t y = 20;
295+
296+
// Test cases
297+
TEST_EXPECT((int32_t)x == 42, "Should have passed the test case");
298+
TEST_EXPECT((int32_t)y == 20, "Should have passed the test case");
299+
TEST_EXPECT((int32_t)x != (int32_t)y, "Should have passed the test case");
300+
TEST_EXPECT((int32_t)y < (int32_t)x, "Should have passed the test case");
301+
TEST_EXPECT((int32_t)y <= (int32_t)x, "Should have passed the test case");
302+
} // end case
303+
304+
FOSSIL_TEST(xexpect_run_of_int64) {
305+
int64_t x = 42;
306+
int64_t y = 20;
307+
308+
// Test cases
309+
TEST_EXPECT((int64_t)x == 42, "Should have passed the test case");
310+
TEST_EXPECT((int64_t)y == 20, "Should have passed the test case");
311+
TEST_EXPECT((int64_t)x != (int64_t)y, "Should have passed the test case");
312+
TEST_EXPECT((int64_t)y < (int64_t)x, "Should have passed the test case");
313+
TEST_EXPECT((int64_t)y <= (int64_t)x, "Should have passed the test case");
314+
} // end case
315+
316+
FOSSIL_TEST(xexpect_run_of_int8_shortcut) {
317+
int8_t x = 42;
318+
int8_t y = 20;
319+
320+
// Test cases
321+
EXPECT_ITS_EQUAL_I8((int8_t)x, 42);
322+
EXPECT_ITS_EQUAL_I8((int8_t)y, 20);
323+
EXPECT_NOT_EQUAL_I8((int8_t)x, (int8_t)y);
324+
EXPECT_ITS_LESS_THAN_I8((int8_t)y, (int8_t)x);
325+
EXPECT_ITS_LESS_OR_EQUAL_I8((int8_t)y, (int8_t)x);
326+
} // end case
327+
328+
FOSSIL_TEST(xexpect_run_of_int16_shortcut) {
329+
int16_t x = 42;
330+
int16_t y = 20;
331+
332+
// Test cases
333+
EXPECT_ITS_EQUAL_I16((int16_t)x, 42);
334+
EXPECT_ITS_EQUAL_I16((int16_t)y, 20);
335+
EXPECT_NOT_EQUAL_I16((int16_t)x, (int16_t)y);
336+
EXPECT_ITS_LESS_THAN_I16((int16_t)y, (int16_t)x);
337+
EXPECT_ITS_LESS_OR_EQUAL_I16((int16_t)y, (int16_t)x);
338+
} // end case
339+
340+
FOSSIL_TEST(xexpect_run_of_int32_shortcut) {
341+
int32_t x = 42;
342+
int32_t y = 20;
343+
344+
// Test cases
345+
EXPECT_ITS_EQUAL_I32((int32_t)x, 42);
346+
EXPECT_ITS_EQUAL_I32((int32_t)y, 20);
347+
EXPECT_NOT_EQUAL_I32((int32_t)x, (int32_t)y);
348+
EXPECT_ITS_LESS_THAN_I32((int32_t)y, (int32_t)x);
349+
EXPECT_ITS_LESS_OR_EQUAL_I32((int32_t)y, (int32_t)x);
350+
} // end case
351+
352+
FOSSIL_TEST(xexpect_run_of_int64_shortcut) {
353+
int64_t x = 42;
354+
int64_t y = 20;
355+
356+
// Test cases
357+
EXPECT_ITS_EQUAL_I64((int64_t)x, 42);
358+
EXPECT_ITS_EQUAL_I64((int64_t)y, 20);
359+
EXPECT_NOT_EQUAL_I64((int64_t)x, (int64_t)y);
360+
EXPECT_ITS_LESS_THAN_I64((int64_t)y, (int64_t)x);
361+
EXPECT_ITS_LESS_OR_EQUAL_I64((int64_t)y, (int64_t)x);
362+
} // end case
363+
94364
// * * * * * * * * * * * * * * * * * * * * * * * *
95365
// * Fossil Logic Test Pool
96366
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -100,4 +370,26 @@ FOSSIL_TEST_GROUP(tdd_test_group) {
100370
ADD_TEST(xassert_run_of_int16);
101371
ADD_TEST(xassert_run_of_int32);
102372
ADD_TEST(xassert_run_of_int64);
373+
ADD_TEST(xassert_run_of_int8_shortcut);
374+
ADD_TEST(xassert_run_of_int16_shortcut);
375+
ADD_TEST(xassert_run_of_int32_shortcut);
376+
ADD_TEST(xassert_run_of_int64_shortcut);
377+
ADD_TEST(xassume_run_of_int);
378+
ADD_TEST(xassume_run_of_int8);
379+
ADD_TEST(xassume_run_of_int16);
380+
ADD_TEST(xassume_run_of_int32);
381+
ADD_TEST(xassume_run_of_int64);
382+
ADD_TEST(xassume_run_of_int8_shortcut);
383+
ADD_TEST(xassume_run_of_int16_shortcut);
384+
ADD_TEST(xassume_run_of_int32_shortcut);
385+
ADD_TEST(xassume_run_of_int64_shortcut);
386+
ADD_TEST(xexpect_run_of_int);
387+
ADD_TEST(xexpect_run_of_int8);
388+
ADD_TEST(xexpect_run_of_int16);
389+
ADD_TEST(xexpect_run_of_int32);
390+
ADD_TEST(xexpect_run_of_int64);
391+
ADD_TEST(xexpect_run_of_int8_shortcut);
392+
ADD_TEST(xexpect_run_of_int16_shortcut);
393+
ADD_TEST(xexpect_run_of_int32_shortcut);
394+
ADD_TEST(xexpect_run_of_int64_shortcut);
103395
} // end of group

0 commit comments

Comments
 (0)