|
1 |
| -# input_element_int_test.py |
2 |
| -# |
3 |
| -# Author: Kangwon Lee (kangwonlee) |
4 |
| -# Date: 22 Oct 2017 |
5 |
| -# |
6 |
| -# Unit tests contributed as part of PR #158, "SISO tf() may not work |
7 |
| -# with numpy arrays with numpy.int elements" |
8 |
| -# |
9 |
| -# Modified: |
10 |
| -# * 29 Dec 2017, RMM - updated file name and added header |
11 |
| - |
12 |
| -import unittest |
| 1 | +"""input_element_int_test.py |
| 2 | +
|
| 3 | +Author: Kangwon Lee (kangwonlee) |
| 4 | +Date: 22 Oct 2017 |
| 5 | +
|
| 6 | +Modified: |
| 7 | +* 29 Dec 2017, RMM - updated file name and added header |
| 8 | +""" |
| 9 | + |
13 | 10 | import numpy as np
|
14 | 11 | import control as ctl
|
15 | 12 |
|
16 |
| -class TestTfInputIntElement(unittest.TestCase): |
17 |
| - # currently these do not pass |
| 13 | +class TestTfInputIntElement: |
| 14 | + """input_element_int_test |
| 15 | +
|
| 16 | + Unit tests contributed as part of PR gh-158, "SISO tf() may not work |
| 17 | + with numpy arrays with numpy.int elements |
| 18 | + """ |
| 19 | + |
18 | 20 | def test_tf_den_with_numpy_int_element(self):
|
19 | 21 | num = 1
|
20 | 22 | den = np.convolve([1, 2, 1], [1, 1, 1])
|
21 | 23 |
|
22 | 24 | sys = ctl.tf(num, den)
|
23 | 25 |
|
24 |
| - self.assertAlmostEqual(1.0, ctl.dcgain(sys)) |
| 26 | + np.testing.assert_array_max_ulp(1.0, ctl.dcgain(sys)) |
25 | 27 |
|
26 | 28 | def test_tf_num_with_numpy_int_element(self):
|
27 | 29 | num = np.convolve([1], [1, 1])
|
28 | 30 | den = np.convolve([1, 2, 1], [1, 1, 1])
|
29 | 31 |
|
30 | 32 | sys = ctl.tf(num, den)
|
31 | 33 |
|
32 |
| - self.assertAlmostEqual(1.0, ctl.dcgain(sys)) |
| 34 | + np.testing.assert_array_max_ulp(1.0, ctl.dcgain(sys)) |
33 | 35 |
|
34 | 36 | # currently these pass
|
35 |
| - def test_tf_input_with_int_element_works(self): |
| 37 | + def test_tf_input_with_int_element(self): |
36 | 38 | num = 1
|
37 | 39 | den = np.convolve([1.0, 2, 1], [1, 1, 1])
|
38 | 40 |
|
39 | 41 | sys = ctl.tf(num, den)
|
40 | 42 |
|
41 |
| - self.assertAlmostEqual(1.0, ctl.dcgain(sys)) |
| 43 | + np.testing.assert_array_max_ulp(1.0, ctl.dcgain(sys)) |
42 | 44 |
|
43 | 45 | def test_ss_input_with_int_element(self):
|
44 |
| - ident = np.matrix(np.identity(2), dtype=int) |
45 |
| - a = np.matrix([[0, 1], |
46 |
| - [-1, -2]], dtype=int) * ident |
47 |
| - b = np.matrix([[0], |
| 46 | + ident = np.eye(2, dtype=int) |
| 47 | + a = np.array([[0, 1], |
| 48 | + [-1, -2]], dtype=int).dot(ident) |
| 49 | + b = np.array([[0], |
48 | 50 | [1]], dtype=int)
|
49 |
| - c = np.matrix([[0, 1]], dtype=int) |
| 51 | + c = np.array([[0, 1]], dtype=int) |
50 | 52 | d = 0
|
51 | 53 |
|
52 | 54 | sys = ctl.ss(a, b, c, d)
|
53 | 55 | sys2 = ctl.ss2tf(sys)
|
54 |
| - self.assertAlmostEqual(ctl.dcgain(sys), ctl.dcgain(sys2)) |
| 56 | + np.testing.assert_array_max_ulp(ctl.dcgain(sys), ctl.dcgain(sys2), |
| 57 | + maxulp=2) |
0 commit comments