Esempio n. 1
0
def test_complex():
    # given that complex numbers are an unordered field
    # the arithmetic mean of complex numbers is meaningless
    pytest.skip('Complex numbers')
    num_list = [2 + 3j, 3 + 4j, -32 - 2j]
    obs = mean(num_list)
    exp = NotImplemented
    assert obs == exp
Esempio n. 2
0
def test_mean_wrong_type():
    with pytest.raises(TypeError):
        mean('not a list')
Esempio n. 3
0
def test_long():
    big = 100000000
    obs = mean(range(1, big))
    exp = big / 2.0
    assert obs == exp
Esempio n. 4
0
def test_empty():
    with pytest.raises(ZeroDivisionError):
        mean([])
Esempio n. 5
0
def test_double():
    # This one will fail in Python 2
    num_list = [1, 2, 3, 4]
    obs = mean(num_list)
    exp = 2.5
    assert obs == exp
Esempio n. 6
0
def test_zero():
    num_list = [0, 2, 4, 6]
    obs = mean(num_list)
    exp = 3
    assert obs == exp
Esempio n. 7
0
def test_ints(num_list_3):
    # num_list_3 = [1, 2, 3, 4, 5]
    obs = mean(num_list_3)
    exp = 3
    assert obs == exp
Esempio n. 8
0
def test_many(num_list, expected_mean):
    # assert mean(num_list) == expected_mean
    assert np.isclose(mean(num_list), expected_mean, 1e-3)