Few improvements on the tests for picewise constant functions
This commit is contained in:
parent
60e84c42e5
commit
4bdb23d26b
1 changed files with 12 additions and 7 deletions
|
|
@ -151,32 +151,37 @@ def test_expiration_aerosols():
|
|||
|
||||
|
||||
def test_piecewiseconstantfunction_wrongarguments():
|
||||
# number of values should be 1+number of transition times
|
||||
pytest.raises(ValueError,models.PiecewiseconstantFunction([0,1],[0,0]))
|
||||
pytest.raises(ValueError,models.PiecewiseconstantFunction([0,2,2],[0,0]))
|
||||
pytest.raises(ValueError,models.PiecewiseconstantFunction([0],[0,0]))
|
||||
# two transition times cannot be equal
|
||||
pytest.raises(ValueError,models.PiecewiseconstantFunction([0,2,2],[0,0]))
|
||||
# unsorted transition times are not allowed
|
||||
pytest.raises(ValueError,models.PiecewiseconstantFunction([2,0],[0,0]))
|
||||
|
||||
|
||||
def test_piecewiseconstantfunction():
|
||||
transitions = [0,8,16,24]
|
||||
transition_times = [0,8,16,24]
|
||||
values = [2,5,8]
|
||||
fun = models.PiecewiseconstantFunction(transitions,values)
|
||||
fun = models.PiecewiseconstantFunction(transitions_times,values)
|
||||
assert (fun.value(10) == 5) and (fun.value(20.5) == 8) and \
|
||||
(fun.value(8) == 2) and (fun.value(0) == 2) and (fun.value(24) == 8)
|
||||
|
||||
|
||||
def test_constantfunction():
|
||||
transitions = [0,24]
|
||||
transition_times = [0,24]
|
||||
values = [20]
|
||||
fun = models.PiecewiseconstantFunction(transitions,values)
|
||||
fun = models.PiecewiseconstantFunction(transition_times,values)
|
||||
for t in [0,1,8,10,16,20.1,24]:
|
||||
assert (fun.value(t) == 20)
|
||||
|
||||
|
||||
def test_piecewiseconstantfunction_vs_interval():
|
||||
transitions = [0,8,16,24]
|
||||
transition_times = [0,8,16,24]
|
||||
values = [0,1,0]
|
||||
fun = models.PiecewiseconstantFunction(transitions,values)
|
||||
fun = models.PiecewiseconstantFunction(transition_times,values)
|
||||
interval = models.SpecificInterval(present_times=(8,16))
|
||||
assert interval.transition_times() == set(transition_times)
|
||||
for t in [0,1,8,10,16,20.1,24]:
|
||||
assert fun.interval().triggered(t) == interval().triggered(t)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue