Skip to content

Commit c26187f

Browse files
committed
Added unit test for rootlocus zoom functionality
1 parent 2ba8277 commit c26187f

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

control/rlocus.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ def _default_gains(num, den, xlim, ylim,zoom_xlim=None,zoom_ylim=None):
174174

175175
k_break, real_break = _break_points(num, den)
176176
kmax = _k_max(num, den, real_break, k_break)
177-
print(kmax)
178177
kvect = np.hstack((np.linspace(0, kmax, 50), np.real(k_break)))
179178
kvect.sort()
180179

control/tests/rlocus_test.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55

66
import unittest
77
import numpy as np
8-
from control.rlocus import root_locus
8+
from control.rlocus import root_locus, _RLClickDispatcher
99
from control.xferfcn import TransferFunction
1010
from control.statesp import StateSpace
1111
from control.bdalg import feedback
12+
import matplotlib.pyplot as plt
13+
from control.tests.margin_test import assert_array_almost_equal
14+
1215

1316
class TestRootLocus(unittest.TestCase):
1417
"""These are tests for the feedback function in rlocus.py."""
@@ -42,6 +45,31 @@ def test_without_gains(self):
4245
roots, kvect = root_locus(sys, Plot=False)
4346
self.check_cl_poles(sys, roots, kvect)
4447

48+
def testRootLocusZoom(self):
49+
"""Check the zooming functionality of the Root locus plot"""
50+
system = TransferFunction([1000], [1, 25, 100, 0])
51+
root_locus(system)
52+
fig = plt.gcf()
53+
ax_rlocus = fig.axes[0]
54+
55+
event = type('test', (object,), {'xdata': 0.9957380594313321, 'ydata': 1.7825491928580846, 'inaxes': ax_rlocus.axes})()
56+
ax_rlocus.set_xlim((-4.420022219849855, 0.9957380594313321))
57+
ax_rlocus.set_ylim((1.7825491928580846, 10.695295157148486))
58+
plt.get_current_fig_manager().toolbar.mode = 'zoom rect'
59+
_RLClickDispatcher(event, system, fig, ax_rlocus, '-')
60+
61+
zoom_x = ax_rlocus.lines[-2].get_data()[0][65:75]
62+
zoom_y = ax_rlocus.lines[-2].get_data()[1][65:75]
63+
zoom_y = [abs(y) for y in zoom_y]
64+
65+
zoom_x_valid = [-2.23659192, -2.23659121, -2.23659103, -2.23659086, -2.23659068, -2.23659063,
66+
-2.23659059, -2.23659055, -2.2365905, -2.23658766]
67+
zoom_y_valid = [1.78253589, 1.78254318, 1.782545, 1.78254682, 1.78254864, 1.7825491,
68+
1.78254955, 1.78255001, 1.78255046, 1.7825796]
69+
70+
assert_array_almost_equal(zoom_x,zoom_x_valid)
71+
assert_array_almost_equal(zoom_y,zoom_y_valid)
72+
4573
def test_suite():
4674
return unittest.TestLoader().loadTestsFromTestCase(TestRootLocus)
4775

0 commit comments

Comments
 (0)