Skip to content

Commit 7674d30

Browse files
committed
make tests work with pre #431 source code state
revert this commit when merging into/with #431 (remove statesp_test.py::test_copy_constructor_nodt if not applicable)
1 parent 3d9b606 commit 7674d30

File tree

6 files changed

+43
-181
lines changed

6 files changed

+43
-181
lines changed

control/tests/config_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def test_change_default_dt(self, dt):
244244
# lambda t, x, u: x, inputs=1, outputs=1)
245245
# assert nlsys.dt == dt
246246

247+
@pytest.mark.skip("implemented in gh-431")
247248
def test_change_default_dt_static(self):
248249
"""Test that static gain systems always have dt=None"""
249250
ct.set_defaults('control', default_dt=0)

control/tests/discrete_test.py

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import numpy as np
77
import pytest
88

9-
from control import (StateSpace, TransferFunction, bode, common_timebase,
10-
evalfr, feedback, forced_response, impulse_response,
11-
isctime, isdtime, rss, sample_system, step_response,
12-
timebase)
9+
from control import StateSpace, TransferFunction, feedback, step_response, \
10+
isdtime, timebase, isctime, sample_system, bode, impulse_response, \
11+
evalfr, timebaseEqual, forced_response, rss
1312

1413

1514
class TestDiscrete:
@@ -52,21 +51,13 @@ class Tsys:
5251

5352
return T
5453

55-
def testCompatibleTimebases(self, tsys):
56-
"""test that compatible timebases don't throw errors and vice versa"""
57-
common_timebase(tsys.siso_ss1.dt, tsys.siso_tf1.dt)
58-
common_timebase(tsys.siso_ss1.dt, tsys.siso_ss1c.dt)
59-
common_timebase(tsys.siso_ss1d.dt, tsys.siso_ss1.dt)
60-
common_timebase(tsys.siso_ss1.dt, tsys.siso_ss1d.dt)
61-
common_timebase(tsys.siso_ss1.dt, tsys.siso_ss1d.dt)
62-
common_timebase(tsys.siso_ss1d.dt, tsys.siso_ss3d.dt)
63-
common_timebase(tsys.siso_ss3d.dt, tsys.siso_ss1d.dt)
64-
with pytest.raises(ValueError):
65-
# cont + discrete
66-
common_timebase(tsys.siso_ss1d.dt, tsys.siso_ss1c.dt)
67-
with pytest.raises(ValueError):
68-
# incompatible discrete
69-
common_timebase(tsys.siso_ss1d.dt, tsys.siso_ss2d.dt)
54+
def testTimebaseEqual(self, tsys):
55+
"""Test for equal timebases and not so equal ones"""
56+
assert timebaseEqual(tsys.siso_ss1, tsys.siso_tf1)
57+
assert timebaseEqual(tsys.siso_ss1, tsys.siso_ss1c)
58+
assert not timebaseEqual(tsys.siso_ss1d, tsys.siso_ss1c)
59+
assert not timebaseEqual(tsys.siso_ss1d, tsys.siso_ss2d)
60+
assert not timebaseEqual(tsys.siso_ss1d, tsys.siso_ss3d)
7061

7162
def testSystemInitialization(self, tsys):
7263
# Check to make sure systems are discrete time with proper variables
@@ -84,18 +75,6 @@ def testSystemInitialization(self, tsys):
8475
assert tsys.siso_tf2d.dt == 0.2
8576
assert tsys.siso_tf3d.dt is True
8677

87-
# keyword argument check
88-
# dynamic systems
89-
assert TransferFunction(1, [1, 1], dt=0.1).dt == 0.1
90-
assert TransferFunction(1, [1, 1], 0.1).dt == 0.1
91-
assert StateSpace(1,1,1,1, dt=0.1).dt == 0.1
92-
assert StateSpace(1,1,1,1, 0.1).dt == 0.1
93-
# static gain system, dt argument should still override default dt
94-
assert TransferFunction(1, [1,], dt=0.1).dt == 0.1
95-
assert TransferFunction(1, [1,], 0.1).dt == 0.1
96-
assert StateSpace(0,0,1,1, dt=0.1).dt == 0.1
97-
assert StateSpace(0,0,1,1, 0.1).dt == 0.1
98-
9978
def testCopyConstructor(self, tsys):
10079
for sys in (tsys.siso_ss1, tsys.siso_ss1c, tsys.siso_ss1d):
10180
newsys = StateSpace(sys)
@@ -135,7 +114,6 @@ def test_timebase_conversions(self, tsys):
135114
assert timebase(tf1*tf2) == timebase(tf2)
136115
assert timebase(tf1*tf3) == timebase(tf3)
137116
assert timebase(tf1*tf4) == timebase(tf4)
138-
assert timebase(tf3*tf4) == timebase(tf4)
139117
assert timebase(tf2*tf1) == timebase(tf2)
140118
assert timebase(tf3*tf1) == timebase(tf3)
141119
assert timebase(tf4*tf1) == timebase(tf4)
@@ -150,36 +128,33 @@ def test_timebase_conversions(self, tsys):
150128

