|
1 | | -"""bdalg_test.py - test suite for block diagram algebra |
| 1 | +"""bdalg_test.py - test suite for block diagram algebra. |
2 | 2 |
|
3 | 3 | RMM, 30 Mar 2011 (based on TestBDAlg from v0.4a) |
4 | 4 | """ |
5 | 5 |
|
| 6 | +import control as ctrl |
6 | 7 | import numpy as np |
7 | | -from numpy import sort |
8 | 8 | import pytest |
9 | | - |
10 | | -import control as ctrl |
11 | | -from control.xferfcn import TransferFunction, _tf_close_coeff |
| 9 | +from control.bdalg import _ensure_tf, append, connect, feedback |
| 10 | +from control.lti import poles, zeros |
12 | 11 | from control.statesp import StateSpace |
13 | | -from control.bdalg import feedback, append, connect |
14 | | -from control.lti import zeros, poles |
15 | | -from control.bdalg import _ensure_tf |
| 12 | +from control.tests.conftest import assert_tf_close_coeff |
| 13 | +from control.xferfcn import TransferFunction |
| 14 | +from numpy import sort |
16 | 15 |
|
17 | 16 |
|
18 | 17 | class TestFeedback: |
19 | | - """These are tests for the feedback function in bdalg.py. Currently, some |
20 | | - of the tests are not implemented, or are not working properly. TODO: these |
21 | | - need to be fixed.""" |
| 18 | + """Tests for the feedback function in bdalg.py.""" |
22 | 19 |
|
23 | 20 | @pytest.fixture |
24 | 21 | def tsys(self): |
@@ -180,7 +177,7 @@ def testTFTF(self, tsys): |
180 | 177 | [[[1., 4., 9., 8., 5.]]]) |
181 | 178 |
|
182 | 179 | def testLists(self, tsys): |
183 | | - """Make sure that lists of various lengths work for operations""" |
| 180 | + """Make sure that lists of various lengths work for operations.""" |
184 | 181 | sys1 = ctrl.tf([1, 1], [1, 2]) |
185 | 182 | sys2 = ctrl.tf([1, 3], [1, 4]) |
186 | 183 | sys3 = ctrl.tf([1, 5], [1, 6]) |
@@ -237,7 +234,7 @@ def testLists(self, tsys): |
237 | 234 | sort(zeros(sys1 + sys2 + sys3 + sys4 + sys5))) |
238 | 235 |
|
239 | 236 | def testMimoSeries(self, tsys): |
240 | | - """regression: bdalg.series reverses order of arguments""" |
| 237 | + """regression: bdalg.series reverses order of arguments.""" |
241 | 238 | g1 = ctrl.ss([], [], [], [[1, 2], [0, 3]]) |
242 | 239 | g2 = ctrl.ss([], [], [], [[1, 0], [2, 3]]) |
243 | 240 | ref = g2 * g1 |
@@ -430,9 +427,9 @@ class TestEnsureTf: |
430 | 427 | ], |
431 | 428 | ) |
432 | 429 | def test_ensure(self, arraylike_or_tf, dt, tf): |
433 | | - """Test nominal cases""" |
| 430 | + """Test nominal cases.""" |
434 | 431 | ensured_tf = _ensure_tf(arraylike_or_tf, dt) |
435 | | - assert _tf_close_coeff(tf, ensured_tf) |
| 432 | + assert_tf_close_coeff(tf, ensured_tf) |
436 | 433 |
|
437 | 434 | @pytest.mark.parametrize( |
438 | 435 | "arraylike_or_tf, dt, exception", |
@@ -460,7 +457,7 @@ def test_ensure(self, arraylike_or_tf, dt, tf): |
460 | 457 | ], |
461 | 458 | ) |
462 | 459 | def test_error_ensure(self, arraylike_or_tf, dt, exception): |
463 | | - """Test error cases""" |
| 460 | + """Test error cases.""" |
464 | 461 | with pytest.raises(exception): |
465 | 462 | _ensure_tf(arraylike_or_tf, dt) |
466 | 463 |
|
@@ -624,7 +621,7 @@ class TestTfCombineSplit: |
624 | 621 | def test_combine_tf(self, tf_array, tf): |
625 | 622 | """Test combining transfer functions.""" |
626 | 623 | tf_combined = ctrl.combine_tf(tf_array) |
627 | | - assert _tf_close_coeff(tf_combined, tf) |
| 624 | + assert_tf_close_coeff(tf_combined, tf) |
628 | 625 |
|
629 | 626 | @pytest.mark.parametrize( |
630 | 627 | "tf_array, tf", |
@@ -712,12 +709,12 @@ def test_split_tf(self, tf_array, tf): |
712 | 709 | # Test entry-by-entry |
713 | 710 | for i in range(tf_split.shape[0]): |
714 | 711 | for j in range(tf_split.shape[1]): |
715 | | - assert _tf_close_coeff( |
| 712 | + assert_tf_close_coeff( |
716 | 713 | tf_split[i, j], |
717 | 714 | tf_array[i, j], |
718 | 715 | ) |
719 | 716 | # Test combined |
720 | | - assert _tf_close_coeff( |
| 717 | + assert_tf_close_coeff( |
721 | 718 | ctrl.combine_tf(tf_split), |
722 | 719 | ctrl.combine_tf(tf_array), |
723 | 720 | ) |
|
0 commit comments