Skip to content

Commit e50ce23

Browse files
committed
add test to cover _rss_generate (rss and drss) errors on invalid input
1 parent 8e3a141 commit e50ce23

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

control/statesp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ def _rss_generate(states, inputs, outputs, cdtype, strictly_proper=False):
14651465
if outputs < 1 or outputs % 1:
14661466
raise ValueError("outputs must be a positive integer. outputs = %g." %
14671467
outputs)
1468-
if cdtype not in ['c', 'd']: # pragma: no cover
1468+
if cdtype not in ['c', 'd']:
14691469
raise ValueError("cdtype must be `c` or `d`")
14701470

14711471
# Make some poles for A. Preallocate a complex array.
@@ -1835,7 +1835,7 @@ def rss(states=1, outputs=1, inputs=1, strictly_proper=False):
18351835
Number of state variables
18361836
inputs : int
18371837
Number of system inputs
1838-
outputs : inte
1838+
outputs : int
18391839
Number of system outputs
18401840
strictly_proper : bool, optional
18411841
If set to 'True', returns a proper system (no direct term).

control/tests/statesp_test.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from control.dtime import sample_system
2020
from control.lti import evalfr
2121
from control.statesp import (StateSpace, _convert_to_statespace, drss,
22-
rss, ss, tf2ss, _statesp_defaults)
22+
rss, ss, tf2ss, _statesp_defaults, _rss_generate)
2323
from control.tests.conftest import ismatarrayout, slycotonly
2424
from control.xferfcn import TransferFunction, ss2tf
2525

@@ -866,6 +866,17 @@ def test_strictly_proper(self, strictly_proper):
866866
break
867867
assert np.all(sys.D == 0.) == strictly_proper
868868

869+
@pytest.mark.parametrize('par, errmatch',
870+
[((-1, 1, 1, 'c'), 'states must be'),
871+
((1, -1, 1, 'c'), 'inputs must be'),
872+
((1, 1, -1, 'c'), 'outputs must be'),
873+
((1, 1, 1, 'x'), 'cdtype must be'),
874+
])
875+
def test_rss_invalid(self, par, errmatch):
876+
"""Test invalid inputs for rss() and drss()."""
877+
with pytest.raises(ValueError, match=errmatch):
878+
_rss_generate(*par)
879+
869880

870881
class TestDrss:
871882
"""These are tests for the proper functionality of statesp.drss."""

0 commit comments

Comments
 (0)