151129
# Make sure discrete time without sampling is converted correctly
152130
assert timebase(tf3*tf3) == timebase(tf3)
153-
assert timebase(tf3*tf4) == timebase(tf4)
154131
assert timebase(tf3+tf3) == timebase(tf3)
155-
assert timebase(tf3+tf4) == timebase(tf4)
156132
assert timebase(feedback(tf3, tf3)) == timebase(tf3)
157-
assert timebase(feedback(tf3, tf4)) == timebase(tf4)
158133

159134
# Make sure all other combinations are errors
160-
with pytest.raises(ValueError, match="incompatible timebases"):
135+
with pytest.raises(ValueError, match="different sampling times"):
161136
tf2 * tf3
162-
with pytest.raises(ValueError, match="incompatible timebases"):
137+
with pytest.raises(ValueError, match="different sampling times"):
163138
tf3 * tf2
164-
with pytest.raises(ValueError, match="incompatible timebases"):
139+
with pytest.raises(ValueError, match="different sampling times"):
165140
tf2 * tf4
166-
with pytest.raises(ValueError, match="incompatible timebases"):
141+
with pytest.raises(ValueError, match="different sampling times"):
167142
tf4 * tf2
168-
with pytest.raises(ValueError, match="incompatible timebases"):
143+
with pytest.raises(ValueError, match="different sampling times"):
169144
tf2 + tf3
170-
with pytest.raises(ValueError, match="incompatible timebases"):
145+
with pytest.raises(ValueError, match="different sampling times"):
171146
tf3 + tf2
172-
with pytest.raises(ValueError, match="incompatible timebases"):
147+
with pytest.raises(ValueError, match="different sampling times"):
173148
tf2 + tf4
174-
with pytest.raises(ValueError, match="incompatible timebases"):
149+
with pytest.raises(ValueError, match="different sampling times"):
175150
tf4 + tf2
176-
with pytest.raises(ValueError, match="incompatible timebases"):
151+
with pytest.raises(ValueError, match="different sampling times"):
177152
feedback(tf2, tf3)
178-
with pytest.raises(ValueError, match="incompatible timebases"):
153+
with pytest.raises(ValueError, match="different sampling times"):
179154
feedback(tf3, tf2)
180-
with pytest.raises(ValueError, match="incompatible timebases"):
155+
with pytest.raises(ValueError, match="different sampling times"):
181156
feedback(tf2, tf4)
182-
with pytest.raises(ValueError, match="incompatible timebases"):
157+
with pytest.raises(ValueError, match="different sampling times"):
183158
feedback(tf4, tf2)
184159

185160
def testisdtime(self, tsys):
@@ -237,7 +212,6 @@ def testAddition(self, tsys):
237212
sys = tsys.siso_ss1c + tsys.siso_ss1c
238213
sys = tsys.siso_ss1d + tsys.siso_ss1d
239214
sys = tsys.siso_ss3d + tsys.siso_ss3d
240-
sys = tsys.siso_ss1d + tsys.siso_ss3d
241215

242216
with pytest.raises(ValueError):
243217
StateSpace.__add__(tsys.mimo_ss1c, tsys.mimo_ss1d)
@@ -254,7 +228,6 @@ def testAddition(self, tsys):
254228
sys = tsys.siso_tf1c + tsys.siso_tf1c
255229
sys = tsys.siso_tf1d + tsys.siso_tf1d
256230
sys = tsys.siso_tf2d + tsys.siso_tf2d
257-
sys = tsys.siso_tf1d + tsys.siso_tf3d
258231

