Skip to content

Commit

Permalink
Unittest added for ab04md.
Browse files Browse the repository at this point in the history
  • Loading branch information
KybernetikJo committed Jul 29, 2023
1 parent a60cee4 commit 5be87c7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions slycot/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(PYSOURCE

__init__.py
test_ab01.py
test_ab04md.py
test_ab08n.py
test_ag08bd.py
test_examples.py
Expand Down
71 changes: 71 additions & 0 deletions slycot/tests/test_ab04md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ===================================================
# ab08n* tests

import unittest
from slycot import analysis
import numpy as np

from scipy.linalg import eig
from numpy.testing import assert_equal, assert_allclose


class test_ab04md(unittest.TestCase):
"""Test ab04md.
Example data taken from
https://www.slicot.org/objects/software/shared/doc/AB04MD.html.
"""

Ac = np.array([[1.0, 0.5],
[0.5, 1.0]])
Bc = np.array([[0.0, -1.0],
[1.0, 0.0]])
Cc = np.array([[-1.0, 0.0],
[0.0, 1.0]])
Dc = np.array([[1.0, 0.0],
[0.0, -1.0]])

Ad = np.array([[-1.0, -4.0],
[-4.0, -1.0]])
Bd = np.array([[2.8284, 0.0],
[0.0, -2.8284]])
Cd = np.array([[0.0, 2.8284],
[-2.8284, 0.0]])
Dd = np.array([[-1.0, 0.0],
[0.0, -3.0]])

def test_ab04md_cont_disc_cont(self):
"""Test transformation from continuous - to discrete - to continuous time.
"""

n, m = self.Bc.shape
p = self.Cc.shape[0]

Ad_t, Bd_t, Cd_t, Dd_t = analysis.ab04md('C',n,m,p,self.Ac,self.Bc,self.Cc,self.Dc)

Ac_t, Bc_t, Cc_t, Dc_t = analysis.ab04md('D',n,m,p,Ad_t,Bd_t,Cd_t,Dd_t)

assert_allclose(self.Ac, Ac_t)
assert_allclose(self.Bc, Bc_t)
assert_allclose(self.Cc, Cc_t)
assert_allclose(self.Dc, Dc_t)

def test_ab04md_disc_cont_disc(self):
"""Test transformation from discrete - to continuous - to discrete time.
"""

n, m = self.Bc.shape
p = self.Cc.shape[0]

Ac_t, Bc_t, Cc_t, Dc_t = analysis.ab04md('D',n,m,p,self.Ad,self.Bd,self.Cd,self.Dd)

Ad_t, Bd_t, Cd_t, Dd_t = analysis.ab04md('C',n,m,p,Ac_t,Bc_t,Cc_t,Dc_t)

assert_allclose(self.Ad, Ad_t)
assert_allclose(self.Bd, Bd_t)
assert_allclose(self.Cd, Cd_t)
assert_allclose(self.Dd, Dd_t)


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

0 comments on commit 5be87c7

Please sign in to comment.