Skip to content

Commit 44dd3e6

Browse files
committed
TST: added simple unit tests for series, parallel
1 parent 3c0fa80 commit 44dd3e6

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

control/tests/bdalg_test.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
import unittest
77
import numpy as np
8+
from numpy import sort
9+
import control as ctrl
810
from control.xferfcn import TransferFunction
911
from control.statesp import StateSpace
1012
from control.bdalg import feedback
13+
from control.lti import zero, pole
1114

1215
class TestFeedback(unittest.TestCase):
1316
"""These are tests for the feedback function in bdalg.py. Currently, some
@@ -177,6 +180,63 @@ def testTFTF(self):
177180
np.testing.assert_array_almost_equal(ans2.num, [[[1., 4., 7., 6.]]])
178181
np.testing.assert_array_almost_equal(ans2.den, [[[1., 4., 9., 8., 5.]]])
179182

183+
def testLists(self):
184+
"""Make sure that lists of various lengths work for operations"""
185+
sys1 = ctrl.tf([1, 1], [1, 2])
186+
sys2 = ctrl.tf([1, 3], [1, 4])
187+
sys3 = ctrl.tf([1, 5], [1, 6])
188+
sys4 = ctrl.tf([1, 7], [1, 8])
189+
sys5 = ctrl.tf([1, 9], [1, 0])
190+
191+
# Series
192+
sys1_2 = ctrl.series(sys1, sys2)
193+
np.testing.assert_array_almost_equal(sort(pole(sys1_2)), [-4., -2.])
194+
np.testing.assert_array_almost_equal(sort(zero(sys1_2)), [-3., -1.])
195+
196+
sys1_3 = ctrl.series(sys1, sys2, sys3);
197+
np.testing.assert_array_almost_equal(sort(pole(sys1_3)),
198+
[-6., -4., -2.])
199+
np.testing.assert_array_almost_equal(sort(zero(sys1_3)),
200+
[-5., -3., -1.])
201+
202+
sys1_4 = ctrl.series(sys1, sys2, sys3, sys4);
203+
np.testing.assert_array_almost_equal(sort(pole(sys1_4)),
204+
[-8., -6., -4., -2.])
205+
np.testing.assert_array_almost_equal(sort(zero(sys1_4)),
206+
[-7., -5., -3., -1.])
207+
208+
sys1_5 = ctrl.series(sys1, sys2, sys3, sys4, sys5);
209+
np.testing.assert_array_almost_equal(sort(pole(sys1_5)),
210+
[-8., -6., -4., -2., -0.])
211+
np.testing.assert_array_almost_equal(sort(zero(sys1_5)),
212+
[-9., -7., -5., -3., -1.])
213+
214+
# Parallel
215+
sys1_2 = ctrl.parallel(sys1, sys2)
216+
np.testing.assert_array_almost_equal(sort(pole(sys1_2)), [-4., -2.])
217+
np.testing.assert_array_almost_equal(sort(zero(sys1_2)),
218+
sort(zero(sys1 + sys2)))
219+
220+
sys1_3 = ctrl.parallel(sys1, sys2, sys3);
221+
np.testing.assert_array_almost_equal(sort(pole(sys1_3)),
222+
[-6., -4., -2.])
223+
np.testing.assert_array_almost_equal(sort(zero(sys1_3)),
224+
sort(zero(sys1 + sys2 + sys3)))
225+
226+
sys1_4 = ctrl.parallel(sys1, sys2, sys3, sys4);
227+
np.testing.assert_array_almost_equal(sort(pole(sys1_4)),
228+
[-8., -6., -4., -2.])
229+
np.testing.assert_array_almost_equal(sort(zero(sys1_4)),
230+
sort(zero(sys1 + sys2 +
231+
sys3 + sys4)))
232+
233+
234+
sys1_5 = ctrl.parallel(sys1, sys2, sys3, sys4, sys5);
235+
np.testing.assert_array_almost_equal(sort(pole(sys1_5)),
236+
[-8., -6., -4., -2., -0.])
237+
np.testing.assert_array_almost_equal(sort(zero(sys1_5)),
238+
sort(zero(sys1 + sys2 +
239+
sys3 + sys4 + sys5)))
180240
def suite():
181241
return unittest.TestLoader().loadTestsFromTestCase(TestFeedback)
182242

0 commit comments

Comments
 (0)