259232
with pytest.raises(ValueError):
260233
TransferFunction.__add__(tsys.siso_tf1c, tsys.siso_tf1d)
@@ -279,7 +252,6 @@ def testMultiplication(self, tsys):
279252
sys = tsys.siso_ss1d * tsys.siso_ss1
280253
sys = tsys.siso_ss1c * tsys.siso_ss1c
281254
sys = tsys.siso_ss1d * tsys.siso_ss1d
282-
sys = tsys.siso_ss1d * tsys.siso_ss3d
283255

284256
with pytest.raises(ValueError):
285257
StateSpace.__mul__(tsys.mimo_ss1c, tsys.mimo_ss1d)
@@ -295,7 +267,6 @@ def testMultiplication(self, tsys):
295267
sys = tsys.siso_tf1d * tsys.siso_tf1
296268
sys = tsys.siso_tf1c * tsys.siso_tf1c
297269
sys = tsys.siso_tf1d * tsys.siso_tf1d
298-
sys = tsys.siso_tf1d * tsys.siso_tf3d
299270

300271
with pytest.raises(ValueError):
301272
TransferFunction.__mul__(tsys.siso_tf1c, tsys.siso_tf1d)
@@ -322,7 +293,6 @@ def testFeedback(self, tsys):
322293
sys = feedback(tsys.siso_ss1d, tsys.siso_ss1)
323294
sys = feedback(tsys.siso_ss1c, tsys.siso_ss1c)
324295
sys = feedback(tsys.siso_ss1d, tsys.siso_ss1d)
325-
sys = feedback(tsys.siso_ss1d, tsys.siso_ss3d)
326296

327297
with pytest.raises(ValueError):
328298
feedback(tsys.mimo_ss1c, tsys.mimo_ss1d)
@@ -338,7 +308,6 @@ def testFeedback(self, tsys):
338308
sys = feedback(tsys.siso_tf1d, tsys.siso_tf1)
339309
sys = feedback(tsys.siso_tf1c, tsys.siso_tf1c)
340310
sys = feedback(tsys.siso_tf1d, tsys.siso_tf1d)
341-
sys = feedback(tsys.siso_tf1d, tsys.siso_tf3d)
342311

343312
with pytest.raises(ValueError):
344313
feedback(tsys.siso_tf1c, tsys.siso_tf1d)

control/tests/iosys_test.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ class TSys:
2929
"""Return some test systems"""
3030
# Create a single input/single output linear system
3131
T.siso_linsys = ct.StateSpace(
32-
[[-1, 1], [0, -2]], [[0], [1]], [[1, 0]], [[0]])
32+
[[-1, 1], [0, -2]], [[0], [1]], [[1, 0]], [[0]], 0)
3333

3434
# Create a multi input/multi output linear system
3535
T.mimo_linsys1 = ct.StateSpace(
3636
[[-1, 1], [0, -2]], [[1, 0], [0, 1]],
37-
[[1, 0], [0, 1]], np.zeros((2, 2)))
37+
[[1, 0], [0, 1]], np.zeros((2, 2)), 0)
3838

3939
# Create a multi input/multi output linear system
4040
T.mimo_linsys2 = ct.StateSpace(
4141
[[-1, 1], [0, -2]], [[0, 1], [1, 0]],
42-
[[1, 0], [0, 1]], np.zeros((2, 2)))
42+
[[1, 0], [0, 1]], np.zeros((2, 2)), 0)
4343

4444
# Create simulation parameters
4545
T.T = np.linspace(0, 10, 100)
@@ -281,7 +281,7 @@ def test_algebraic_loop(self, tsys):
281281
linsys = tsys.siso_linsys
282282
lnios = ios.LinearIOSystem(linsys)
283283
nlios = ios.NonlinearIOSystem(None, \
284-
lambda t, x, u, params: u*u, inputs=1, outputs=1)
284+
lambda t, x, u, params: u*u, inputs=1, outputs=1, dt=0)
285285
nlios1 = nlios.copy()
286286
nlios2 = nlios.copy()
287287

@@ -310,7 +310,7 @@ def test_algebraic_loop(self, tsys):
310310
iosys = ios.InterconnectedSystem(
311311
(lnios, nlios), # linear system w/ nonlinear feedback
312312
((1,), # feedback interconnection (sig to 0)
313-
(0, (1, 0, -1))),
313+
(0, (1, 0, -1))),
314314
0, # input to linear system
315315
0 # output from linear system
316316
)
@@ -331,7 +331,7 @@ def test_algebraic_loop(self, tsys):
331331

