|
2 | 2 | # test_mc.py - test suite for polynomial and rational function manipulation |
3 | 3 | # bnavigator <[email protected]>, Aug 2019 |
4 | 4 |
|
5 | | -import unittest |
6 | | -import warnings |
| 5 | +import pytest |
| 6 | +import re |
7 | 7 |
|
8 | 8 | from slycot import mc01td |
9 | | - |
10 | | - |
11 | | -class test_mc(unittest.TestCase): |
12 | | - |
13 | | - def test_mc01td(self): |
14 | | - """ test_mc01td: doc example |
15 | | - data from http://slicot.org/objects/software/shared/doc/MC01TD.html |
16 | | - """ |
17 | | - (dp, stable, nz) = mc01td('C', 4, [2, 0, 1, -1, 1]) |
18 | | - self.assertEqual(dp, 4) |
19 | | - self.assertEqual(stable, 0) |
20 | | - self.assertEqual(nz, 2) |
21 | | - |
22 | | - def test_mc01td_D(self): |
23 | | - """ test_mc01td_D: test discrete option """ |
24 | | - (dp, stable, nz) = mc01td('D', 3, [1, 2, 3, 4]) |
25 | | - self.assertEqual(dp, 3) |
26 | | - self.assertEqual(stable, 1) |
27 | | - self.assertEqual(nz, 0) |
28 | | - (dp, stable, nz) = mc01td('D', 3, [4, 3, 2, 1]) |
29 | | - self.assertEqual(dp, 3) |
30 | | - self.assertEqual(stable, 0) |
31 | | - self.assertEqual(nz, 3) |
32 | | - |
33 | | - def test_mc01td_warnings(self): |
34 | | - """ test_mc01td_warnings: Test warnings """ |
35 | | - T = [([0, 0], "\n" |
36 | | - "Entry ``P(x)`` is the zero polynomial."), |
37 | | - ([0, 1], "\n" |
38 | | - "The polynomial ``P(x)`` is most probably unstable,\n" |
39 | | - "although it may be stable with one or more zeros\n" |
40 | | - "very close to the imaginary axis.\n" |
41 | | - "The number of unstable zeros (NZ) is not determined."), |
42 | | - ([1, 0], "\n" |
43 | | - "The degree of the polynomial ``P(x)`` has been\n" |
44 | | - "reduced to ``(DB - 1)`` because\n" |
45 | | - "``P(DB+1-j) = 0.0`` on entry\n" |
46 | | - "for ``j = 0, 1,..., k-1`` and ``P(DB+1-k) <> 0.0``.")] |
47 | | - for P, m in T: |
48 | | - with warnings.catch_warnings(record=True) as w: |
49 | | - (dp, stable, nz) = mc01td('C', len(P)-1, P) |
50 | | - self.assertEqual(str(w[0].message), m) |
51 | | - |
52 | | - |
53 | | -if __name__ == "__main__": |
54 | | - unittest.main() |
| 9 | +from slycot.exceptions import SlycotResultWarning |
| 10 | + |
| 11 | + |
| 12 | +def test_mc01td(): |
| 13 | + """ test_mc01td: doc example |
| 14 | + data from http://slicot.org/objects/software/shared/doc/MC01TD.html |
| 15 | + """ |
| 16 | + (dp, stable, nz) = mc01td('C', 4, [2, 0, 1, -1, 1]) |
| 17 | + assert dp == 4 |
| 18 | + assert stable == 0 |
| 19 | + assert nz == 2 |
| 20 | + |
| 21 | +def test_mc01td_D(): |
| 22 | + """ test_mc01td_D: test discrete option """ |
| 23 | + (dp, stable, nz) = mc01td('D', 3, [1, 2, 3, 4]) |
| 24 | + assert dp == 3 |
| 25 | + assert stable == 1 |
| 26 | + assert nz == 0 |
| 27 | + (dp, stable, nz) = mc01td('D', 3, [4, 3, 2, 1]) |
| 28 | + assert dp == 3 |
| 29 | + assert stable == 0 |
| 30 | + assert nz == 3 |
| 31 | + |
| 32 | +def test_mc01td_warnings(): |
| 33 | + """ test_mc01td_warnings: Test warnings """ |
| 34 | + T = [([0, 0], "Entry ``P(x)`` is the zero polynomial."), |
| 35 | + ([0, 1], "The polynomial ``P(x)`` is most probably unstable,\n" |
| 36 | + "although it may be stable with one or more zeros\n" |
| 37 | + "very close to the imaginary axis.\n" |
| 38 | + "The number of unstable zeros (NZ) is not determined."), |
| 39 | + ([1, 0], "The degree of the polynomial ``P(x)`` has been\n" |
| 40 | + "reduced to ``(DB - 1)`` because\n" |
| 41 | + "``P(DB+1-j) = 0.0`` on entry\n" |
| 42 | + "for ``j = 0, 1,..., k-1`` and ``P(DB+1-k) <> 0.0``.")] |
| 43 | + for P, m in T: |
| 44 | + with pytest.warns(SlycotResultWarning, match=re.escape(m)): |
| 45 | + (dp, stable, nz) = mc01td('C', len(P)-1, P) |
0 commit comments