Skip to content

Commit 534e5d3

Browse files
committed
New floating point integration test added
1 parent e9877ad commit 534e5d3

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
  fp:zero_equals  OK [0 of 10 failed]
2+
  fp:infinities  OK [0 of 4 failed]
3+
  fp:nans  OK [0 of 6 failed]
4+
  fp:comparisons  [6 tests] 
5+
  [1/6] fp:comparisons  OK [0 of 1 failed]
6+
  [2/6] fp:comparisons  OK [0 of 1 failed]
7+
  [3/6] fp:comparisons  OK [0 of 1 failed]
8+
  [4/6] fp:comparisons  OK [0 of 1 failed]
9+
  [5/6] fp:comparisons  OK [0 of 1 failed]
10+
  [6/6] fp:comparisons  OK [0 of 1 failed]
11+
12+
All tests passed [0 of 9 failed]
13+

tests/floating_point_tests.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#define YUKTI_TEST_IMPLEMENTATION
2+
#include "../yukti.h"
3+
#include <stdint.h>
4+
#include <float.h>
5+
6+
YT_TEST (fp, zero_equals)
7+
{
8+
double a = 67329.234; // Just some number
9+
double b = 67329.234;
10+
11+
YT_EQ_DOUBLE_ABS (a, b, FLT_EPSILON);
12+
YT_EQ_DOUBLE_ABS (0.0, a - b, FLT_EPSILON);
13+
YT_EQ_DOUBLE_ABS (0.0, b - a, FLT_EPSILON);
14+
YT_EQ_DOUBLE_ABS (-0.0, a - b, FLT_EPSILON);
15+
YT_EQ_DOUBLE_ABS (-0.0, b - a, FLT_EPSILON);
16+
17+
YT_EQ_DOUBLE_REL (a, b, FLT_EPSILON);
18+
YT_EQ_DOUBLE_REL (0.0, a - b, FLT_EPSILON);
19+
YT_EQ_DOUBLE_REL (0.0, b - a, FLT_EPSILON);
20+
YT_EQ_DOUBLE_REL (-0.0, a - b, FLT_EPSILON);
21+
YT_EQ_DOUBLE_REL (-0.0, b - a, FLT_EPSILON);
22+
YT_END();
23+
}
24+
25+
YT_TEST (fp, infinities)
26+
{
27+
double a = -INFINITY;
28+
double b = INFINITY;
29+
double c = 0.1;
30+
31+
YT_EQ_DOUBLE_ABS (a, b, FLT_EPSILON);
32+
YT_NEQ_DOUBLE_ABS (a, c, FLT_EPSILON);
33+
34+
YT_EQ_DOUBLE_REL (a, b, FLT_EPSILON);
35+
YT_NEQ_DOUBLE_REL (a, c, FLT_EPSILON);
36+
YT_END();
37+
}
38+
39+
YT_TEST (fp, nans)
40+
{
41+
double a = -NAN;
42+
double b = NAN;
43+
double c = INFINITY;
44+
double d = 0.1;
45+
46+
YT_NEQ_DOUBLE_ABS (a, b, FLT_EPSILON);
47+
YT_NEQ_DOUBLE_ABS (a, c, FLT_EPSILON);
48+
YT_NEQ_DOUBLE_ABS (a, d, FLT_EPSILON);
49+
50+
YT_NEQ_DOUBLE_REL (a, b, FLT_EPSILON);
51+
YT_NEQ_DOUBLE_REL (a, c, FLT_EPSILON);
52+
YT_NEQ_DOUBLE_REL (a, d, FLT_EPSILON);
53+
YT_END();
54+
}
55+
56+
YT_TESTP (fp, comparisons, double)
57+
{
58+
double start = YT_ARG_0();
59+
60+
double product = 0;
61+
for (int i = 0; i < 100; i++) {
62+
product += start;
63+
}
64+
65+
YT_EQ_DOUBLE_REL (product, start * 100.0, FLT_EPSILON);
66+
YT_END();
67+
}
68+
69+
void yt_reset()
70+
{
71+
}
72+
73+
int main (void)
74+
{
75+
YT_INIT();
76+
zero_equals();
77+
infinities();
78+
nans();
79+
comparisons (6, YT_ARG (double){ 0.16777226, 0.1, -0.1, 5.0, -16777226.1, 16777226.1 });
80+
YT_RETURN_WITH_REPORT();
81+
}

0 commit comments

Comments
 (0)