Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_invalid_runtime_str():
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='1')
assert exc 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_runtime_negative():
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=-1)
assert exc in str(excinfo.value)
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_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,
])
def test_invalid_step_size_str():
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, 'a')
assert exc in str(excinfo.value)
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_invalid_step_size_negative():
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, -1)
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)