forked from FookieMonster/numpy-unittest-100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_array_broadcast.py
28 lines (22 loc) · 1.01 KB
/
test_array_broadcast.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
import unittest
import numpy as np
from numpy.testing import assert_array_equal
class TestArrayBroadcast(unittest.TestCase):
def test_plus(self):
vector = np.arange(6).reshape(2, 3)
assert_array_equal(vector, np.array([[0, 1, 2], [3, 4, 5]]))
assert_array_equal(vector + 1, np.array([[1, 2, 3], [4, 5, 6]]))
def test_minus(self):
vector = np.arange(6).reshape(2, 3)
assert_array_equal(vector, np.array([[0, 1, 2], [3, 4, 5]]))
assert_array_equal(vector - 1, np.array([[-1, 0, 1], [2, 3, 4]]))
def test_multi(self):
vector = np.arange(6).reshape(2, 3)
assert_array_equal(vector, np.array([[0, 1, 2], [3, 4, 5]]))
assert_array_equal(vector * 2, np.array([[0, 2, 4], [6, 8, 10]]))
def test_square(self):
vector = np.arange(6).reshape(2, 3)
assert_array_equal(vector, np.array([[0, 1, 2], [3, 4, 5]]))
assert_array_equal(vector ** 2, np.array([[0, 1, 4], [9, 16, 25]]))
if __name__ == '__main__':
unittest.main()