1515from control .bdalg import feedback
1616
1717
18+ @pytest .mark .usefixtures ("mplcleanup" )
1819class TestRootLocus :
1920 """These are tests for the feedback function in rlocus.py."""
2021
@@ -32,7 +33,7 @@ class TestRootLocus:
3233 (True , 'dtime' )]
3334 ])
3435 def sys (self , request ):
35- """Return some simple LTI system for testing"""
36+ """Return some simple LTI systems for testing"""
3637 # avoid construction during collection time: prevent unfiltered
3738 # deprecation warning
3839 sysfn , args = request .param
@@ -45,7 +46,7 @@ def check_cl_poles(self, sys, pole_list, k_list):
4546 np .testing .assert_array_almost_equal (poles , poles_expected )
4647
4748 def testRootLocus (self , sys ):
48- """Basic root locus plot"""
49+ """Basic root locus (no plot) """
4950 klist = [- 1 , 0 , 1 ]
5051
5152 roots , k_out = root_locus (sys , klist , plot = False )
@@ -57,6 +58,33 @@ def test_without_gains(self, sys):
5758 roots , kvect = root_locus (sys , plot = False )
5859 self .check_cl_poles (sys , roots , kvect )
5960
61+ @pytest .mark .parametrize ('grid' , [None , True , False ])
62+ def test_root_locus_plot_grid (self , sys , grid ):
63+ rlist , klist = root_locus (sys , grid = grid )
64+ ax = plt .gca ()
65+ n_gridlines = sum ([int (line .get_linestyle () in [':' , 'dotted' ,
66+ '--' , 'dashed' ])
67+ for line in ax .lines ])
68+ if grid is False :
69+ assert n_gridlines == 2
70+ else :
71+ assert n_gridlines > 2
72+ # TODO check validity of grid
73+
74+ def test_root_locus_warnings (self ):
75+ sys = TransferFunction ([1000 ], [1 , 25 , 100 , 0 ])
76+ with pytest .warns (FutureWarning , match = "Plot.*deprecated" ):
77+ rlist , klist = root_locus (sys , Plot = True )
78+ with pytest .warns (FutureWarning , match = "PrintGain.*deprecated" ):
79+ rlist , klist = root_locus (sys , PrintGain = True )
80+
81+ def test_root_locus_neg_false_gain_nonproper (self ):
82+ """ Non proper TranferFunction with negative gain: Not implemented"""
83+ with pytest .raises (ValueError , match = "with equal order" ):
84+ root_locus (TransferFunction ([- 1 , 2 ], [1 , 2 ]))
85+
86+ # TODO: cover and validate negative false_gain branch in _default_gains()
87+
6088 def test_root_locus_zoom (self ):
6189 """Check the zooming functionality of the Root locus plot"""
6290 system = TransferFunction ([1000 ], [1 , 25 , 100 , 0 ])
@@ -104,4 +132,3 @@ def test_rlocus_default_wn(self):
104132 [- 1e-2 , 1 - 1e7j , 1 + 1e7j ], [0 , - 1e7j , 1e7j ], 1 ))
105133
106134 ct .root_locus (sys )
107-
0 commit comments