Skip to content

Commit bb16be0

Browse files
committed
Parameterize unit tests. Catch edge case of A=0.
1 parent d6916c6 commit bb16be0

2 files changed

Lines changed: 25 additions & 35 deletions

File tree

control/passivity.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def ispassive(sys):
4444
[n, m] = D.shape
4545
D = D + np.nextafter(0, 1)*np.eye(n, m)
4646

47+
[n, _] = A.shape
48+
A = A - np.nextafter(0, 1)*np.eye(n)
49+
4750
def make_LMI_matrix(P):
4851
V = np.vstack((
4952
np.hstack((A.T @ P + P@A, P@B)),
@@ -75,7 +78,7 @@ def make_LMI_matrix(P):
7578
# crunch feasibility solution
7679
cvx.solvers.options['show_progress'] = False
7780
sol = cvx.solvers.sdp(c,
78-
Gs=[cvx.matrix(coefficents)],
79-
hs=[cvx.matrix(constants)])
81+
Gs=[cvx.matrix(coefficents)],
82+
hs=[cvx.matrix(constants)])
8083

8184
return (sol["x"] is not None)

control/tests/passivity_test.py

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Author: Mark Yeatman
33
Date: May 30, 2022
44
'''
5-
5+
import pytest
66
import numpy
77
from control import ss, passivity
88
from control.tests.conftest import cvxoptonly
@@ -25,39 +25,26 @@ def test_ispassive():
2525

2626
assert(not passivity.ispassive(sys))
2727

28-
28+
A_d = numpy.array([[-2, 0], [0, 0]])
29+
A = numpy.array([[-3, 0], [0, -2]])
30+
B = numpy.array([[0], [1]])
31+
C = numpy.array([[-1, 2]])
32+
D = numpy.array([[1.5]])
2933
@cvxoptonly
30-
def test_ispassive_edge_cases():
31-
A = numpy.array([[0, 1], [-2, -2]])
32-
B = numpy.array([[0], [1]])
33-
C = numpy.array([[-1, 2]])
34-
D = numpy.array([[1.5]])
35-
36-
D *= 0
34+
@pytest.mark.parametrize(
35+
"test_input,expected",
36+
[((A,B,C,D*0.0), True),
37+
((A_d,B,C,D), True),
38+
((A*1e12,B,C,D*0), True),
39+
((A,B*0,C*0,D), True),
40+
((A*0,B,C,D), True),
41+
((A*0,B*0,C*0,D*0), True)])
42+
def test_ispassive_edge_cases(test_input, expected):
3743

3844
# strictly proper
45+
A = test_input[0]
46+
B = test_input[1]
47+
C = test_input[2]
48+
D = test_input[3]
3949
sys = ss(A, B, C, D)
40-
assert(passivity.ispassive(sys))
41-
42-
# ill conditioned
43-
A = A*1e12
44-
sys = ss(A, B, C, D)
45-
assert(passivity.ispassive(sys))
46-
47-
# different combinations of zero A,B,C,D are 0
48-
B *= 0
49-
C *= 0
50-
assert(passivity.ispassive(sys))
51-
52-
A *= 0
53-
B = numpy.array([[0], [1]])
54-
C = numpy.array([[-1, 2]])
55-
D = numpy.array([[1.5]])
56-
assert(passivity.ispassive(sys))
57-
58-
B *= 0
59-
C *= 0
60-
assert(passivity.ispassive(sys))
61-
62-
A *= 0
63-
assert(passivity.ispassive(sys))
50+
assert(passivity.ispassive(sys)==expected)

0 commit comments

Comments
 (0)