Merge pull request #589 from bnavigator/drss-dt · python-control/python-control@8b900ca

@@ -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

@@ -855,6 +855,28 @@ def test_pole(self, states, outputs, inputs):

855855

for z in p:

856856

assert 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+858880859881

class TestDrss:

860882

"""These are tests for the proper functionality of statesp.drss."""

@@ -873,6 +895,7 @@ def test_shape(self, states, outputs, inputs):

873895

assert sys.nstates == states

874896

assert sys.ninputs == inputs

875897

assert 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):

884907

for z in p:

885908

assert 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+887921888922

class TestLTIConverter:

889923

"""Test returnScipySignalLTI method"""