332332
# Algebraic loop due to feedthrough term
333333
linsys = ct.StateSpace(
334-
[[-1, 1], [0, -2]], [[0], [1]], [[1, 0]], [[1]])
334+
[[-1, 1], [0, -2]], [[0], [1]], [[1, 0]], [[1]], 0)
335335
lnios = ios.LinearIOSystem(linsys)
336336
iosys = ios.InterconnectedSystem(
337337
(nlios, lnios), # linear system w/ nonlinear feedback
@@ -374,7 +374,7 @@ def test_rmul(self, tsys):
374374
# Also creates a nested interconnected system
375375
ioslin = ios.LinearIOSystem(tsys.siso_linsys)
376376
nlios = ios.NonlinearIOSystem(None, \
377-
lambda t, x, u, params: u*u, inputs=1, outputs=1)
377+
lambda t, x, u, params: u*u, inputs=1, outputs=1, dt=0)
378378
sys1 = nlios * ioslin
379379
sys2 = ios.InputOutputSystem.__rmul__(nlios, sys1)
380380

@@ -414,7 +414,7 @@ def test_feedback(self, tsys):
414414
# Linear system with constant feedback (via "nonlinear" mapping)
415415
ioslin = ios.LinearIOSystem(tsys.siso_linsys)
416416
nlios = ios.NonlinearIOSystem(None, \
417-
lambda t, x, u, params: u, inputs=1, outputs=1)
417+
lambda t, x, u, params: u, inputs=1, outputs=1, dt=0)
418418
iosys = ct.feedback(ioslin, nlios)
419419
linsys = ct.feedback(tsys.siso_linsys, 1)
420420

@@ -740,7 +740,7 @@ def test_named_signals(self, tsys):
740740
inputs = ('u[0]', 'u[1]'),
741741
outputs = ('y[0]', 'y[1]'),
742742
states = tsys.mimo_linsys1.states,
743-
name = 'sys1')
743+
name = 'sys1', dt=0)
744744
sys2 = ios.LinearIOSystem(tsys.mimo_linsys2,
745745
inputs = ('u[0]', 'u[1]'),
746746
outputs = ('y[0]', 'y[1]'),
@@ -1015,7 +1015,7 @@ def test_duplicates(self, tsys):
10151015
nlios = ios.NonlinearIOSystem(lambda t, x, u, params: x,
10161016
lambda t, x, u, params: u * u,
10171017
inputs=1, outputs=1, states=1,
1018-
name="sys")
1018+
name="sys", dt=0)
10191019

10201020
# Duplicate objects
10211021
with pytest.warns(UserWarning, match="Duplicate object"):
@@ -1024,7 +1024,7 @@ def test_duplicates(self, tsys):
10241024
# Nonduplicate objects
10251025
nlios1 = nlios.copy()
10261026
nlios2 = nlios.copy()
1027-
with pytest.warns(UserWarning, match="copy of sys") as record:
1027+
with pytest.warns(UserWarning, match="Duplicate name"):
10281028
ios_series = nlios1 * nlios2
10291029
assert "copy of sys_1.x[0]" in ios_series.state_index.keys()
10301030
assert "copy of sys.x[0]" in ios_series.state_index.keys()
@@ -1033,10 +1033,10 @@ def test_duplicates(self, tsys):
10331033
iosys_siso = ct.LinearIOSystem(tsys.siso_linsys)
10341034
nlios1 = ios.NonlinearIOSystem(None,
10351035
lambda t, x, u, params: u * u,
1036-
inputs=1, outputs=1, name="sys")
1036+
inputs=1, outputs=1, name="sys", dt=0)
10371037
nlios2 = ios.NonlinearIOSystem(None,
10381038
lambda t, x, u, params: u * u,
1039-
inputs=1, outputs=1, name="sys")
1039+
inputs=1, outputs=1, name="sys", dt=0)
10401040

10411041
with pytest.warns(UserWarning, match="Duplicate name"):
10421042
ct.InterconnectedSystem((nlios1, iosys_siso, nlios2),
@@ -1045,10 +1045,10 @@ def test_duplicates(self, tsys):
10451045
# Same system, different names => everything should be OK
10461046
nlios1 = ios.NonlinearIOSystem(None,
10471047
lambda t, x, u, params: u * u,
1048-
inputs=1, outputs=1, name="nlios1")
1048+
inputs=1, outputs=1, name="nlios1", dt=0)
10491049
nlios2 = ios.NonlinearIOSystem(None,
10501050
lambda t, x, u, params: u * u,
1051-
inputs=1, outputs=1, name="nlios2")
1051+
inputs=1, outputs=1, name="nlios2", dt=0)
10521052
with pytest.warns(None) as record:
10531053
ct.InterconnectedSystem((nlios1, iosys_siso, nlios2),
10541054
inputs=0, outputs=0, states=0)

