-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_test.py
More file actions
72 lines (53 loc) · 2.19 KB
/
run_test.py
File metadata and controls
72 lines (53 loc) · 2.19 KB
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
65
66
67
68
69
70
71
72
# coding: utf-8
import sys
import os
import re
import unittest
import numpy as np
import numpy_exercises as exercise
A = np.array([[ 0, -5, 6, -2, -7, 4],
[-1, 1, -3, 3, 4, 5],
[ 8, 6, 8, 1, 8, -2],
[ 5, 7, 0, -6, -4, 2],
[-4, -6, -7, 0, 2, -1],
[-7, 2, 8, -5, 1, 4]])
class TestReplaceZeros(unittest.TestCase):
def setUp(self):
self.A = A
def test_replace_zeros(self):
res = np.array([[10, -5, 6, -2, -7, 4],
[-1, 1, -3, 3, 4, 5],
[ 8, 6, 8, 1, 8, -2],
[ 5, 7, 10, -6, -4, 2],
[-4, -6, -7, 10, 2, -1],
[-7, 2, 8, -5, 1, 4]])
exercise.replace_zeros(self.A, 10)
np.testing.assert_equal(A, res)
class TestCenter(unittest.TestCase):
def setUp(self):
self.A = A.copy()
def test_center(self):
res = A - np.average(A.ravel())
np.testing.assert_allclose(exercise.centered(self.A), res)
def test_A_unchanged(self):
exercise.centered(A)
np.testing.assert_equal(A, self.A)
class TestBelowDiagonal(unittest.TestCase):
def test_below_diagonal(self):
np.testing.assert_allclose(exercise.below_diagonal(A), sum(np.tril(A,-1), 0))
class TestCheckboard(unittest.TestCase):
def test_checkboard_odd(self):
np.testing.assert_equal(exercise.checkboard(5),
np.array([[ 1., 0., 1., 0., 1.],
[ 0., 1., 0., 1., 0.],
[ 1., 0., 1., 0., 1.],
[ 0., 1., 0., 1., 0.],
[ 1., 0., 1., 0., 1.]]))
def test_checkboard_even(self):
np.testing.assert_equal(exercise.checkboard(4),
np.array([[ 1., 0., 1., 0.],
[ 0., 1., 0., 1.],
[ 1., 0., 1., 0.],
[ 0., 1., 0., 1.]]))
if __name__ == '__main__':
unittest.main()