8000 Simplify linfnorm testing · python-control/python-control@0b86c62 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b86c62

Browse files
committed
Simplify linfnorm testing
Only test small number of examples. Changed discrete-time under-damped test to get easily-predictable result.
1 parent b24bd12 commit 0b86c62

File tree

3 files changed

+31
-676
lines changed

3 files changed

+31
-676
lines changed

control/tests/linfnorm_mimo_testcases.py

Lines changed: 0 additions & 262 deletions
This file was deleted.

control/tests/statesp_test.py

Lines changed: 31 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
from .conftest import editsdefaults
2929

30-
from .linfnorm_mimo_testcases import continuous_time_mimo, discrete_time_mimo
3130

3231
class TestStateSpace:
3332
"""Tests for the StateSpace class."""
@@ -1102,83 +1101,50 @@ def test_latex_repr_testsize(editsdefaults):
11021101
assert gstatic._repr_latex_() is None
11031102

11041103

1105-
# these are relatively simple examples
1106-
# the underdamped gpeak and fpeak are found from
1107-
# gpeak = 1/(2*zeta*(1-zeta**2)**0.5
1108-
# fpeak = wn*(1-2*zeta**2)**0.5
1109-
@pytest.fixture(params=[
1110-
('lpf', ct.tf, ([1],[1,1]), 1, 0),
1111-
('static', ct.tf, ([1.23],[1]), 1.23, 0),
1112-
('underdamped', ct.tf, ([100],[1, 2*0.1*10, 100]), 5.02518907629606, 9.89949493661),
1113-
('hpf', ct.tf, ([1, 0], [1, 1]), 1, np.inf),
1114-
('integrator', ct.tf, ([1],[1,0]), np.inf, 0),
1115-
('undamped', ct.tf, ([1],[1, 0, 144]), np.inf, 12),
1116-
('zero', ct.ss, ([-1],[1],[0],[0]), 0, 0),
1117-
])
1118-
def continuous_time_siso(request):
1119-
name, systype, sysargs, refgpeak, reffpeak = request.param
1120-
return systype(*sysargs), refgpeak, reffpeak
1121-
1122-
# these are the continuous-time examples with some tweaks
1123-
@pytest.fixture(params=[
1124-
('lpf', ct.tf, ([1],[1,1]), 0.1, 1, 0),
1125-
('static', ct.tf, ([1.23],[1]), 0.1, 1.23, 0),
1126-
# the gain and frequency don't quite match the continuous-time case,
1127-
# I assume due to c2d imperfection
1128-
('underdamped', ct.tf, ([100],[1, 2*0.1*10, 100]), 0.01, 5.023137, 9.899412),
1129-
# The HPF fpeak is the Nyquist frequency
1130-
# Assume gpeak mismatch is again c2d mismatch
1131-
('hpf', ct.tf, ([1, 0], [1, 1]), 0.1, 1.04995845, np.pi * 10),
1132-
('integrator', ct.tf, ([1],[1,0]), 0.1, np.inf, 0),
1133-
('undamped', ct.tf, ([1],[1, 0, 144]), 0.003, np.inf, 12),
1134-
# ss call works around Scipy's "Badly conditioned filter coefficients" warning
1135-
('zero', ct.ss, ([-1],[1],[0],[0]), 0.003, 0, 0),
1136-
])
1137-
def discrete_time_siso(request):
1138-
name, systype, sysargs, dt, refgpeak, reffpeak = request.param
1139-
return ct.c2d(systype(*sysargs), dt), refgpeak, reffpeak
1140-
1141-
1142-
from .linfnorm_mimo_testcases import continuous_time_mimo, discrete_time_mimo
1143-
1144-
11451104
class TestLinfnorm:
1146-
@slycotonly
1147-
# @pytest.mark.parametrize(
1148-
# "name, sys, refgpeak, reffpeak",
1149-
# [
1150-
# ])
1151-
def test_linfnorm_siso_continuoustime(self, continuous_time_siso):
1152-
sys, refgpeak, reffpeak = continuous_time_siso
1153-
gpeak, fpeak = linfnorm(sys)
1154-
np.testing.assert_allclose(gpeak, refgpeak)
1155-
np.testing.assert_allclose(fpeak, reffpeak)
1156-
1105+
# these are simple tests; we assume ab13dd is correct
1106+
# python-control specific behaviour is:
1107+
# - checking for continuous- and discrete-time
1108+
# - scaling fpeak for discrete-time
1109+
# - handling static gains
1110+
1111+
# the underdamped gpeak and fpeak are found from
1112+
# gpeak = 1/(2*zeta*(1-zeta**2)**0.5)
1113+
# fpeak = wn*(1-2*zeta**2)**0.5
1114+
@pytest.fixture(params=[
1115+
('static', ct.tf, ([1.23],[1]), 1.23, 0),
1116+
('underdamped', ct.tf, ([100],[1, 2*0.5*10, 100]), 1.1547005, 7.0710678),
1117+
])
1118+
def ct_siso(self, request):
1119+
name, systype, sysargs, refgpeak, reffpeak = request.param
1120+
return systype(*sysargs), refgpeak, reffpeak
1121+
1122+
@pytest.fixture(params=[
1123+
('underdamped', ct.tf, ([100],[1, 2*0.5*10, 100]), 1e-4, 1.1547005, 7.0710678),
1124+
])
1125+
def dt_siso(self, request):
1126+
name, systype, sysargs, dt, refgpeak, reffpeak = request.param
1127+
return ct.c2d(systype(*sysargs), dt), refgpeak, reffpeak
11571128

11581129
@slycotonly
1159-
def test_linfnorm_siso_discretetime(self, discrete_time_siso):
1160-
sys, refgpeak, reffpeak = discrete_time_siso
1130+
def test_linfnorm_ct_siso(self, ct_siso):
1131+
sys, refgpeak, reffpeak = ct_siso
11611132
gpeak, fpeak = linfnorm(sys)
11621133
np.testing.assert_allclose(gpeak, refgpeak)
11631134
np.testing.assert_allclose(fpeak, reffpeak)
11641135

1165-
11661136
@slycotonly
1167-
def test_linfnorm_mimo_continuoustime(self, continuous_time_mimo):
1168-
sys, refgpeak, reffpeak = continuous_time_mimo
1137+
def test_linfnorm_dt_siso(self, dt_siso):
1138+
sys, refgpeak, reffpeak = dt_siso
11691139
gpeak, fpeak = linfnorm(sys)
1140+
# c2d pole-mapping has round-off
11701141
np.testing.assert_allclose(gpeak, refgpeak)
11711142
np.testing.assert_allclose(fpeak, reffpeak)
11721143

11731144
@slycotonly
1174-
def test_linfnorm_mimo_discretetime(self, discrete_time_mimo):
1175-
sys, refgpeak, reffpeak = discrete_time_mimo
1145+
def test_linfnorm_ct_mimo(self, ct_siso):
1146+
siso, refgpeak, reffpeak = ct_siso
1147+
sys = ct.append(siso, siso)
11761148
gpeak, fpeak = linfnorm(sys)
11771149
np.testing.assert_allclose(gpeak, refgpeak)
11781150
np.testing.assert_allclose(fpeak, reffpeak)
1179-
1180-
@slycotonly
1181-
def test_linfnorm_notimebase(self):
1182-
g = ct.ss(-0.1,1,1,0,dt=None)
1183-
with pytest.raises(ValueError):
1184-
linfnorm(g)

0 commit comments

Comments
 (0)
0