-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
64 lines (43 loc) · 1.24 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pytest
import numpy as np
from my_funcs import greeting, my_stdev
def test_greeting():
name = 'Jane'
assert greeting(name) == 'Hello, Jane'
@pytest.mark.parametrize("name", ['Jane', 'John'])
def test_greeting_multiple(name):
assert greeting(name) == f'Hello, {name}'
def test_my_stdev_1():
x = np.random.normal(size=100)
assert my_stdev(x) > 0
def test_my_stdev_2():
x = np.random.normal(size=100)
assert my_stdev(x) == np.std(x, ddof=1)
def test_my_stdev_3():
x = np.random.normal(size=100)
assert my_stdev(x) > np.std(x, ddof=0)
def test_my_stdev_raises():
x = np.random.normal(size=1)
with pytest.raises(ZeroDivisionError):
my_stdev(x)
@pytest.fixture()
def setup_data():
x = np.random.normal(size=10000)
yield x
def test_my_stdev_1_v2(setup_data):
x = setup_data
assert my_stdev(x) > 0
def test_my_stdev_2_v2(setup_data):
x = setup_data
assert my_stdev(x) == np.std(x, ddof=1)
def test_my_stdev_3_v2(setup_data):
x = setup_data
assert my_stdev(x) > np.std(x, ddof=0)
def test_my_stdev_3_v2(setup_data):
x = setup_data
assert my_stdev(x) > np.std(x, ddof=0)
def test_my_stdev_approx(setup_data):
x = setup_data
delta = 0.2
assert my_stdev(x) == pytest.approx(1.0, delta)
assert 1 - delta < my_stdev(x) < 1 + delta