Skip to content

Commit 762fbd6

Browse files
committed
FIX: development of parametrized tests for the singular_values_plot function
1 parent fe97069 commit 762fbd6

File tree

1 file changed

+79
-12
lines changed

1 file changed

+79
-12
lines changed

control/tests/freqresp_test.py

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,82 @@ def test_dcgain_consistency():
511511
np.testing.assert_almost_equal(sys_ss.dcgain(), -1)
512512

513513

514-
def test_singular_values_plot():
515-
den = [75, 1]
516-
sys = tf([[[87.8], [-86.4]],
517-
[[108.2], [-109.6]]],
518-
[[den, den],
519-
[den, den]])
520-
sigma, omega = singular_values_plot(sys, 0.0)
521-
sys_dc = np.array([[87.8, -86.4],
522-
[108.2, -109.6]])
523-
524-
u, s, v = np.linalg.svd(sys_dc)
525-
np.testing.assert_almost_equal(sigma.ravel(), s.ravel())
514+
# Testing of the singular_value_plot_function
515+
class TSys:
516+
"""Struct of test system"""
517+
def __init__(self, sys=None, call_kwargs=None):
518+
self.sys = sys
519+
self.kwargs = call_kwargs if call_kwargs else {}
520+
521+
def __repr__(self):
522+
"""Show system when debugging"""
523+
return self.sys.__repr__()
524+
525+
526+
@pytest.fixture
527+
def ss_mimo_t():
528+
A = np.diag([-1/75.0, -1/75.0])
529+
B = np.array([[87.8, -86.4],
530+
[108.2, -109.6]])/75.0
531+
C = np.eye(2)
532+
D = np.zeros((2, 2))
533+
T = TSys(ss(A, B, C, D))
534+
T.omega = 0.0
535+
T.sigma = np.array([[197.20868123, 1.39141948]])
536+
return T
537+
538+
539+
@pytest.fixture
540+
def ss_miso_t():
541+
A = np.diag([-1 / 75.0])
542+
B = np.array([[87.8, -86.4]]) / 75.0
543+
C = np.array([[1]])
544+
D = np.zeros((1, 2))
545+
T = TSys(ss(A, B, C, D))
546+
T.omega = 0.0
547+
T.sigma = np.array([[123.1819792]])
548+
return T
549+
550+
551+
@pytest.fixture
552+
def ss_simo_t():
553+
A = np.diag([-1 / 75.0])
554+
B = np.array([[1.0]]) / 75.0
555+
C = np.array([[87.8], [108.2]])
556+
D = np.zeros((2, 1))
557+
T = TSys(ss(A, B, C, D))
558+
T.omega = 0.0
559+
T.sigma = np.array([[139.34159465]])
560+
return T
561+
562+
563+
@pytest.fixture
564+
def ss_siso_t():
565+
A = np.diag([-1 / 75.0])
566+
B = np.array([[1.0]]) / 75.0
567+
C = np.array([[87.8]])
568+
D = np.zeros((1, 1))
569+
T = TSys(ss(A, B, C, D))
570+
T.omega = 0.0
571+
T.sigma = np.array([[87.8]])
572+
return T
573+
574+
575+
@pytest.fixture
576+
def tsystem(request, ss_mimo_t, ss_miso_t, ss_simo_t):
577+
578+
systems = {"ss_mimo": ss_mimo_t,
579+
"ss_miso": ss_miso_t,
580+
"ss_simo": ss_simo_t,
581+
"ss_siso": ss_simo_t
582+
}
583+
return systems[request.param]
584+
585+
586+
@pytest.mark.parametrize("tsystem", ["ss_mimo", "ss_miso", "ss_simo", "ss_siso"], indirect=["tsystem"])
587+
def test_singular_values_plot(tsystem):
588+
sys = tsystem.sys
589+
omega = tsystem.omega
590+
sigma_check = tsystem.sigma
591+
sigma, omega = singular_values_plot(sys, omega, plot=False)
592+
np.testing.assert_almost_equal(sigma, sigma_check)

0 commit comments

Comments
 (0)