Skip to content

Commit

Permalink
add unittests for mc01td, fix dp constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Greiner committed Aug 10, 2019
1 parent 2a3c98c commit 81d7031
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion slycot/src/math.pyf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

subroutine mc01td(dico,dp,p,stable,nz,dwork,iwarn,info) ! in :new:MC01TD.f
character :: dico
integer intent(in,out),check(dp>0) :: dp
integer intent(in,out),check(dp>=0) :: dp
double precision intent(in),check(shape(p,0)==dp+1),dimension(dp+1),depend(dp) :: p
logical intent(out) :: stable
integer intent(out) :: nz
Expand Down
46 changes: 46 additions & 0 deletions slycot/tests/test_mc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
#
# test_mc.py - test suite for polynomial and rational function manipulation
# bnavigator <code@bnavigator.de>, Aug 2019

import unittest
import warnings

from slycot import mc01td


class test_mc(unittest.TestCase):

def test_mc01td(self):
""" test_mc01td: doc example
data from http://slicot.org/objects/software/shared/doc/MC01TD.html
"""
(dp, stable, nz) = mc01td('C', 4, [2, 0, 1, -1, 1])
self.assertEqual(dp, 4)
self.assertEqual(stable, 0)
self.assertEqual(nz, 2)

def test_mc01td_D(self):
""" test_mc01td_D: test discrete option """
(dp, stable, nz) = mc01td('D', 3, [1, 2, 3, 4])
self.assertEqual(dp, 2)
self.assertEqual(stable, 1)
self.assertEqual(nz, 0)
(dp, stable, nz) = mc01td('D', 3, [4, 3, 2, 1])
self.assertEqual(dp, 3)
self.assertEqual(stable, 0)
self.assertEqual(nz, 3)

def test_mc01td_warnings(self):
""" test_mc01td_warnings: Test warnings """
T = [([0, 0], "entry P(x) is the zero polynomial."),
([0, 1], "P(x) may have zeros very close to stability boundary."),
([1, 0], "The degree of P(x) has been reduced to 0")]
for P, m in T:
with warnings.catch_warnings(record=True) as w:
(dp, stable, nz) = mc01td('C', len(P)-1, P)
self.assertEqual(w[0].message, m)


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

0 comments on commit 81d7031

Please sign in to comment.