Skip to content

Commit ca302d6

Browse files
committed
add coverage for rlocus with dtime, grid and sisotool
1 parent c21bc69 commit ca302d6

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

control/tests/rlocus_test.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@
1818
class TestRootLocus:
1919
"""These are tests for the feedback function in rlocus.py."""
2020

21-
@pytest.fixture(params=[(TransferFunction, ([1, 2], [1, 2, 3])),
22-
(StateSpace, ([[1., 4.], [3., 2.]],
23-
[[1.], [-4.]],
24-
[[1., 0.]], [[0.]]))],
25-
ids=["tf", "ss"])
21+
@pytest.fixture(params=[pytest.param((sysclass, sargs + (dt, )),
22+
id=f"{systypename}-{dtstring}")
23+
for sysclass, systypename, sargs in [
24+
(TransferFunction, 'TF', ([1, 2],
25+
[1, 2, 3])),
26+
(StateSpace, 'SS', ([[1., 4.], [3., 2.]],
27+
[[1.], [-4.]],
28+
[[1., 0.]],
29+
[[0.]])),
30+
]
31+
for dt, dtstring in [(0, 'ctime'),
32+
(True, 'dtime')]
33+
])
2634
def sys(self, request):
2735
"""Return some simple LTI system for testing"""
2836
# avoid construction during collection time: prevent unfiltered

control/tests/sisotool_test.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@ class TestSisotool:
1717
"""These are tests for the sisotool in sisotool.py."""
1818

1919
@pytest.fixture
20-
def sys(self):
20+
def tsys(self, request):
2121
"""Return a generic SISO transfer function"""
22-
return TransferFunction([1000], [1, 25, 100, 0])
23-
24-
@pytest.fixture
25-
def sysdt(self):
26-
"""Return a generic SISO transfer function"""
27-
return TransferFunction([1000], [1, 25, 100, 0], True)
22+
dt = getattr(request, 'param', 0)
23+
return TransferFunction([1000], [1, 25, 100, 0], dt)
2824

2925
@pytest.fixture
3026
def sys222(self):
@@ -50,8 +46,8 @@ def sys221(self):
5046
D221 = [[1., -1.]]
5147
return StateSpace(A222, B222, C221, D221)
5248

53-
def test_sisotool(self, sys):
54-
sisotool(sys, Hz=False)
49+
def test_sisotool(self, tsys):
50+
sisotool(tsys, Hz=False)
5551
fig = plt.gcf()
5652
ax_mag, ax_rlocus, ax_phase, ax_step = fig.axes[:4]
5753

@@ -89,7 +85,7 @@ def test_sisotool(self, sys):
8985
event = type('test', (object,), {'xdata': 2.31206868287,
9086
'ydata': 15.5983051046,
9187
'inaxes': ax_rlocus.axes})()
92-
_RLClickDispatcher(event=event, sys=sys, fig=fig,
88+
_RLClickDispatcher(event=event, sys=tsys, fig=fig,
9389
ax_rlocus=ax_rlocus, sisotool=True, plotstr='-',
9490
bode_plot_params=bode_plot_params, tvect=None)
9591

@@ -118,37 +114,24 @@ def test_sisotool(self, sys):
118114
assert_array_almost_equal(
119115
ax_step.lines[0].get_data()[1][:10], step_response_moved, 4)
120116

121-
def test_sisotool_tvect(self, sys):
117+
@pytest.mark.parametrize('tsys', [0, True],
118+
indirect=True, ids=['ctime', 'dtime'])
119+
def test_sisotool_tvect(self, tsys):
122120
# test supply tvect
123121
tvect = np.linspace(0, 1, 10)
124-
sisotool(sys, tvect=tvect)
122+
sisotool(tsys, tvect=tvect)
125123
fig = plt.gcf()
126124
ax_rlocus, ax_step = fig.axes[1], fig.axes[3]
127125

128126
# Move the rootlocus to another point and confirm same tvect
129127
event = type('test', (object,), {'xdata': 2.31206868287,
130128
'ydata': 15.5983051046,
131129
'inaxes': ax_rlocus.axes})()
132-
_RLClickDispatcher(event=event, sys=sys, fig=fig,
130+
_RLClickDispatcher(event=event, sys=tsys, fig=fig,
133131
ax_rlocus=ax_rlocus, sisotool=True, plotstr='-',
134132
bode_plot_params=dict(), tvect=tvect)
135133
assert_array_almost_equal(tvect, ax_step.lines[0].get_data()[0])
136134

137-
def test_sisotool_tvect_dt(self, sysdt):
138-
# test supply tvect
139-
tvect = np.linspace(0, 1, 10)
140-
sisotool(sysdt, tvect=tvect)
141-
fig = plt.gcf()
142-
ax_rlocus, ax_step = fig.axes[1], fig.axes[3]
143-
144-
# Move the rootlocus to another point and confirm same tvect
145-
event = type('test', (object,), {'xdata': 2.31206868287,
146-
'ydata': 15.5983051046,
147-
'inaxes': ax_rlocus.axes})()
148-
_RLClickDispatcher(event=event, sys=sysdt, fig=fig,
149-
ax_rlocus=ax_rlocus, sisotool=True, plotstr='-',
150-
bode_plot_params=dict(), tvect=tvect)
151-
assert_array_almost_equal(tvect, ax_step.lines[0].get_data()[0])
152135

153136
def test_sisotool_mimo(self, sys222, sys221):
154137
# a 2x2 should not raise an error:

0 commit comments

Comments
 (0)