Skip to content

Commit d2c11b6

Browse files
committed
Test floating point numbers the right way
1 parent 345b873 commit d2c11b6

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

integration_tests/test_math.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
ldexp, fabs, gcd, lcm)
33
from ltypes import i32, f64
44

5+
eps: f64
6+
eps = 1e-12
57

68
def test_factorial_1():
79
i: i32
@@ -30,31 +32,31 @@ def test_isqrt():
3032
def test_degrees():
3133
i: f64
3234
i = degrees(32.2)
33-
assert i == 1844.924100321251
35+
assert abs(i - 1844.924100321251) < eps
3436

3537

3638
def test_radians():
3739
i: f64
3840
i = radians(100.1)
39-
assert i == 1.7470745812463238
41+
assert abs(i - 1.7470745812463238) < eps
4042

4143

4244
def test_exp():
4345
i: f64
4446
i = exp(2.34)
45-
assert i == 10.381236562731843
47+
assert abs(i - 10.381236562731843) < eps
4648

4749

4850
def test_pow():
4951
i: f64
5052
i = pow(2.4, 4.3)
51-
assert i == 43.14280115650323
53+
assert abs(i - 43.14280115650323) < eps
5254

5355

5456
def test_ldexp():
5557
i: f64
5658
i = ldexp(23.3, 2)
57-
assert i == 93.2
59+
assert abs(i - 93.2) < eps
5860

5961

6062
def test_fabs():
@@ -84,15 +86,18 @@ def test_lcm():
8486
assert i == 84
8587

8688

87-
test_factorial_1()
88-
test_comb()
89-
test_isqrt()
90-
test_perm()
91-
test_degrees()
92-
test_radians()
93-
test_exp()
94-
test_pow()
95-
test_fabs()
96-
test_ldexp()
97-
test_gcd()
98-
test_lcm()
89+
def check():
90+
test_factorial_1()
91+
test_comb()
92+
test_isqrt()
93+
test_perm()
94+
test_degrees()
95+
test_radians()
96+
test_exp()
97+
test_pow()
98+
test_fabs()
99+
test_ldexp()
100+
test_gcd()
101+
test_lcm()
102+
103+
check()

0 commit comments

Comments
 (0)