Skip to content

Commit 238482e

Browse files
committed
reenable masked timevector test, and really test if we get the tfinal
1 parent a1fd47e commit 238482e

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

control/tests/timeresp_test.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -706,20 +706,23 @@ def test_step_robustness(self):
706706
(TransferFunction(1, [1, .5, 0]), 25)]) # poles at 0.5 and 0
707707
def test_auto_generated_time_vector_tfinal(self, tfsys, tfinal):
708708
"""Confirm a TF with a pole at p simulates for tfinal seconds"""
709-
np.testing.assert_almost_equal(
710-
_ideal_tfinal_and_dt(tfsys)[0], tfinal, decimal=4)
709+
ideal_tfinal, ideal_dt = _ideal_tfinal_and_dt(tfsys)
710+
np.testing.assert_allclose(ideal_tfinal, tfinal, rtol=1e-4)
711+
T = _default_time_vector(tfsys)
712+
np.testing.assert_allclose(T[-1], tfinal, atol=0.5*ideal_dt)
711713

712714
@pytest.mark.parametrize("wn, zeta", [(10, 0), (100, 0), (100, .1)])
713-
def test_auto_generated_time_vector_dt_cont(self, wn, zeta):
715+
def test_auto_generated_time_vector_dt_cont1(self, wn, zeta):
714716
"""Confirm a TF with a natural frequency of wn rad/s gets a
715717
dt of 1/(ratio*wn)"""
716718

717719
dtref = 0.25133 / wn
718720

719721
tfsys = TransferFunction(1, [1, 2*zeta*wn, wn**2])
720-
np.testing.assert_almost_equal(_ideal_tfinal_and_dt(tfsys)[1], dtref)
722+
np.testing.assert_almost_equal(_ideal_tfinal_and_dt(tfsys)[1], dtref,
723+
decimal=5)
721724

722-
def test_auto_generated_time_vector_dt_cont(self):
725+
def test_auto_generated_time_vector_dt_cont2(self):
723726
"""A sampled tf keeps its dt"""
724727
wn = 100
725728
zeta = .1
@@ -746,29 +749,31 @@ def test_default_timevector_long(self):
746749
def test_default_timevector_functions_c(self, fun):
747750
"""Test that functions can calculate the time vector automatically"""
748751
sys = TransferFunction(1, [1, .5, 0])
752+
_tfinal, _dt = _ideal_tfinal_and_dt(sys)
749753

750754
# test impose number of time steps
751755
tout, _ = fun(sys, T_num=10)
752756
assert len(tout) == 10
753757

754758
# test impose final time
755-
tout, _ = fun(sys, 100)
756-
np.testing.assert_allclose(tout[-1], 100., atol=0.5)
759+
tout, _ = fun(sys, T=100.)
760+
np.testing.assert_allclose(tout[-1], 100., atol=0.5*_dt)
757761

758762
@pytest.mark.parametrize("fun", [step_response,
759763
impulse_response,
760764
initial_response])
761-
def test_default_timevector_functions_d(self, fun):
765+
@pytest.mark.parametrize("dt", [0.1, 0.112])
766+
def test_default_timevector_functions_d(self, fun, dt):
762767
"""Test that functions can calculate the time vector automatically"""
763-
sys = TransferFunction(1, [1, .5, 0], 0.1)
768+
sys = TransferFunction(1, [1, .5, 0], dt)
764769

765770
# test impose number of time steps is ignored with dt given
766771
tout, _ = fun(sys, T_num=15)
767772
assert len(tout) != 15
768773

769774
# test impose final time
770775
tout, _ = fun(sys, 100)
771-
np.testing.assert_allclose(tout[-1], 100., atol=0.5)
776+
np.testing.assert_allclose(tout[-1], 100., atol=0.5*dt)
772777

773778

774779
@pytest.mark.parametrize("tsystem",

0 commit comments

Comments
 (0)