|
1 | 1 | """lti_test.py""" |
2 | 2 |
|
| 3 | +import re |
| 4 | + |
3 | 5 | import numpy as np |
4 | 6 | import pytest |
5 | | -from .conftest import editsdefaults |
6 | 7 |
|
7 | 8 | import control as ct |
8 | | -from control import c2d, tf, ss, tf2ss, NonlinearIOSystem |
9 | | -from control.lti import LTI, evalfr, damp, dcgain, zeros, poles, bandwidth |
10 | | -from control import common_timebase, isctime, isdtime, issiso |
11 | | -from control.tests.conftest import slycotonly |
| 9 | +from control import NonlinearIOSystem, c2d, common_timebase, isctime, \ |
| 10 | + isdtime, issiso, ss, tf, tf2ss |
12 | 11 | from control.exception import slycot_check |
| 12 | +from control.lti import LTI, bandwidth, damp, dcgain, evalfr, poles, zeros |
| 13 | +from control.tests.conftest import slycotonly |
| 14 | + |
| 15 | +from .conftest import editsdefaults |
| 16 | + |
13 | 17 |
|
14 | 18 | class TestLTI: |
15 | 19 | @pytest.mark.parametrize("fun, args", [ |
@@ -368,3 +372,41 @@ def test_scalar_algebra(op, fcn): |
368 | 372 |
|
369 | 373 | scaled = getattr(sys, op)(2) |
370 | 374 | np.testing.assert_almost_equal(getattr(sys(1j), op)(2), scaled(1j)) |
| 375 | + |
| 376 | + |
| 377 | +@pytest.mark.parametrize( |
| 378 | + "fcn, args, kwargs, suppress, " + |
| 379 | + "repr_expected, str_expected, latex_expected", [ |
| 380 | + (ct.ss, (-1e-12, 1, 2, 3), {}, False, |
| 381 | + r"StateSpace\([\s]*array\(\[\[-1.e-12\]\]\).*", |
| 382 | + None, # standard Numpy formatting |
| 383 | + r"10\^\{-12\}"), |
| 384 | + (ct.ss, (-1e-12, 1, 3, 3), {}, True, |
| 385 | + r"StateSpace\([\s]*array\(\[\[-0\.\]\]\).*", |
| 386 | + None, # standard Numpy formatting |
| 387 | + r"-0"), |
| 388 | + (ct.tf, ([1, 1e-12, 1], [1, 2, 1]), {}, False, |
| 389 | + r"\[1\.e\+00, 1\.e-12, 1.e\+00\]", |
| 390 | + r"s\^2 \+ 1e-12 s \+ 1", |
| 391 | + r"1 \\times 10\^\{-12\}"), |
| 392 | + (ct.tf, ([1, 1e-12, 1], [1, 2, 1]), {}, True, |
| 393 | + r"\[1\., 0., 1.\]", |
| 394 | + r"s\^2 \+ 1", |
| 395 | + r"\{s\^2 \+ 1\}"), |
| 396 | +]) |
| 397 | +@pytest.mark.usefixtures("editsdefaults") |
| 398 | +def test_printoptions( |
| 399 | + fcn, args, kwargs, suppress, |
| 400 | + repr_expected, str_expected, latex_expected): |
| 401 | + sys = fcn(*args, **kwargs) |
| 402 | + |
| 403 | + with np.printoptions(suppress=suppress): |
| 404 | + # Test loadable representation |
| 405 | + assert re.search(repr_expected, sys.iosys_repr('loadable')) is not None |
| 406 | + |
| 407 | + # Test string representation |
| 408 | + if str_expected is not None: |
| 409 | + assert re.search(str_expected, str(sys)) is not None |
| 410 | + |
| 411 | + # Test LaTeX representation |
| 412 | + assert re.search(latex_expected, sys._repr_latex_()) is not None |
0 commit comments