|
6 | 6 |
|
7 | 7 |
|
8 | 8 | class TestPrecision: |
9 | | - |
10 | | - # Start a Matlab session |
| 9 | + |
| 10 | + # Start a Matlab session before running any tests |
11 | 11 | @classmethod |
12 | 12 | def setup_class(cls): |
13 | 13 | cls.mlab = tu.connect_to_matlab() |
14 | | - |
15 | | - # Tear down the Matlab session |
| 14 | + |
| 15 | + # Tear down the Matlab session after running all the tests |
16 | 16 | @classmethod |
17 | 17 | def teardown_class(cls): |
18 | 18 | tu.stop_matlab(cls.mlab) |
19 | | - |
20 | | - |
| 19 | + |
| 20 | + |
21 | 21 | # Pass a 64-bit floating number through the signal path |
22 | 22 | def test_float64_roundtrip(self): |
23 | 23 | for i in range(0,10): |
24 | 24 | val = np.float64(rd.random()) |
25 | 25 | res = self.mlab.run_func('precision_pass.m', {'val':val})['result'] |
26 | 26 | npt.assert_almost_equal(res, val, decimal=8, err_msg="Float64 roundtrip error") |
27 | | - |
28 | | - |
| 27 | + |
29 | 28 | # Add two 64-bit floating number in Matlab and return the sum |
30 | 29 | def test_float64_sum(self): |
31 | 30 | for i in range(0,10): |
32 | 31 | val1 = np.float64(rd.random()) |
33 | 32 | val2 = np.float64(rd.random()) |
34 | | - |
| 33 | + |
35 | 34 | res = self.mlab.run_func('precision_sum.m', {'val1':val1, 'val2':val2})['result'] |
36 | 35 | npt.assert_almost_equal(res, val1 + val2, decimal=8, err_msg="Float64 sum error") |
37 | | - |
38 | | - |
| 36 | + |
39 | 37 | # Multiply two 64-bit floating number in Matlab and return the product |
40 | 38 | def test_float64_multiply(self): |
41 | 39 | for i in range(0,10): |
42 | 40 | val1 = np.float64(rd.random()) |
43 | 41 | val2 = np.float64(rd.random()) |
44 | | - |
| 42 | + |
45 | 43 | res = self.mlab.run_func('precision_multiply.m', {'val1':val1, 'val2':val2})['result'] |
46 | 44 | npt.assert_almost_equal(res, val1 * val2, decimal=8, err_msg="Float64 multiply error") |
47 | | - |
48 | | - |
| 45 | + |
49 | 46 | # Make a division in Matlab and return the results |
50 | 47 | def test_float64_divide(self): |
51 | 48 | for i in range(0,10): |
52 | 49 | val1 = np.float64(rd.random()) |
53 | 50 | val2 = np.float64(rd.random()) |
54 | | - |
| 51 | + |
55 | 52 | res = self.mlab.run_func('precision_divide.m', {'val1':val1, 'val2':val2})['result'] |
56 | 53 | npt.assert_almost_equal(res, val1 / val2, decimal=8, err_msg="Float64 divide error") |
57 | | - |
58 | | - |
| 54 | + |
59 | 55 | # Calculate the square root in Matlab and return the result |
60 | 56 | def test_float64_sqrt(self): |
61 | 57 | for i in range(0,10): |
62 | 58 | val = np.float64(rd.random()) |
63 | | - |
| 59 | + |
64 | 60 | res = self.mlab.run_func('precision_sqrt.m', {'val':val})['result'] |
65 | 61 | npt.assert_almost_equal(res, np.sqrt(val), decimal=8, err_msg="Float64 square root error") |
0 commit comments