1 /* ==========================================
2 Unity Project - A Test Framework for C
3 Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
4 [Released under MIT License. Please refer to license.txt for details]
5 ========================================== */
6
7 #include "unity.h"
8 #define TEST_INSTANCES
9 #include "self_assessment_utils.h"
10
11 static int SetToOneToFailInTearDown;
12 static int SetToOneMeanWeAlreadyCheckedThisGuy;
13
setUp(void)14 void setUp(void)
15 {
16 SetToOneToFailInTearDown = 0;
17 SetToOneMeanWeAlreadyCheckedThisGuy = 0;
18 }
19
tearDown(void)20 void tearDown(void)
21 {
22 endPutcharSpy(); /* Stop suppressing test output */
23 if (SetToOneToFailInTearDown == 1)
24 {
25 /* These will be skipped internally if already failed/ignored */
26 TEST_FAIL_MESSAGE("<= Failed in tearDown");
27 TEST_IGNORE_MESSAGE("<= Ignored in tearDown");
28 }
29 if ((SetToOneMeanWeAlreadyCheckedThisGuy == 0) && (Unity.CurrentTestFailed > 0))
30 {
31 UnityPrint(": [[[[ Test Should Have Passed But Did Not ]]]]");
32 UNITY_OUTPUT_CHAR('\n');
33 }
34 }
35
testDoublesWithinDelta(void)36 void testDoublesWithinDelta(void)
37 {
38 #ifdef UNITY_EXCLUDE_DOUBLE
39 TEST_IGNORE();
40 #else
41 TEST_ASSERT_DOUBLE_WITHIN(0.00003, 187245.03485, 187245.03488);
42 TEST_ASSERT_DOUBLE_WITHIN(1.0, 187245.0, 187246.0);
43 TEST_ASSERT_DOUBLE_WITHIN(0.05, 9273.2549, 9273.2049);
44 TEST_ASSERT_DOUBLE_WITHIN(0.007, -726.93725, -726.94424);
45 #endif
46 }
47
testDoublesNotWithinDelta(void)48 void testDoublesNotWithinDelta(void)
49 {
50 #ifdef UNITY_EXCLUDE_DOUBLE
51 TEST_IGNORE();
52 #else
53 EXPECT_ABORT_BEGIN
54 TEST_ASSERT_DOUBLE_WITHIN(0.05, 9273.2649, 9273.2049);
55 VERIFY_FAILS_END
56 #endif
57 }
58
59
testDoublesEqual(void)60 void testDoublesEqual(void)
61 {
62 #ifdef UNITY_EXCLUDE_DOUBLE
63 TEST_IGNORE();
64 #else
65 TEST_ASSERT_EQUAL_DOUBLE(187245123456.0, 187245123456.0);
66 TEST_ASSERT_EQUAL_DOUBLE(187241234567.5, 187241234567.6);
67 TEST_ASSERT_EQUAL_DOUBLE(9273.2512345649, 9273.25123455699);
68 TEST_ASSERT_EQUAL_DOUBLE(-726.12345693724, -726.1234569374);
69 #endif
70 }
71
testDoublesNotEqual(void)72 void testDoublesNotEqual(void)
73 {
74 #ifdef UNITY_EXCLUDE_DOUBLE
75 TEST_IGNORE();
76 #else
77 EXPECT_ABORT_BEGIN
78 TEST_ASSERT_EQUAL_DOUBLE(9273.9649, 9273.0049);
79 VERIFY_FAILS_END
80 #endif
81 }
82
testDoublesNotEqualNegative1(void)83 void testDoublesNotEqualNegative1(void)
84 {
85 #ifdef UNITY_EXCLUDE_DOUBLE
86 TEST_IGNORE();
87 #else
88 EXPECT_ABORT_BEGIN
89 TEST_ASSERT_EQUAL_DOUBLE(-9273.9649, -9273.0049);
90 VERIFY_FAILS_END
91 #endif
92 }
93
testDoublesNotEqualNegative2(void)94 void testDoublesNotEqualNegative2(void)
95 {
96 #ifdef UNITY_EXCLUDE_DOUBLE
97 TEST_IGNORE();
98 #else
99 EXPECT_ABORT_BEGIN
100 TEST_ASSERT_EQUAL_DOUBLE(-9273.0049, -9273.9649);
101 VERIFY_FAILS_END
102 #endif
103 }
104
testDoublesNotEqualActualNaN(void)105 void testDoublesNotEqualActualNaN(void)
106 {
107 #ifdef UNITY_EXCLUDE_DOUBLE
108 TEST_IGNORE();
109 #else
110 EXPECT_ABORT_BEGIN
111 TEST_ASSERT_EQUAL_DOUBLE(85.963, 0.0 / d_zero);
112 VERIFY_FAILS_END
113 #endif
114 }
115
testDoublesNotEqualExpectedNaN(void)116 void testDoublesNotEqualExpectedNaN(void)
117 {
118 #ifdef UNITY_EXCLUDE_DOUBLE
119 TEST_IGNORE();
120 #else
121 EXPECT_ABORT_BEGIN
122 TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 85.963);
123 VERIFY_FAILS_END
124 #endif
125 }
126
testDoublesEqualBothNaN(void)127 void testDoublesEqualBothNaN(void)
128 {
129 #ifdef UNITY_EXCLUDE_DOUBLE
130 TEST_IGNORE();
131 #else
132 TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 0.0 / d_zero);
133 #endif
134 }
135
testDoublesNotEqualInfNaN(void)136 void testDoublesNotEqualInfNaN(void)
137 {
138 #ifdef UNITY_EXCLUDE_DOUBLE
139 TEST_IGNORE();
140 #else
141 EXPECT_ABORT_BEGIN
142 TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, 0.0 / d_zero);
143 VERIFY_FAILS_END
144 #endif
145 }
146
testDoublesNotEqualNaNInf(void)147 void testDoublesNotEqualNaNInf(void)
148 {
149 #ifdef UNITY_EXCLUDE_DOUBLE
150 TEST_IGNORE();
151 #else
152 EXPECT_ABORT_BEGIN
153 TEST_ASSERT_EQUAL_DOUBLE(0.0 / d_zero, 1.0 / d_zero);
154 VERIFY_FAILS_END
155 #endif
156 }
157
testDoublesNotEqualActualInf(void)158 void testDoublesNotEqualActualInf(void)
159 {
160 #ifdef UNITY_EXCLUDE_DOUBLE
161 TEST_IGNORE();
162 #else
163 EXPECT_ABORT_BEGIN
164 TEST_ASSERT_EQUAL_DOUBLE(321.642, 1.0 / d_zero);
165 VERIFY_FAILS_END
166 #endif
167 }
168
testDoublesNotEqualExpectedInf(void)169 void testDoublesNotEqualExpectedInf(void)
170 {
171 #ifdef UNITY_EXCLUDE_DOUBLE
172 TEST_IGNORE();
173 #else
174 EXPECT_ABORT_BEGIN
175 TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, 321.642);
176 VERIFY_FAILS_END
177 #endif
178 }
179
testDoublesEqualBothInf(void)180 void testDoublesEqualBothInf(void)
181 {
182 #ifdef UNITY_EXCLUDE_DOUBLE
183 TEST_IGNORE();
184 #else
185 TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, 1.0 / d_zero);
186 #endif
187 }
188
testDoublesNotEqualPlusMinusInf(void)189 void testDoublesNotEqualPlusMinusInf(void)
190 {
191 #ifdef UNITY_EXCLUDE_DOUBLE
192 TEST_IGNORE();
193 #else
194 EXPECT_ABORT_BEGIN
195 TEST_ASSERT_EQUAL_DOUBLE(1.0 / d_zero, -1.0 / d_zero);
196 VERIFY_FAILS_END
197 #endif
198 }
199
testDoubleIsPosInf1(void)200 void testDoubleIsPosInf1(void)
201 {
202 #ifdef UNITY_EXCLUDE_DOUBLE
203 TEST_IGNORE();
204 #else
205 TEST_ASSERT_DOUBLE_IS_INF(2.0 / d_zero);
206 #endif
207 }
208
testDoubleIsPosInf2(void)209 void testDoubleIsPosInf2(void)
210 {
211 #ifdef UNITY_EXCLUDE_DOUBLE
212 TEST_IGNORE();
213 #else
214 EXPECT_ABORT_BEGIN
215 TEST_ASSERT_DOUBLE_IS_NOT_INF(2.0 / d_zero);
216 VERIFY_FAILS_END
217 #endif
218 }
219
testDoubleIsNegInf1(void)220 void testDoubleIsNegInf1(void)
221 {
222 #ifdef UNITY_EXCLUDE_DOUBLE
223 TEST_IGNORE();
224 #else
225 TEST_ASSERT_DOUBLE_IS_NEG_INF(-3.0 / d_zero);
226 #endif
227 }
228
testDoubleIsNegInf2(void)229 void testDoubleIsNegInf2(void)
230 {
231 #ifdef UNITY_EXCLUDE_DOUBLE
232 TEST_IGNORE();
233 #else
234 EXPECT_ABORT_BEGIN
235 TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(-3.0 / d_zero);
236 VERIFY_FAILS_END
237 #endif
238 }
239
testDoubleIsNotPosInf1(void)240 void testDoubleIsNotPosInf1(void)
241 {
242 #ifdef UNITY_EXCLUDE_DOUBLE
243 TEST_IGNORE();
244 #else
245 EXPECT_ABORT_BEGIN
246 TEST_ASSERT_DOUBLE_IS_INF(2.0);
247 VERIFY_FAILS_END
248 #endif
249 }
250
testDoubleIsNotPosInf2(void)251 void testDoubleIsNotPosInf2(void)
252 {
253 #ifdef UNITY_EXCLUDE_DOUBLE
254 TEST_IGNORE();
255 #else
256 TEST_ASSERT_DOUBLE_IS_NOT_INF(2.0);
257 #endif
258 }
259
testDoubleIsNotNegInf(void)260 void testDoubleIsNotNegInf(void)
261 {
262 #ifdef UNITY_EXCLUDE_DOUBLE
263 TEST_IGNORE();
264 #else
265 EXPECT_ABORT_BEGIN
266 TEST_ASSERT_DOUBLE_IS_NEG_INF(-999.876);
267 VERIFY_FAILS_END
268 #endif
269 }
270
testDoubleIsNan1(void)271 void testDoubleIsNan1(void)
272 {
273 #ifdef UNITY_EXCLUDE_DOUBLE
274 TEST_IGNORE();
275 #else
276 TEST_ASSERT_DOUBLE_IS_NAN(0.0 / d_zero);
277 #endif
278 }
279
testDoubleIsNan2(void)280 void testDoubleIsNan2(void)
281 {
282 #ifdef UNITY_EXCLUDE_DOUBLE
283 TEST_IGNORE();
284 #else
285 EXPECT_ABORT_BEGIN
286 TEST_ASSERT_DOUBLE_IS_NOT_NAN(0.0 / d_zero);
287 VERIFY_FAILS_END
288 #endif
289 }
290
testDoubleIsNotNan1(void)291 void testDoubleIsNotNan1(void)
292 {
293 #ifdef UNITY_EXCLUDE_DOUBLE
294 TEST_IGNORE();
295 #else
296 EXPECT_ABORT_BEGIN
297 TEST_ASSERT_DOUBLE_IS_NAN(234.9);
298 VERIFY_FAILS_END
299 #endif
300 }
301
testDoubleIsNotNan2(void)302 void testDoubleIsNotNan2(void)
303 {
304 #ifdef UNITY_EXCLUDE_DOUBLE
305 TEST_IGNORE();
306 #else
307 TEST_ASSERT_DOUBLE_IS_NOT_NAN(234.9);
308 #endif
309 }
310
testDoubleInfIsNotNan(void)311 void testDoubleInfIsNotNan(void)
312 {
313 #ifdef UNITY_EXCLUDE_DOUBLE
314 TEST_IGNORE();
315 #else
316 EXPECT_ABORT_BEGIN
317 TEST_ASSERT_DOUBLE_IS_NAN(1.0 / d_zero);
318 VERIFY_FAILS_END
319 #endif
320 }
321
testDoubleNanIsNotInf(void)322 void testDoubleNanIsNotInf(void)
323 {
324 #ifdef UNITY_EXCLUDE_DOUBLE
325 TEST_IGNORE();
326 #else
327 EXPECT_ABORT_BEGIN
328 TEST_ASSERT_DOUBLE_IS_INF(0.0 / d_zero);
329 VERIFY_FAILS_END
330 #endif
331 }
332
testDoubleIsDeterminate1(void)333 void testDoubleIsDeterminate1(void)
334 {
335 #ifdef UNITY_EXCLUDE_DOUBLE
336 TEST_IGNORE();
337 #else
338 TEST_ASSERT_DOUBLE_IS_DETERMINATE(0.0);
339 TEST_ASSERT_DOUBLE_IS_DETERMINATE(123.3);
340 TEST_ASSERT_DOUBLE_IS_DETERMINATE(-88.3);
341 #endif
342 }
343
testDoubleIsDeterminate2(void)344 void testDoubleIsDeterminate2(void)
345 {
346 #ifdef UNITY_EXCLUDE_DOUBLE
347 TEST_IGNORE();
348 #else
349 EXPECT_ABORT_BEGIN
350 TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(-88.3);
351 VERIFY_FAILS_END
352 #endif
353 }
354
testDoubleIsNotDeterminate1(void)355 void testDoubleIsNotDeterminate1(void)
356 {
357 #ifdef UNITY_EXCLUDE_DOUBLE
358 TEST_IGNORE();
359 #else
360 TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(1.0 / d_zero);
361 TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(-1.0 / d_zero);
362 TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(0.0 / d_zero);
363 #endif
364 }
365
testDoubleIsNotDeterminate2(void)366 void testDoubleIsNotDeterminate2(void)
367 {
368 #ifdef UNITY_EXCLUDE_DOUBLE
369 TEST_IGNORE();
370 #else
371 EXPECT_ABORT_BEGIN
372 TEST_ASSERT_DOUBLE_IS_DETERMINATE(-1.0 / d_zero);
373 VERIFY_FAILS_END
374 #endif
375 }
376
testDoubleTraitFailsOnInvalidTrait(void)377 void testDoubleTraitFailsOnInvalidTrait(void)
378 {
379 #ifdef UNITY_EXCLUDE_DOUBLE
380 TEST_IGNORE();
381 #else
382 EXPECT_ABORT_BEGIN
383 UnityAssertDoubleSpecial(1.0, NULL, __LINE__, UNITY_FLOAT_INVALID_TRAIT);
384 VERIFY_FAILS_END
385 #endif
386 }
387
testEqualDoubleArrays(void)388 void testEqualDoubleArrays(void)
389 {
390 #ifdef UNITY_EXCLUDE_DOUBLE
391 TEST_IGNORE();
392 #else
393 double p0[] = {1.0, -8.0, 25.4, -0.123};
394 double p1[] = {1.0, -8.0, 25.4, -0.123};
395 double p2[] = {1.0, -8.0, 25.4, -0.2};
396 double p3[] = {1.0, -23.0, 25.0, -0.26};
397
398 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p0, 1);
399 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p0, 4);
400 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
401 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p2, 3);
402 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p3, 1);
403 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(NULL, NULL, 1);
404 #endif
405 }
406
testNotEqualDoubleArraysExpectedNull(void)407 void testNotEqualDoubleArraysExpectedNull(void)
408 {
409 #ifdef UNITY_EXCLUDE_DOUBLE
410 TEST_IGNORE();
411 #else
412 double* p0 = NULL;
413 double p1[] = {1.0, 8.0, 25.4, 0.252};
414
415 EXPECT_ABORT_BEGIN
416 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
417 VERIFY_FAILS_END
418 #endif
419 }
420
testNotEqualDoubleArraysActualNull(void)421 void testNotEqualDoubleArraysActualNull(void)
422 {
423 #ifdef UNITY_EXCLUDE_DOUBLE
424 TEST_IGNORE();
425 #else
426 double p0[] = {1.0, 8.0, 25.4, 0.253};
427 double* p1 = NULL;
428
429 EXPECT_ABORT_BEGIN
430 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
431 VERIFY_FAILS_END
432 #endif
433 }
434
testNotEqualDoubleArrays1(void)435 void testNotEqualDoubleArrays1(void)
436 {
437 #ifdef UNITY_EXCLUDE_DOUBLE
438 TEST_IGNORE();
439 #else
440 double p0[] = {1.0, 8.0, 25.4, 0.25666666667};
441 double p1[] = {1.0, 8.0, 25.4, 0.25666666666};
442
443 EXPECT_ABORT_BEGIN
444 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
445 VERIFY_FAILS_END
446 #endif
447 }
448
testNotEqualDoubleArrays2(void)449 void testNotEqualDoubleArrays2(void)
450 {
451 #ifdef UNITY_EXCLUDE_DOUBLE
452 TEST_IGNORE();
453 #else
454 double p0[] = {1.0, 8.0, 25.4, 0.253};
455 double p1[] = {2.0, 8.0, 25.4, 0.253};
456
457 EXPECT_ABORT_BEGIN
458 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
459 VERIFY_FAILS_END
460 #endif
461 }
462
testNotEqualDoubleArrays3(void)463 void testNotEqualDoubleArrays3(void)
464 {
465 #ifdef UNITY_EXCLUDE_DOUBLE
466 TEST_IGNORE();
467 #else
468 double p0[] = {1.0, 8.0, 25.4, 0.253};
469 double p1[] = {1.0, 8.0, 25.5, 0.253};
470
471 EXPECT_ABORT_BEGIN
472 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
473 VERIFY_FAILS_END
474 #endif
475 }
476
testNotEqualDoubleArraysNegative1(void)477 void testNotEqualDoubleArraysNegative1(void)
478 {
479 #ifdef UNITY_EXCLUDE_DOUBLE
480 TEST_IGNORE();
481 #else
482 double p0[] = {-1.0, -8.0, -25.4, -0.2566666667};
483 double p1[] = {-1.0, -8.0, -25.4, -0.2566666666};
484
485 EXPECT_ABORT_BEGIN
486 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
487 VERIFY_FAILS_END
488 #endif
489 }
490
testNotEqualDoubleArraysNegative2(void)491 void testNotEqualDoubleArraysNegative2(void)
492 {
493 #ifdef UNITY_EXCLUDE_DOUBLE
494 TEST_IGNORE();
495 #else
496 double p0[] = {-1.0, -8.0, -25.4, -0.253};
497 double p1[] = {-2.0, -8.0, -25.4, -0.253};
498
499 EXPECT_ABORT_BEGIN
500 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
501 VERIFY_FAILS_END
502 #endif
503 }
504
testNotEqualDoubleArraysNegative3(void)505 void testNotEqualDoubleArraysNegative3(void)
506 {
507 #ifdef UNITY_EXCLUDE_DOUBLE
508 TEST_IGNORE();
509 #else
510 double p0[] = {-1.0, -8.0, -25.4, -0.253};
511 double p1[] = {-1.0, -8.0, -25.5, -0.253};
512
513 EXPECT_ABORT_BEGIN
514 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
515 VERIFY_FAILS_END
516 #endif
517 }
518
testEqualDoubleArraysNaN(void)519 void testEqualDoubleArraysNaN(void)
520 {
521 #ifdef UNITY_EXCLUDE_DOUBLE
522 TEST_IGNORE();
523 #else
524 double p0[] = {1.0, 0.0 / d_zero, 25.4, 0.253};
525 double p1[] = {1.0, 0.0 / d_zero, 25.4, 0.253};
526
527 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
528 #endif
529 }
530
testEqualDoubleArraysInf(void)531 void testEqualDoubleArraysInf(void)
532 {
533 #ifdef UNITY_EXCLUDE_DOUBLE
534 TEST_IGNORE();
535 #else
536 double p0[] = {1.0, 1.0 / d_zero, 25.4, 0.253};
537 double p1[] = {1.0, 1.0 / d_zero, 25.4, 0.253};
538
539 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 4);
540 #endif
541 }
542
testNotEqualDoubleArraysLengthZero(void)543 void testNotEqualDoubleArraysLengthZero(void)
544 {
545 #ifdef UNITY_EXCLUDE_DOUBLE
546 TEST_IGNORE();
547 #else
548 double p0[1] = {0.0};
549 double p1[1] = {0.0};
550
551 EXPECT_ABORT_BEGIN
552 TEST_ASSERT_EQUAL_DOUBLE_ARRAY(p0, p1, 0);
553 VERIFY_FAILS_END
554 #endif
555 }
556
testEqualDoubleEachEqual(void)557 void testEqualDoubleEachEqual(void)
558 {
559 #ifdef UNITY_EXCLUDE_DOUBLE
560 TEST_IGNORE();
561 #else
562 double p0[] = {1.0, 1.0, 1.0, 1.0};
563 double p1[] = {-0.123, -0.123, -0.123, -0.123};
564 double p2[] = {25.4, 25.4, 25.4, -0.2};
565 double p3[] = {1.0, -23.0, 25.0, -0.26};
566
567 TEST_ASSERT_EACH_EQUAL_DOUBLE(1.0, p0, 1);
568 TEST_ASSERT_EACH_EQUAL_DOUBLE(1.0, p0, 4);
569 TEST_ASSERT_EACH_EQUAL_DOUBLE(-0.123, p1, 4);
570 TEST_ASSERT_EACH_EQUAL_DOUBLE(25.4, p2, 3);
571 TEST_ASSERT_EACH_EQUAL_DOUBLE(1.0, p3, 1);
572 #endif
573 }
574
testNotEqualDoubleEachEqualActualNull(void)575 void testNotEqualDoubleEachEqualActualNull(void)
576 {
577 #ifdef UNITY_EXCLUDE_DOUBLE
578 TEST_IGNORE();
579 #else
580 double* p0 = NULL;
581
582 EXPECT_ABORT_BEGIN
583 TEST_ASSERT_EACH_EQUAL_DOUBLE(5, p0, 4);
584 VERIFY_FAILS_END
585 #endif
586 }
587
testNotEqualDoubleEachEqual1(void)588 void testNotEqualDoubleEachEqual1(void)
589 {
590 #ifdef UNITY_EXCLUDE_DOUBLE
591 TEST_IGNORE();
592 #else
593 double p0[] = {0.253, 8.0, 0.253, 0.253};
594
595 EXPECT_ABORT_BEGIN
596 TEST_ASSERT_EACH_EQUAL_DOUBLE(0.253, p0, 4);
597 VERIFY_FAILS_END
598 #endif
599 }
600
testNotEqualDoubleEachEqual2(void)601 void testNotEqualDoubleEachEqual2(void)
602 {
603 #ifdef UNITY_EXCLUDE_DOUBLE
604 TEST_IGNORE();
605 #else
606 double p0[] = {8.0, 8.0, 8.0, 0.253};
607
608 EXPECT_ABORT_BEGIN
609 TEST_ASSERT_EACH_EQUAL_DOUBLE(8.0, p0, 4);
610 VERIFY_FAILS_END
611 #endif
612 }
613
testNotEqualDoubleEachEqual3(void)614 void testNotEqualDoubleEachEqual3(void)
615 {
616 #ifdef UNITY_EXCLUDE_DOUBLE
617 TEST_IGNORE();
618 #else
619 double p0[] = {1.0, 1.0, 1.0, 0.253};
620
621 EXPECT_ABORT_BEGIN
622 TEST_ASSERT_EACH_EQUAL_DOUBLE(1.0, p0, 4);
623 VERIFY_FAILS_END
624 #endif
625 }
626
testNotEqualDoubleEachEqualNegative1(void)627 void testNotEqualDoubleEachEqualNegative1(void)
628 {
629 #ifdef UNITY_EXCLUDE_DOUBLE
630 TEST_IGNORE();
631 #else
632 double p0[] = {-1.0, -0.253, -0.253, -0.253};
633
634 EXPECT_ABORT_BEGIN
635 TEST_ASSERT_EACH_EQUAL_DOUBLE(-0.253, p0, 4);
636 VERIFY_FAILS_END
637 #endif
638 }
639
testNotEqualDoubleEachEqualNegative2(void)640 void testNotEqualDoubleEachEqualNegative2(void)
641 {
642 #ifdef UNITY_EXCLUDE_DOUBLE
643 TEST_IGNORE();
644 #else
645 double p0[] = {-25.4, -8.0, -25.4, -25.4};
646
647 EXPECT_ABORT_BEGIN
648 TEST_ASSERT_EACH_EQUAL_DOUBLE(-25.4, p0, 4);
649 VERIFY_FAILS_END
650 #endif
651 }
652
testNotEqualDoubleEachEqualNegative3(void)653 void testNotEqualDoubleEachEqualNegative3(void)
654 {
655 #ifdef UNITY_EXCLUDE_DOUBLE
656 TEST_IGNORE();
657 #else
658 double p0[] = {-8.0, -8.0, -8.0, -0.253};
659
660 EXPECT_ABORT_BEGIN
661 TEST_ASSERT_EACH_EQUAL_DOUBLE(-8.0, p0, 4);
662 VERIFY_FAILS_END
663 #endif
664 }
665
testEqualDoubleEachEqualNaN(void)666 void testEqualDoubleEachEqualNaN(void)
667 {
668 #ifdef UNITY_EXCLUDE_DOUBLE
669 TEST_IGNORE();
670 #else
671 double p0[] = {0.0 / d_zero, 0.0 / d_zero, 0.0 / d_zero, 0.0 / d_zero};
672
673 TEST_ASSERT_EACH_EQUAL_DOUBLE(0.0 / d_zero, p0, 4);
674 #endif
675 }
676
testEqualDoubleEachEqualInf(void)677 void testEqualDoubleEachEqualInf(void)
678 {
679 #ifdef UNITY_EXCLUDE_DOUBLE
680 TEST_IGNORE();
681 #else
682 double p0[] = {1.0 / d_zero, 1.0 / d_zero, 25.4, 0.253};
683
684 TEST_ASSERT_EACH_EQUAL_DOUBLE(1.0 / d_zero, p0, 2);
685 #endif
686 }
687
testNotEqualDoubleEachEqualLengthZero(void)688 void testNotEqualDoubleEachEqualLengthZero(void)
689 {
690 #ifdef UNITY_EXCLUDE_DOUBLE
691 TEST_IGNORE();
692 #else
693 double p0[1] = {0.0};
694
695 EXPECT_ABORT_BEGIN
696 TEST_ASSERT_EACH_EQUAL_DOUBLE(0.0, p0, 0);
697 VERIFY_FAILS_END
698 #endif
699 }
700
testDoublePrinting(void)701 void testDoublePrinting(void)
702 {
703 #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
704 TEST_IGNORE();
705 #else
706 TEST_ASSERT_EQUAL_PRINT_FLOATING("0", 0.0);
707 TEST_ASSERT_EQUAL_PRINT_FLOATING("4.99e-07", 0.000000499);
708 TEST_ASSERT_EQUAL_PRINT_FLOATING("5.0000005e-07", 0.00000050000005);
709 TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469499", 0.100469499);
710 TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 0.9999999995); /*Rounding to int place*/
711 TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 1.0);
712 TEST_ASSERT_EQUAL_PRINT_FLOATING("1.25", 1.25);
713 TEST_ASSERT_EQUAL_PRINT_FLOATING("7.99999999", 7.99999999); /*Not rounding*/
714 TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0000002", 16.0000002);
715 TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0000004", 16.0000004);
716 TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0000006", 16.0000006);
717 TEST_ASSERT_EQUAL_PRINT_FLOATING("999999999", 999999999.0); /*Last full print integer*/
718
719 TEST_ASSERT_EQUAL_PRINT_FLOATING("0", -0.0); /* -0 no supported on all targets */
720 TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.99e-07", -0.000000499);
721 TEST_ASSERT_EQUAL_PRINT_FLOATING("-5.0000005e-07", -0.00000050000005);
722 TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469499", -0.100469499);
723 TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -0.9999999995); /*Rounding to int place*/
724 TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -1.0);
725 TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.25", -1.25);
726 TEST_ASSERT_EQUAL_PRINT_FLOATING("-7.99999999", -7.99999999); /*Not rounding*/
727 TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0000002", -16.0000002);
728 TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0000004", -16.0000004);
729 TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0000006", -16.0000006);
730 TEST_ASSERT_EQUAL_PRINT_FLOATING("-999999999", -999999999.0); /*Last full print integer*/
731
732 TEST_ASSERT_EQUAL_PRINT_FLOATING("0.1004695", 0.10046949999999999);
733 TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967295.9);
734 TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967296.0);
735 TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 9999999995.0);
736 TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199254740990.0);
737 TEST_ASSERT_EQUAL_PRINT_FLOATING("7e+100", 7.0e+100);
738 TEST_ASSERT_EQUAL_PRINT_FLOATING("3e+200", 3.0e+200);
739 TEST_ASSERT_EQUAL_PRINT_FLOATING("9.23456789e+300", 9.23456789e+300);
740
741 TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.1004695", -0.10046949999999999);
742 TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.2949673e+09", -4294967295.9);
743 TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.2949673e+09", -4294967296.0);
744 TEST_ASSERT_EQUAL_PRINT_FLOATING("-7e+100", -7.0e+100);
745 #endif
746 }
747
testDoublePrintingRoundTiesToEven(void)748 void testDoublePrintingRoundTiesToEven(void)
749 {
750 #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
751 TEST_IGNORE();
752 #else
753 #ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
754 TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00000001e+10", 10000000050.0);
755 TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199245000000.0);
756 #else /* Default to Round ties to even */
757 TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 10000000050.0);
758 TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719924e+15", 9007199245000000.0);
759 #endif
760 #endif
761 }
762
testDoublePrintingInfinityAndNaN(void)763 void testDoublePrintingInfinityAndNaN(void)
764 {
765 #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
766 TEST_IGNORE();
767 #else
768 TEST_ASSERT_EQUAL_PRINT_FLOATING("inf", 1.0 / d_zero);
769 TEST_ASSERT_EQUAL_PRINT_FLOATING("-inf", -1.0 / d_zero);
770
771 TEST_ASSERT_EQUAL_PRINT_FLOATING("nan", 0.0 / d_zero);
772 #endif
773 }
774