|
3 | 3 | import numpy as np |
4 | 4 | import control as ct |
5 | 5 |
|
| 6 | +# Utility function to convert state space system to nlsys |
| 7 | +def ss2io(sys): |
| 8 | + return ct.nlsys( |
| 9 | + sys.updfcn, sys.outfcn, states=sys.nstates, |
| 10 | + inputs=sys.ninputs, outputs=sys.noutputs, dt=sys.dt) |
| 11 | + |
6 | 12 | @pytest.mark.parametrize( |
7 | 13 | "dt1, dt2, dt3", [ |
8 | 14 | (0, 0, 0), |
9 | 15 | (0, 0.1, ValueError), |
10 | 16 | (0, None, 0), |
| 17 | + (0, 'float', 0), |
| 18 | + (0, 'array', 0), |
| 19 | + (None, 'array', None), |
| 20 | + (None, 'array', None), |
11 | 21 | (0, True, ValueError), |
12 | 22 | (0.1, 0, ValueError), |
13 | 23 | (0.1, 0.1, 0.1), |
14 | 24 | (0.1, None, 0.1), |
15 | 25 | (0.1, True, 0.1), |
| 26 | + (0.1, 'array', 0.1), |
| 27 | + (0.1, 'float', 0.1), |
16 | 28 | (None, 0, 0), |
| 29 | + ('float', 0, 0), |
| 30 | + ('array', 0, 0), |
| 31 | + ('float', None, None), |
| 32 | + ('array', None, None), |
17 | 33 | (None, 0.1, 0.1), |
| 34 | + ('array', 0.1, 0.1), |
| 35 | + ('float', 0.1, 0.1), |
18 | 36 | (None, None, None), |
19 | 37 | (None, True, True), |
20 | 38 | (True, 0, ValueError), |
|
25 | 43 | (0.2, 0.1, ValueError), |
26 | 44 | ]) |
27 | 45 | @pytest.mark.parametrize("op", [ct.series, ct.parallel, ct.feedback]) |
28 | | -@pytest.mark.parametrize("type", [ct.StateSpace, ct.ss, ct.tf]) |
| 46 | +@pytest.mark.parametrize("type", [ct.StateSpace, ct.ss, ct.tf, ss2io]) |
29 | 47 | def test_composition(dt1, dt2, dt3, op, type): |
30 | | - # Define the system |
31 | 48 | A, B, C, D = [[1, 1], [0, 1]], [[0], [1]], [[1, 0]], 0 |
32 | | - sys1 = ct.StateSpace(A, B, C, D, dt1) |
33 | | - sys2 = ct.StateSpace(A, B, C, D, dt2) |
| 49 | + Karray = np.array([[1]]) |
| 50 | + kfloat = 1 |
34 | 51 |
|
35 | | - # Convert to the desired form |
36 | | - sys1 = type(sys1) |
37 | | - sys2 = type(sys2) |
| 52 | + # Define the system |
| 53 | + if isinstance(dt1, (int, float)) or dt1 is None: |
| 54 | + sys1 = ct.StateSpace(A, B, C, D, dt1) |
| 55 | + sys1 = type(sys1) |
| 56 | + elif dt1 == 'array': |
| 57 | + sys1 = Karray |
| 58 | + elif dt1 == 'float': |
| 59 | + sys1 = kfloat |
| 60 | + |
| 61 | + if isinstance(dt2, (int, float)) or dt2 is None: |
| 62 | + sys2 = ct.StateSpace(A, B, C, D, dt2) |
| 63 | + sys2 = type(sys2) |
| 64 | + elif dt2 == 'array': |
| 65 | + sys2 = Karray |
| 66 | + elif dt2 == 'float': |
| 67 | + sys2 = kfloat |
38 | 68 |
|
39 | 69 | if inspect.isclass(dt3) and issubclass(dt3, Exception): |
40 | 70 | with pytest.raises(dt3, match="incompatible timebases"): |
|
0 commit comments