control/tests/lti_test.py

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
from control import c2d, tf, tf2ss, NonlinearIOSystem
7-
from control.lti import (LTI, common_timebase, damp, dcgain, isctime, isdtime,
7+
from control.lti import (LTI, damp, dcgain, isctime, isdtime,
88
issiso, pole, timebaseEqual, zero)
99
from control.tests.conftest import slycotonly
1010

@@ -72,84 +72,3 @@ def test_dcgain(self):
7272
sys = tf(84, [1, 2])
7373
np.testing.assert_equal(sys.dcgain(), 42)
7474
np.testing.assert_equal(dcgain(sys), 42)
75-
76-
@pytest.mark.parametrize("dt1, dt2, expected",
77-
[(None, None, True),
78-
(None, 0, True),
79-
(None, 1, True),
80-
pytest.param(None, True, True,
81-
marks=pytest.mark.xfail(
82-
reason="returns false")),
83-
(0, 0, True),
84-
(0, 1, False),
85-
(0, True, False),
86-
(1, 1, True),
87-
(1, 2, False),
88-
(1, True, False),
89-
(True, True, True)])
90-
def test_timebaseEqual_deprecated(self, dt1, dt2, expected):
91-
"""Test that timbaseEqual throws a warning and returns as documented"""
92-
sys1 = tf([1], [1, 2, 3], dt1)
93-
sys2 = tf([1], [1, 4, 5], dt2)
94-
95-
print(sys1.dt)
96-
print(sys2.dt)
97-
98-
with pytest.deprecated_call():
99-
assert timebaseEqual(sys1, sys2) is expected
100-
# Make sure behaviour is symmetric
101-
with pytest.deprecated_call():
102-
assert timebaseEqual(sys2, sys1) is expected
103-
104-
@pytest.mark.parametrize("dt1, dt2, expected",
105-
[(None, None, None),
106-
(None, 0, 0),
107-
(None, 1, 1),
108-
(None, True, True),
109-
(True, True, True),
110-
(True, 1, 1),
111-
(1, 1, 1),
112-
(0, 0, 0),
113-
])
114-
@pytest.mark.parametrize("sys1", [True, False])
115-
@pytest.mark.parametrize("sys2", [True, False])
116-
def test_common_timebase(self, dt1, dt2, expected, sys1, sys2):
117-
"""Test that common_timbase adheres to :ref:`conventions-ref`"""
118-
i1 = tf([1], [1, 2, 3], dt1) if sys1 else dt1
119-
i2 = tf([1], [1, 4, 5], dt2) if sys2 else dt2
120-
assert common_timebase(i1, i2) == expected
121-
# Make sure behaviour is symmetric
122-
assert common_timebase(i2, i1) == expected
123-
124-
@pytest.mark.parametrize("i1, i2",
125-
[(True, 0),
126-
(0, 1),
127-
(1, 2)])
128-
def test_common_timebase_errors(self, i1, i2):
129-
"""Test that common_timbase throws errors on invalid combinations"""
130-
with pytest.raises(ValueError):
131-
common_timebase(i1, i2)
132-
# Make sure behaviour is symmetric
133-
with pytest.raises(ValueError):
134-
common_timebase(i2, i1)
135-
136-
@pytest.mark.parametrize("dt, ref, strictref",
137-
[(None, True, False),
138-
(0, False, False),
139-
(1, True, True),
140-
(True, True, True)])
141-
@pytest.mark.parametrize("objfun, arg",
142-
[(LTI, ()),
143-
(NonlinearIOSystem, (lambda x: x, ))])
144-
def test_isdtime(self, objfun, arg, dt, ref, strictref):
145-
"""Test isdtime and isctime functions to follow convention"""
146-
obj = objfun(*arg, dt=dt)
147-
148-
assert isdtime(obj) == ref
149-
assert isdtime(obj, strict=True) == strictref
150-
151-
if dt is not None:
152-
ref = not ref
153-
strictref = not strictref
154-
assert isctime(obj) == ref
155-
assert isctime(obj, strict=True) == strictref

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy