def test_runtime_exceeded_warns(): ts = np.arange(2**18) m = 2**8 runtime = 1 warn_text = 'Max runtime exceeded. Approximate solution is given.' with pytest.warns(RuntimeWarning, match=warn_text): scrimp.scrimp_plus_plus(ts, m, runtime=runtime)
def test_scrimp_plus_plus(): ts = np.array([1, 2, 3, 4, 5, 6, 7, 8]) m = 4 step_size = 0.25 mp, mpidx = scrimp.scrimp_plus_plus(ts, m, step_size) expected_mp = np.array([ 0.4215e-07, 0.4215e-07, 0.4215e-07, 0.4215e-07, 0.4215e-07, ]) expected_mpidx = np.array([ 2, 3, 0, 0, 0, ]) np.testing.assert_almost_equal(mp, expected_mp) np.testing.assert_almost_equal(mpidx, expected_mpidx) ts = np.array([0, 0, 1, 0, 0, 0, 1, 0]) m = 4 step_size = 0.25 mp, mpidx = scrimp.scrimp_plus_plus(ts, m, step_size) expected_mpidx = np.array([ 4, 3, 0, 0, 0, ]) np.testing.assert_almost_equal(mpidx, expected_mpidx) ts = np.loadtxt(os.path.join(MODULE_PATH, '..', 'tests', 'sampledata.txt')) m = 32 step_size = 0.25 mp, mpidx = scrimp.scrimp_plus_plus(ts, m, step_size) expected_mp = np.loadtxt(os.path.join(MODULE_PATH, '..', 'tests', 'mp.txt')) np.testing.assert_almost_equal(mp, expected_mp, decimal=4)
def test_invalid_runtime_zero(): exc = 'runtime should be a valid positive integer.' with pytest.raises(ValueError) as excinfo: scrimp.scrimp_plus_plus([1, 2, 3, 4, 5], 2, runtime=0) assert exc in str(excinfo.value)
def test_invalid_step_size_greater(): exc = 'step_size should be a float between 0 and 1.' with pytest.raises(ValueError) as excinfo: scrimp.scrimp_plus_plus([1, 2, 3, 4, 5], 2, 2) assert exc in str(excinfo.value)
def test_window_size_minimum_exception(): with pytest.raises(ValueError) as excinfo: scrimp.scrimp_plus_plus([1, 2, 3, 4, 5], 2, 0.25) assert 'Window size must be at least 4' in str(excinfo.value)
def test_time_series_too_short_exception(): with pytest.raises(ValueError) as excinfo: scrimp.scrimp_plus_plus([1, 2, 3, 4, 5], 4, 0.25) assert 'Time series is too short' in str(excinfo.value)
def test_invalid_random_state_exception(): exc = 'Invalid random_state value given.' with pytest.raises(ValueError) as excinfo: scrimp.scrimp_plus_plus([1, 2, 3, 4, 5], 2, random_state='adsf') assert exc in str(excinfo.value)