add test cases #13
1 changed files with 16 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
from numpy.testing import assert_allclose
|
||||
|
||||
from numpy import isclose
|
||||
import pytest
|
||||
from logistic import f
|
||||
|
||||
|
||||
|
@ -18,11 +19,25 @@ def test_f_corner_cases():
|
|||
# x=0.1, r=2.2 => f(x, r)=0.198
|
||||
# x=0.2, r=3.4 => f(x, r)=0.544
|
||||
# x=0.5, r=2 => f(x, r)=0.5
|
||||
def test_f_generic_cases():
|
||||
cases = [
|
||||
(0.1, 2.2, 0.198),
|
||||
(0.2, 3.4, 0.544),
|
||||
(0.5, 2, 0.5),
|
||||
]
|
||||
for x, r, expected in cases:
|
||||
result = f(x, r)
|
||||
assert_allclose(result, expected)
|
||||
|
||||
|
||||
# Hands on 2:
|
||||
# parametrize the above test using @pytest.mark.parametrize
|
||||
|
||||
@pytest.mark.parametrize('x, r, expected', ([0.1, 2.2, 0.198],[0.2, 3.4, 0.544],[0.5, 2, 0.5]))
|
||||
def test_f_parametrize(x, r, expected):
|
||||
result = f(x, r)
|
||||
isclose(result, expected)
|
||||
|
||||
|
||||
# Hands on 3
|
||||
# Implement a function iterate_f that runs f for it iterations. Write tests for the following cases:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue