Skip to content

Commit 28277f3

Browse files
committed
add unit tests and fixes to pass unit tests
1 parent 65e051f commit 28277f3

7 files changed

Lines changed: 79 additions & 8 deletions

File tree

control/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def use_legacy_defaults(version):
288288
set_defaults('control', default_dt=None)
289289

290290
# changed iosys naming conventions
291-
set_defaults('iosys', state_name_delim='.',
291+
set_defaults('namedio', state_name_delim='.',
292292
duplicate_system_name_prefix='copy of ',
293293
duplicate_system_name_suffix='',
294294
linearized_system_name_prefix='',

control/iosys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,7 @@ def linearize(sys, xeq, ueq=None, t=0, params=None, **kw):
22042204
---------------------
22052205
inputs : int, list of str or None, optional
22062206
Description of the system inputs. If not specified, the origional
2207-
system inputs are used. See :class:`InputOutputSystem` for more
2207+
system inputs are used. See :class:`NamedIOSystem` for more
22082208
information.
22092209
outputs : int, list of str or None, optional
22102210
Description of the system outputs. Same format as `inputs`.

control/namedio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def _copy_names(self, sys, name=None):
104104
in case a specific name (e.g. append 'linearized') is desired. """
105105
if name is None:
106106
self.name = sys.name
107+
else:
108+
self.name = name
107109
self.ninputs, self.input_index = \
108110
sys.ninputs, sys.input_index.copy()
109111
self.noutputs, self.output_index = \

control/tests/iosys_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def test_linearize(self, tsys, kincar):
216216
@pytest.mark.usefixtures("editsdefaults")
217217
def test_linearize_named_signals(self, kincar):
218218
# Full form of the call
219-
linearized = kincar.linearize([0, 0, 0], [0, 0], copy=True,
219+
linearized = kincar.linearize([0, 0, 0], [0, 0], copy_names=True,
220220
name='linearized')
221221
assert linearized.name == 'linearized'
222222
assert linearized.find_input('v') == 0
@@ -228,17 +228,17 @@ def test_linearize_named_signals(self, kincar):
228228
assert linearized.find_state('theta') == 2
229229

230230
# If we copy signal names w/out a system name, append '$linearized'
231-
linearized = kincar.linearize([0, 0, 0], [0, 0], copy=True)
231+
linearized = kincar.linearize([0, 0, 0], [0, 0], copy_names=True)
232232
assert linearized.name == kincar.name + '$linearized'
233233

234234
# Test legacy version as well
235235
ct.use_legacy_defaults('0.8.4')
236236
ct.config.use_numpy_matrix(False) # np.matrix deprecated
237-
linearized = kincar.linearize([0, 0, 0], [0, 0], copy=True)
237+
linearized = kincar.linearize([0, 0, 0], [0, 0], copy_names=True)
238238
assert linearized.name == kincar.name + '_linearized'
239239

240240
# If copy is False, signal names should not be copied
241-
lin_nocopy = kincar.linearize(0, 0, copy=False)
241+
lin_nocopy = kincar.linearize(0, 0, copy_names=False)
242242
assert lin_nocopy.find_input('v') is None
243243
assert lin_nocopy.find_output('x') is None
244244
assert lin_nocopy.find_state('x') is None

control/tests/kwargs_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,10 @@ def test_matplotlib_kwargs(function, nsysargs, moreargs, kwargs, mplcleanup):
198198
'NonlinearIOSystem.__init__':
199199
interconnect_test.test_interconnect_exceptions,
200200
'StateSpace.__init__': test_unrecognized_kwargs,
201+
'StateSpace.sample': test_unrecognized_kwargs,
201202
'TimeResponseData.__call__': trdata_test.test_response_copy,
202203
'TransferFunction.__init__': test_unrecognized_kwargs,
204+
'TransferFunction.sample': test_unrecognized_kwargs,
203205
}
204206

205207
#

control/tests/statesp_test.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,42 @@ def test_error_u_dynamics_mimo(self, u, sys222):
820820
sys222.dynamics(0, (1, 1), u)
821821
with pytest.raises(ValueError):
822822
sys222.output(0, (1, 1), u)
823-
824-
823+
824+
def test_sample_named_signals(self):
825+
sysc = ct.StateSpace(1.1, 1, 1, 1, inputs='u', outputs='y', states='a')
826+
827+
# Full form of the call
828+
sysd = sysc.sample(0.1, name='sampled')
829+
assert sysd.name == 'sampled'
830+
assert sysd.find_input('u') == 0
831+
assert sysd.find_output('y') == 0
832+
assert sysd.find_state('a') == 0
833+
834+
# If we copy signal names w/out a system name, append '$sampled'
835+
sysd = sysc.sample(0.1)
836+
assert sysd.name == sysc.name + '$sampled'
837+
838+
# If copy is False, signal names should not be copied
839+
sysd_nocopy = sysc.sample(0.1, copy_names=False)
840+
assert sysd_nocopy.find_input('u') is None
841+
assert sysd_nocopy.find_output('y') is None
842+
assert sysd_nocopy.find_state('a') is None
843+
844+
# if signal names are provided, they should override those of sysc
845+
sysd_newnames = sysc.sample(0.1, inputs='v', outputs='x', states='b')
846+
assert sysd_newnames.find_input('v') == 0
847+
assert sysd_newnames.find_input('u') is None
848+
assert sysd_newnames.find_output('x') == 0
849+
assert sysd_newnames.find_output('y') is None
850+
assert sysd_newnames.find_state('b') == 0
851+
assert sysd_newnames.find_state('a') is None
852+
# test just one name
853+
sysd_newnames = sysc.sample(0.1, inputs='v')
854+
assert sysd_newnames.find_input('v') == 0
855+
assert sysd_newnames.find_input('u') is None
856+
assert sysd_newnames.find_output('y') == 0
857+
assert sysd_newnames.find_output('x') is None
858+
825859
class TestRss:
826860
"""These are tests for the proper functionality of statesp.rss."""
827861

@@ -1164,3 +1198,5 @@ def test_params_warning():
11641198

11651199
with pytest.warns(UserWarning, match="params keyword ignored"):
11661200
sys.output(0, [0], [0], {'k': 5})
1201+
1202+

control/tests/xferfcn_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,37 @@ def test_repr(self, Hargs, ref):
986986
np.testing.assert_array_almost_equal(H.num[p][m], H2.num[p][m])
987987
np.testing.assert_array_almost_equal(H.den[p][m], H2.den[p][m])
988988
assert H.dt == H2.dt
989+
990+
def test_sample_named_signals(self):
991+
sysc = ct.TransferFunction(1.1, (1, 2), inputs='u', outputs='y')
992+
993+
# Full form of the call
994+
sysd = sysc.sample(0.1, name='sampled')
995+
assert sysd.name == 'sampled'
996+
assert sysd.find_input('u') == 0
997+
assert sysd.find_output('y') == 0
998+
999+
# If we copy signal names w/out a system name, append '$sampled'
1000+
sysd = sysc.sample(0.1)
1001+
assert sysd.name == sysc.name + '$sampled'
1002+
1003+
# If copy is False, signal names should not be copied
1004+
sysd_nocopy = sysc.sample(0.1, copy_names=False)
1005+
assert sysd_nocopy.find_input('u') is None
1006+
assert sysd_nocopy.find_output('y') is None
1007+
1008+
# if signal names are provided, they should override those of sysc
1009+
sysd_newnames = sysc.sample(0.1, inputs='v', outputs='x')
1010+
assert sysd_newnames.find_input('v') == 0
1011+
assert sysd_newnames.find_input('u') is None
1012+
assert sysd_newnames.find_output('x') == 0
1013+
assert sysd_newnames.find_output('y') is None
1014+
# test just one name
1015+
sysd_newnames = sysc.sample(0.1, inputs='v')
1016+
assert sysd_newnames.find_input('v') == 0
1017+
assert sysd_newnames.find_input('u') is None
1018+
assert sysd_newnames.find_output('y') == 0
1019+
assert sysd_newnames.find_output('x') is None
9891020

9901021

9911022
class TestLTIConverter:

0 commit comments

Comments
 (0)