15
15
from control .bdalg import feedback
16
16
17
17
18
+ @pytest .mark .usefixtures ("mplcleanup" )
18
19
class TestRootLocus :
19
20
"""These are tests for the feedback function in rlocus.py."""
20
21
@@ -32,7 +33,7 @@ class TestRootLocus:
32
33
(True , 'dtime' )]
33
34
])
34
35
def sys (self , request ):
35
- """Return some simple LTI system for testing"""
36
+ """Return some simple LTI systems for testing"""
36
37
# avoid construction during collection time: prevent unfiltered
37
38
# deprecation warning
38
39
sysfn , args = request .param
@@ -45,7 +46,7 @@ def check_cl_poles(self, sys, pole_list, k_list):
45
46
np .testing .assert_array_almost_equal (poles , poles_expected )
46
47
47
48
def testRootLocus (self , sys ):
48
- """Basic root locus plot"""
49
+ """Basic root locus (no plot) """
49
50
klist = [- 1 , 0 , 1 ]
50
51
51
52
roots , k_out = root_locus (sys , klist , plot = False )
@@ -57,6 +58,33 @@ def test_without_gains(self, sys):
57
58
roots , kvect = root_locus (sys , plot = False )
58
59
self .check_cl_poles (sys , roots , kvect )
59
60
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
+
60
88
def test_root_locus_zoom (self ):
61
89
"""Check the zooming functionality of the Root locus plot"""
62
90
system = TransferFunction ([1000 ], [1 , 25 , 100 , 0 ])
@@ -104,4 +132,3 @@ def test_rlocus_default_wn(self):
104
132
[- 1e-2 , 1 - 1e7j , 1 + 1e7j ], [0 , - 1e7j , 1e7j ], 1 ))
105
133
106
134
ct .root_locus (sys )
107
-
0 commit comments