Skip to content

Commit

Permalink
Improve unitest
Browse files Browse the repository at this point in the history
  • Loading branch information
KybernetikJo committed Aug 3, 2023
1 parent 32e468f commit 5ae584c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 0 additions & 1 deletion slycot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from .analysis import ab09ad, ab09ax, ab09bd, ab09md, ab09nd
from .analysis import ab13bd, ab13dd, ab13ed, ab13fd, ab13md


# Data analysis routines (0/7 wrapped)

# Filtering routines (0/6 wrapped)
Expand Down
21 changes: 15 additions & 6 deletions slycot/tests/test_sb10yd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import numpy as np
from scipy import signal

from numpy.testing import assert_almost_equal, assert_equal

class test_sb10yd(unittest.TestCase):

def test_sb10yd_exec(self):
"""Test execution.
"""A simple execution test.
"""

A = np.array([[0.0, 1.0], [-0.5, -0.1]])
Expand All @@ -25,10 +23,13 @@ def test_sb10yd_exec(self):
imag_H_resp = np.imag(H)

n = 2
dico = 0 # 0 for continuous time
flag = 0 # 0 for no constraints on the poles
n_id, *_ = synthesis.sb10yd(
0, 0, len(omega),
dico, flag, len(omega),
real_H_resp, imag_H_resp, omega, n, tol=0)

# Because flag = 0, we expect n == n_id
np.testing.assert_equal(n, n_id)

def test_sb10yd_allclose(self):
Expand All @@ -49,15 +50,23 @@ def test_sb10yd_allclose(self):
imag_H_resp = np.imag(H)

n = 2
dico = 0 # 0 for continuous time
flag = 0 # 0 for no constraints on the poles
n_id, A_id, B_id, C_id, D_id = synthesis.sb10yd(
0, 0, len(omega),
dico, flag, len(omega),
real_H_resp, imag_H_resp, omega, n, tol=0)

sys_tf_id = signal.ss2tf(A_id,B_id,C_id,D_id)
num_id, den_id = sys_tf_id
w_id, H_id = signal.freqs(num_id.squeeze(), den_id, worN=omega)

np.testing.assert_allclose(abs(H),abs(H_id),rtol=0.3,atol=0)
#print(np.max(abs(H)-abs(H_id)), np.max(abs(H_id)-abs(H)))
#print(np.max(abs(H_id)/abs(H)))

# Compare given and identified frequency response up to some toleration.
# absolute(a-b) <= atol + rtol*abolute(b), element-wise true
# absolute(a-b) or absolute(b-a) <= atol, for rtol=0 element-wise true
np.testing.assert_allclose(abs(H_id),abs(H),rtol=0,atol=0.1)

if __name__ == "__main__":
unittest.main()

0 comments on commit 5ae584c

Please sign in to comment.