Skip to content

Commit a78e85c

Browse files
Test if labels are transferred to the response and we can still relabel them
1 parent 34a7a49 commit a78e85c

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

control/tests/trdata_test.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,20 @@ def test_response_copy():
196196
with pytest.raises(ValueError, match="not enough"):
197197
t, y, x = response_mimo
198198

199-
# Labels
200-
assert response_mimo.output_labels is None
201-
assert response_mimo.state_labels is None
202-
assert response_mimo.input_labels is None
199+
# Make sure labels are transferred to the response
200+
assert response_siso.output_labels == sys_siso.output_labels
201+
assert response_siso.state_labels == sys_siso.state_labels
202+
assert response_siso.input_labels == sys_siso.input_labels
203+
assert response_mimo.output_labels == sys_mimo.output_labels
204+
assert response_mimo.state_labels == sys_mimo.state_labels
205+
assert response_mimo.input_labels == sys_mimo.input_labels
206+
207+
# Check relabelling
203208
response = response_mimo(
204209
output_labels=['y1', 'y2'], input_labels='u',
205-
state_labels=["x[%d]" % i for i in range(4)])
210+
state_labels=["x%d" % i for i in range(4)])
206211
assert response.output_labels == ['y1', 'y2']
207-
assert response.state_labels == ['x[0]', 'x[1]', 'x[2]', 'x[3]']
212+
assert response.state_labels == ['x0', 'x1', 'x2', 'x3']
208213
assert response.input_labels == ['u']
209214

210215
# Unknown keyword
@@ -231,6 +236,17 @@ def test_trdata_labels():
231236
np.testing.assert_equal(
232237
response.input_labels, ["u[%d]" % i for i in range(sys.ninputs)])
233238

239+
# Make sure the selected input and output are both correctly transferred to the response
240+
for nu in range(sys.ninputs):
241+
for ny in range(sys.noutputs):
242+
step_response = ct.step_response(sys, T, input=nu, output=ny)
243+
assert step_response.input_labels == [sys.input_labels[nu]]
244+
assert step_response.output_labels == [sys.output_labels[ny]]
245+
246+
init_response = ct.initial_response(sys, T, input=nu, output=ny)
247+
assert init_response.input_labels == None
248+
assert init_response.output_labels == [sys.output_labels[ny]]
249+
234250

235251
def test_trdata_multitrace():
236252
#

0 commit comments

Comments
 (0)