Пример #1
0
def test_numpy():
    # Generate 10,000 uniformly distributed random numbers with numpy.
    num_list = np.random.uniform(0, 1, 10000)
    # Test that your mean is a proper numerical match to the numpy one.
    obs = mean(num_list)
    exp = np.mean(num_list)
    np.testing.assert_almost_equal(obs, exp)
Пример #2
0
def test_complex():
    # given that complex numbers are an unordered field
    # the arithmetic mean of complex numbers is meaningless
    num_list = [2 + 3j, 3 + 4j, -32 - 2j]
    obs = mean(num_list)
    exp = NotImplemented
    assert obs == exp
Пример #3
0
def test_numpy():
    # testing with numpy
    import numpy as np
    num_list = np.random.uniform(0, 10, 10000)
    obs = mean(num_list)
    exp = np.mean(num_list)
    np.testing.assert_almost_equal(obs, exp, decimal=10)
Пример #4
0
def test_uniform():
    # test the mean of 10,000 uniforms
    import numpy as np
    np.random.seed(259)
    unif_list = np.random.uniform(size=10000)
    obs = mean(unif_list)
    exp = np.mean(unif_list)
    assert np.isclose(obs, exp)
Пример #5
0
def test_ints():
    num_list = [1, 2, 3, 4, 5]
    obs = mean(num_list)
    exp = 3
    assert obs == exp
Пример #6
0
def test_mean():
    assert mean([1]) == 1
Пример #7
0
def test_rand():
    x = np.random.uniform(size=10000)
    # npt.assert_almost_equal(mean(x), np.mean(x))
    npt.assert_allclose(mean(x), np.mean(x), rtol=1e-12)
Пример #8
0
def test_long():
    big = 100000000
    obs = mean(range(1, big))
    exp = big / 2.0
    assert obs == exp
Пример #9
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
Пример #10
0
def test_zero():
    num_list = [0, 2, 4, 6]
    obs = mean(num_list)
    exp = 3
    assert obs == exp
Пример #11
0
def test_mean_random():
    data = np.random.rand(10000)
    npm = np.mean(data)
    mea = mean(data)
    assert np.isclose(npm,mea)
Пример #12
0
def test_npmean():
    np_list = np.random.uniform(size=10_000)
    obs = mean(np_list)
    exp = np.mean(np_list)
    np.testing.assert_allclose(obs, exp, rtol=1e-12)
Пример #13
0
def test_np_mean():
    uni = np.random.uniform(size=10_000)
    npt.assert_allclose(mean(uni), np.mean(uni))
Пример #14
0
def test_numpy():
    import numpy as np
    nums = np.random.uniform(0, 1, 10000)
    np.testing.assert_allclose(np.mean(nums), mean(nums), atol=1e-07)
Пример #15
0
def test_mean():
    array = np.random.uniform(0, 100, 10000)
    assert np.mean(array) == mean(array)
Пример #16
0
def test_numpy():
    "Test against numpy's mean with a reasonably large array"
    npr = np.random.uniform(size=10_000)
    npm = npr.mean()
    mym = mean(npr)
    npt.assert_allclose(mym, npm, rtol=1e-12)