8000 Add tests for nichols_grid · python-control/python-control@b813e0c · GitHub
[go: up one dir, main page]

Skip to content

Commit b813e0c

Browse files
committed
Add tests for nichols_grid
1 parent 3281a8d commit b813e0c

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

control/tests/nichols_test.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
RMM, 31 Mar 2011
44
"""
55

6+
import matplotlib.pyplot as plt
7+
68
import pytest
79

8-
from control import StateSpace, nichols_plot, nichols
10+
from control import StateSpace, nichols_plot, nichols, nichols_grid, pade, tf
911

1012

1113
@pytest.fixture()
@@ -26,3 +28,73 @@ def test_nichols(tsys, mplcleanup):
2628
def test_nichols_alias(tsys, mplcleanup):
2729
"""Test the control.nichols alias and the grid=False parameter"""
2830
nichols(tsys, grid=False)
31+
32+
33+
class TestNicholsGrid:
34+
def test_ax(self):
35+
# check grid is plotted into gca, or specified axis
36+
fig, axs = plt.subplots(2,2)
37+
plt.sca(axs[0,1])
38+
39+
cl_mag_lines = nichols_grid()[1]
40+
assert cl_mag_lines[0].axes is axs[0, 1]
41+
42+
cl_mag_lines = nichols_grid(ax=axs[1,1])[1]
43+
assert cl_mag_lines[0].axes is axs[1, 1]
44+
# nichols_grid didn't change what the "current axes" are
45+
assert plt.gca() is axs[0, 1]
46+
47+
48+
def test_cl_phase_label_control(self):
49+
# test label_cl_phases argument
50+
plt.clf()
51+
cl_mag_lines, cl_phase_lines, cl_mag_labels, cl_phase_labels \
52+
= nichols_grid()
53+
assert len(cl_phase_labels) > 0
54+
55+
plt.clf()
56+
cl_mag_lines, cl_phase_lines, cl_mag_labels, cl_phase_labels \
57+
= nichols_grid(label_cl_phases=False)
58+
assert len(cl_phase_labels) == 0
59+
60+
61+
def test_labels_clipped(self):
62+
# regression test: check that contour labels are clipped
63+
plt.clf()
64+
mcontours, ncontours, mlabels, nlabels = nichols_grid()
65+
assert all(ml.get_clip_on() for ml in mlabels)
66+
assert all(nl.get_clip_on() for nl in nlabels)
67+
68+
69+
def test_minimal_phase(self):
70+
# regression test: phase extent is minimal
71+
g = tf([1],[1,1]) * tf([1],[1/1, 2*0.1/1, 1])
72+
plt.clf()
73+
nichols(g)
74+
ax = plt.gca()
75+
assert ax.get_xlim()[1] <= 0
76+
77+
78+
def test_fixed_view(self):
79+
# respect xlim, ylim set by user
80+
g = (tf([1],[1/1, 2*0.01/1, 1])
81+
* tf([1],[1/100**2, 2*0.001/100, 1])
82+
* tf(*pade(0.01, 5)))
83+
84+
# normally a broad axis
85+
plt.clf()
86+
m, p = nichols(g)
87+
88+
assert(plt.xlim()[0] == -1440)
89+
assert(plt.ylim()[0] <= -240)
90+
91+
plt.clf()
92+
nichols(g, grid=False)
93+
94+
# zoom in
95+
plt.axis([-360,0,-40,50])
96+
97+
# nichols_grid doesn't expand limits
98+
nichols_grid()
99+
assert(plt.xlim()[0] == -360)
100+
assert(plt.ylim()[1] >= -40)

0 commit comments

Comments
 (0)
0