Skip to content

Commit

Permalink
Refactor all pytest of analysis.py routines
Browse files Browse the repository at this point in the history
  • Loading branch information
KybernetikJo committed Sep 9, 2023
1 parent 63caadf commit a8c3e63
Show file tree
Hide file tree
Showing 19 changed files with 395 additions and 148 deletions.
19 changes: 17 additions & 2 deletions slycot/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
set(PYSOURCE

__init__.py
test_ab01.py
test_ab01nd.py
test_ab04md.py
test_ab05md.py
test_ab05nd.py
test_ab07nd.py
test_ab08n.py
test_ab08nd.py
test_ab08nz.py
test_ab09ad.py
test_ab09ax.py
test_ab09bd.py
test_ab09md.py
test_ab09nd.py
test_ab13bd.py
test_ab13dd.py
test_ab13ed.py
test_ab13fd.py
test_ab13md.py
test_ag08bd.py
test_analysis.py
test_examples.py
test_exceptions.py
test_mb.py
test_mc.py
test_sb.py
test_analysis.py
test_transform.py
test_sg02ad.py
test_sg03ad.py
Expand Down
65 changes: 0 additions & 65 deletions slycot/tests/test_ab01.py

This file was deleted.

67 changes: 67 additions & 0 deletions slycot/tests/test_ab01nd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Test ab01 wrappers
@author: bnavigator
"""

from numpy import array
from numpy.testing import assert_allclose, assert_equal
from scipy.linalg.lapack import dorgqr

from slycot.analysis import ab01nd


class Test_ab01nd:

def test_ab01nd(self):
"""SLICOT doc example
http://slicot.org/objects/software/shared/doc/AB01ND.html"""

# Example program data
n = 3
m = 2
tol = 0.0

A = array([[-1., 0., 0.],
[-2., -2., -2.],
[-1., 0., -3.]])
B = array([[1., 0.],
[0, 2.],
[0., 1.]])

for jobz in ['N', 'I', 'F']:
Ac, Bc, ncont, indcon, nblk, Z, tau = ab01nd(n, m, A, B,
jobz=jobz, tol=tol)

# The transformed state dynamics matrix of a controllable realization
assert_allclose(Ac[:ncont, :ncont], array([[-3.0000, 2.2361],
[ 0.0000, -1.0000]]),
atol=0.0001)

# and the dimensions of its diagonal blocks are
assert_equal(nblk[:indcon], array([2]))

# The transformed input/state matrix B of a controllable realization
assert_allclose(Bc[:ncont, :],array([[ 0.0000, -2.2361],
[ 1.0000, 0.0000]]),
atol=0.0001)

# The controllability index of the transformed system representation
assert indcon == 1

if jobz == 'N':
assert Z is None
continue
elif jobz == 'I':
Z_ = Z
elif jobz == 'F':
Z_, _, info = dorgqr(Z, tau)
assert info == 0

# The similarity transformation matrix Z
assert_allclose(Z_, array([[ 0.0000, 1.0000, 0.0000],
[-0.8944, 0.0000, -0.4472],
[-0.4472, 0.0000, 0.8944]]),
atol=0.0001)

13 changes: 13 additions & 0 deletions slycot/tests/test_ab05md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy import linalg, signal

from slycot import analysis


class Test_ab05md:

@pytest.mark.skip("not implemented yet, TODO")
def test_ab05md():
pass
15 changes: 15 additions & 0 deletions slycot/tests/test_ab05nd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from slycot import analysis
from slycot.exceptions import SlycotArithmeticError

from .test_exceptions import assert_docstring_parse


class Test_ab05nd:

@pytest.mark.parametrize(
'fun, exception_class, erange, checkvars',
((analysis.ab05nd, SlycotArithmeticError, 1, {'p1': 1}),))
def test_ab_docparse(self, fun, exception_class, erange, checkvars):
assert_docstring_parse(fun.__doc__, exception_class, erange, checkvars)
13 changes: 13 additions & 0 deletions slycot/tests/test_ab07nd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy import linalg, signal

from slycot import analysis


class Test_ab07nd:

@pytest.mark.skip("not implemented yet, TODO")
def test_ab07nd():
pass
13 changes: 13 additions & 0 deletions slycot/tests/test_ab08nd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy import linalg, signal

from slycot import analysis


class Test_ab08nd:

@pytest.mark.skip("not implemented yet, TODO")
def test_ab08nd():
pass
13 changes: 13 additions & 0 deletions slycot/tests/test_ab08nz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy import linalg, signal

from slycot import analysis


class Test_ab08nz:

@pytest.mark.skip("not implemented yet, TODO")
def test_ab08nz():
pass
21 changes: 21 additions & 0 deletions slycot/tests/test_ab09ad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy import linalg, signal

from slycot import analysis
from slycot.exceptions import SlycotArithmeticError, SlycotResultWarning

from .test_exceptions import assert_docstring_parse


class Test_ab09ad:

@pytest.mark.parametrize(
'fun, exception_class, erange, checkvars',
((analysis.ab09ad, SlycotArithmeticError, 3, {'dico': 'C'}),
(analysis.ab09ad, SlycotArithmeticError, (2,), {'dico': 'D'}),
(analysis.ab09ad, SlycotResultWarning, ((1, 0), ), {'nr': 3,
'Nr': 2}),))
def test_ab09ad_docparse(self, fun, exception_class, erange, checkvars):
assert_docstring_parse(fun.__doc__, exception_class, erange, checkvars)
19 changes: 19 additions & 0 deletions slycot/tests/test_ab09ax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy import linalg, signal

from slycot import analysis
from slycot.exceptions import SlycotArithmeticError, SlycotResultWarning

from .test_exceptions import assert_docstring_parse


class Test_ab09ax:

@pytest.mark.parametrize(
'fun, exception_class, erange, checkvars',
((analysis.ab09ax, SlycotArithmeticError, 2, {'dico': 'C'}),
(analysis.ab09ax, SlycotResultWarning, ((1, 0), ), {'nr': 3, 'Nr': 2}),))
def test_ab09ax_docparse(self, fun, exception_class, erange, checkvars):
assert_docstring_parse(fun.__doc__, exception_class, erange, checkvars)
13 changes: 13 additions & 0 deletions slycot/tests/test_ab09bd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy import linalg, signal

from slycot import analysis


class Test_ab09bd:

@pytest.mark.skip("not implemented yet, TODO")
def test_ab09bd():
pass
22 changes: 22 additions & 0 deletions slycot/tests/test_ab09md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy import linalg, signal


from slycot import analysis
from slycot.exceptions import SlycotArithmeticError, SlycotResultWarning

from .test_exceptions import assert_docstring_parse


class Test_ab09md:

@pytest.mark.parametrize(
'fun, exception_class, erange, checkvars',
((analysis.ab09md, SlycotArithmeticError, 3, {'alpha': -0.1}),
(analysis.ab09md, SlycotResultWarning, ((1, 0), (2, 0)), {'nr': 3,
'Nr': 2,
'alpha': -0.1}),))
def test_ab09md_docparse(self, fun, exception_class, erange, checkvars):
assert_docstring_parse(fun.__doc__, exception_class, erange, checkvars)
21 changes: 21 additions & 0 deletions slycot/tests/test_ab09nd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy import linalg, signal

from slycot import analysis
from slycot.exceptions import SlycotArithmeticError, SlycotResultWarning

from .test_exceptions import assert_docstring_parse


class Test_ab09nd:

@pytest.mark.parametrize(
'fun, exception_class, erange, checkvars',
((analysis.ab09nd, SlycotArithmeticError, 3, {'alpha': -0.1}),
(analysis.ab09nd, SlycotResultWarning, ((1, 0), (2, 0)), {'nr': 3,
'Nr': 2,
'alpha': -0.1}),))
def test_ab09nd_docparse(self, fun, exception_class, erange, checkvars):
assert_docstring_parse(fun.__doc__, exception_class, erange, checkvars)
11 changes: 11 additions & 0 deletions slycot/tests/test_ab13bd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
# ab08n* tests

import numpy as np
import pytest
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy import linalg, signal

from slycot import analysis
from slycot.exceptions import SlycotArithmeticError, SlycotResultWarning

from .test_exceptions import assert_docstring_parse


class Test_ab13bd:
Expand All @@ -19,6 +23,13 @@ class Test_ab13bd:

Ad, Bd, Cd, Dd, dt = signal.cont2discrete((A, B, C, D), 0.1, method='zoh')

@pytest.mark.parametrize(
'fun, exception_class, erange, checkvars',
((analysis.ab13bd, SlycotArithmeticError, 6, {'dico': 'C'}),
(analysis.ab13bd, SlycotResultWarning, ((1, 0),), {}),))
def test_ab13bd_docparse(self, fun, exception_class, erange, checkvars):
assert_docstring_parse(fun.__doc__, exception_class, erange, checkvars)

def test_no_change_args_ccase(self):
""" ab13md must not change its arguments. continuous system case.
"""
Expand Down
Loading

0 comments on commit a8c3e63

Please sign in to comment.