forked from Fatima-EzzahraFettah/2022-assignment-numpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_numpy_questions.py
39 lines (26 loc) · 874 Bytes
/
test_numpy_questions.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
# ##################################################
# YOU SHOULD NOT TOUCH THIS FILE !
# ##################################################
import math as m
import numpy as np
import pytest
from numpy_questions import wallis_product, max_index
def test_max_index():
X = np.array([[0, 1], [2, 0]])
assert max_index(X) == (1, 0)
X = np.random.randn(100, 100)
i, j = max_index(X)
assert np.all(X[i, j] >= X)
with pytest.raises(ValueError):
max_index(None)
with pytest.raises(ValueError):
max_index([[0, 1], [2, 0]])
with pytest.raises(ValueError):
max_index(np.array([0, 1]))
def test_wallis_product():
pi_approx = wallis_product(0)
assert pi_approx == 2.
pi_approx = wallis_product(1)
assert pi_approx == 8 / 3
pi_approx = wallis_product(100000)
assert abs(pi_approx - m.pi) < 1e-4