Merge pull request #589 from bnavigator/drss-dt · python-control/python-control@8b900ca
@@ -19,7 +19,7 @@
1919from control.dtime import sample_system
2020from control.lti import evalfr
2121from control.statesp import (StateSpace, _convert_to_statespace, drss,
22-rss, ss, tf2ss, _statesp_defaults)
22+rss, ss, tf2ss, _statesp_defaults, _rss_generate)
2323from control.tests.conftest import ismatarrayout, slycotonly
2424from control.xferfcn import TransferFunction, ss2tf
2525@@ -855,6 +855,28 @@ def test_pole(self, states, outputs, inputs):
855855for z in p:
856856assert z.real < 0
857857858+@pytest.mark.parametrize('strictly_proper', [True, False])
859+def test_strictly_proper(self, strictly_proper):
860+"""Test that the strictly_proper argument returns a correct D."""
861+for i in range(100):
862+# The probability that drss(..., strictly_proper=False) returns an
863+# all zero D 100 times in a row is 0.5**100 = 7.89e-31
864+sys = rss(1, 1, 1, strictly_proper=strictly_proper)
865+if np.all(sys.D == 0.) == strictly_proper:
866+break
867+assert np.all(sys.D == 0.) == strictly_proper
868+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+858880859881class TestDrss:
860882"""These are tests for the proper functionality of statesp.drss."""
@@ -873,6 +895,7 @@ def test_shape(self, states, outputs, inputs):
873895assert sys.nstates == states
874896assert sys.ninputs == inputs
875897assert sys.noutputs == outputs
898+assert sys.dt is True
876899877900@pytest.mark.parametrize('states', range(1, maxStates))
878901@pytest.mark.parametrize('outputs', range(1, maxIO))
@@ -884,6 +907,17 @@ def test_pole(self, states, outputs, inputs):
884907for z in p:
885908assert abs(z) < 1
886909910+@pytest.mark.parametrize('strictly_proper', [True, False])
911+def test_strictly_proper(self, strictly_proper):
912+"""Test that the strictly_proper argument returns a correct D."""
913+for i in range(100):
914+# The probability that drss(..., strictly_proper=False) returns an
915+# all zero D 100 times in a row is 0.5**100 = 7.89e-31
916+sys = drss(1, 1, 1, strictly_proper=strictly_proper)
917+if np.all(sys.D == 0.) == strictly_proper:
918+break
919+assert np.all(sys.D == 0.) == strictly_proper
920+887921888922class TestLTIConverter:
889923"""Test returnScipySignalLTI method"""