@@ -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+
825859class 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+
0 commit comments