-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_epsilon.py
48 lines (33 loc) · 1.47 KB
/
test_epsilon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Run the tests by executing, for all test classes:
$ python -m unittest -v test_epsilon.py
or
$ python test_epsilon.py
or, for individual test classes (sorted as appearing in this file):
$ python -m unittest -v test_sphere.Test_zero_in_practice
$ python -m unittest -v test_sphere.Test_equal_in_practice
"""
import unittest
from epsilon import epsilon_distance, zero_in_practice, equal_in_practice
from typing import Final
class Test_zero_in_practice(unittest.TestCase):
def test_GivenAFloatVeryCloseToZero_When_zero_in_practice_ThenReturnTrue(self):
f: Final = epsilon_distance/2.
self.assertTrue(zero_in_practice(f))
def test_GivenAFarEnoughFromZero_When_zero_in_practice_ThenReturnFalse(self):
f: Final = 2.*epsilon_distance
self.assertFalse(zero_in_practice(f))
class Test_equal_in_practice(unittest.TestCase):
def test_GivenAFloat_When_test_equal_in_practice_ThenReturnTrue(self):
f: Final = 3.
self.assertTrue(equal_in_practice(f, f))
def test_GivenAFloatAndA2ndVeryClose_When_test_equal_in_practice_ThenReturnTrue(self):
f_1: Final = 3.
f_2: Final = f_1 + epsilon_distance/2.
self.assertTrue(equal_in_practice(f_1, f_2))
def test_GivenAFloatAndA2ndFarEnough_When_test_equal_in_practice_ThenReturnFalse(self):
f_1: Final = 3.
f_2: Final = f_1 + 2.*epsilon_distance
self.assertFalse(equal_in_practice(f_1, f_2))
if __name__ == '__main__':
unittest.main()