Skip to content

Commit 2aeab18

Browse files
committed
shortened testing code as suggested by @bnavigator
1 parent 559a89f commit 2aeab18

2 files changed

Lines changed: 16 additions & 34 deletions

File tree

control/tests/mateqn_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,3 @@ def test_raise(self):
325325
cdare(A, B, Qfs, R, S, E)
326326
with pytest.raises(ValueError):
327327
cdare(A, B, Q, Rfs, S, E)
328-
with pytest.raises(ValueError):
329-
cdare(A, B, Q, R, S)

control/tests/statefbk_test.py

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -399,48 +399,32 @@ def test_DLQE(self, matarrayin):
399399
L, P, poles = dlqe(A, G, C, QN, RN)
400400
self.check_DLQE(L, P, poles, G, QN, RN)
401401

402-
def test_care(self, matarrayin):
403-
"""Test stabilizing feedback, continuous"""
402+
@pytest.mark.parametrize(
403+
"stabilizing",
404+
[True, pytest.param(False, marks=slycotonly)])
405+
def test_care(self, matarrayin, stabilizing):
406+
"""Test stabilizing and anti-stabilizing feedback, continuous"""
404407
A = matarrayin(np.diag([1, -1]))
405408
B = matarrayin(np.identity(2))
406409
Q = matarrayin(np.identity(2))
407410
R = matarrayin(np.identity(2))
408411
S = matarrayin(np.zeros((2, 2)))
409412
E = matarrayin(np.identity(2))
410-
X, L, G = care(A, B, Q, R, S, E, stabilizing=True)
411-
assert np.all(np.real(L) < 0)
413+
X, L, G = care(A, B, Q, R, S, E, stabilizing=stabilizing)
414+
sgn = {True: -1, False: 1}[stabilizing]
415+
assert np.all(sgn * np.real(L) > 0)
412416

413-
@slycotonly
414-
def test_care_antistabilizing(self, matarrayin):
415-
"""Test anti-stabilizing feedbacks, continuous"""
416-
A = matarrayin(np.diag([1, -1]))
417-
B = matarrayin(np.identity(2))
418-
Q = matarrayin(np.identity(2))
419-
R = matarrayin(np.identity(2))
420-
S = matarrayin(np.zeros((2, 2)))
421-
E = matarrayin(np.identity(2))
422-
X, L, G = care(A, B, Q, R, S, E, stabilizing=False)
423-
assert np.all(np.real(L) > 0)
424-
425-
def test_dare(self, matarrayin):
426-
"""Test stabilizing feedback, discrete"""
427-
A = matarrayin(np.diag([0.5, 2]))
428-
B = matarrayin(np.identity(2))
429-
Q = matarrayin(np.identity(2))
430-
R = matarrayin(np.identity(2))
431-
S = matarrayin(np.zeros((2, 2)))
432-
E = matarrayin(np.identity(2))
433-
X, L, G = dare(A, B, Q, R, S, E, stabilizing=True)
434-
assert np.all(np.abs(L) < 1)
435-
436-
@slycotonly
437-
def test_dare_antistabilizing(self, matarrayin):
438-
"""Test anti-stabilizing feedbacks, discrete"""
417+
@pytest.mark.parametrize(
418+
"stabilizing",
419+
[True, pytest.param(False, marks=slycotonly)])
420+
def test_dare(self, matarrayin, stabilizing):
421+
"""Test stabilizing and anti-stabilizing feedback, discrete"""
439422
A = matarrayin(np.diag([0.5, 2]))
440423
B = matarrayin(np.identity(2))
441424
Q = matarrayin(np.identity(2))
442425
R = matarrayin(np.identity(2))
443426
S = matarrayin(np.zeros((2, 2)))
444427
E = matarrayin(np.identity(2))
445-
X, L, G = dare(A, B, Q, R, S, E, stabilizing=False)
446-
assert np.all(np.abs(L) > 1)
428+
X, L, G = dare(A, B, Q, R, S, E, stabilizing=stabilizing)
429+
sgn = {True: -1, False: 1}[stabilizing]
430+
assert np.all(sgn * (np.abs(L) - 1) > 0)

0 commit comments

Comments
 (0)