Skip to content

Commit f2af185

Browse files
committed
updated freqresp unit tests + use abs(omega) in statespace.freqresp
1 parent 55f4bb6 commit f2af185

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

control/statesp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def freqresp(self, omega):
460460
if isdtime(self, strict=True):
461461
dt = timebase(self)
462462
cmplx_freqs = exp(1.j * omega * dt)
463-
if (max(omega) * dt > math.pi):
463+
if max(abs(omega)) * dt > math.pi:
464464
warn("freqresp: frequency evaluation above Nyquist frequency")
465465
else:
466466
cmplx_freqs = omega * 1.j

control/tests/freqresp_test.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_superimpose(self):
4646
ctrl.bode_plot(ctrl.tf([5], [1, 1]))
4747

4848
# Check to make sure there are two axes and that each axes has two lines
49-
assert len(plt.gcf().axes) == 2
49+
self.assertEqual(len(plt.gcf().axes), 2)
5050
for ax in plt.gcf().axes:
5151
# Make sure there are 2 lines in each subplot
5252
assert len(ax.get_lines()) == 2
@@ -56,7 +56,7 @@ def test_superimpose(self):
5656
ctrl.bode_plot([ctrl.tf([1], [1,2,1]), ctrl.tf([5], [1, 1])])
5757

5858
# Check to make sure there are two axes and that each axes has two lines
59-
assert len(plt.gcf().axes) == 2
59+
self.assertEqual(len(plt.gcf().axes), 2)
6060
for ax in plt.gcf().axes:
6161
# Make sure there are 2 lines in each subplot
6262
assert len(ax.get_lines()) == 2
@@ -68,7 +68,7 @@ def test_superimpose(self):
6868
ctrl.bode_plot(ctrl.tf([5], [1, 1]))
6969

7070
# Check to make sure there are two axes and that each axes has one line
71-
assert len(plt.gcf().axes) == 2
71+
self.assertEqual(len(plt.gcf().axes), 2)
7272
for ax in plt.gcf().axes:
7373
# Make sure there is only 1 line in the subplot
7474
assert len(ax.get_lines()) == 1
@@ -78,7 +78,7 @@ def test_superimpose(self):
7878
if ax.get_label() == 'control-bode-magnitude':
7979
break
8080
ax.semilogx([1e-2, 1e1], 20 * np.log10([1, 1]), 'k-')
81-
assert len(ax.get_lines()) == 2
81+
self.assertEqual(len(ax.get_lines()), 2)
8282

8383
def test_doubleint(self):
8484
# 30 May 2016, RMM: added to replicate typecast bug in freqresp.py
@@ -144,9 +144,9 @@ def test_discrete(self):
144144
omega_bad = np.linspace(10e-4,1.1,10) * np.pi/sys.dt
145145
ret = sys.freqresp(omega_bad)
146146
print("len(w) =", len(w))
147-
assert len(w) == 1
148-
assert "above" in str(w[-1].message)
149-
assert "Nyquist" in str(w[-1].message)
147+
self.assertEqual(len(w), 1)
148+
self.assertIn("above", str(w[-1].message))
149+
self.assertIn("Nyquist", str(w[-1].message))
150150

151151
# Test bode plots (currently only implemented for SISO)
152152
if (sys.inputs == 1 and sys.outputs == 1):
@@ -162,12 +162,7 @@ def test_discrete(self):
162162

163163
else:
164164
# Calling bode should generate a not implemented error
165-
try:
166-
ret_ss = bode(sys)
167-
raise RuntimeError("MIMO bode seems to be implemented?")
168-
except NotImplementedError:
169-
# This is where we should end up (so do nothing)
170-
continue
165+
self.assertRaises(NotImplementedError, bode, (sys,))
171166

172167
def suite():
173168
return unittest.TestLoader().loadTestsFromTestCase(TestTimeresp)

0 commit comments

Comments
 (0)