-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_dot_if.py
49 lines (39 loc) · 1.48 KB
/
test_dot_if.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
40
41
42
43
44
45
46
47
48
49
import os
import dot_if
import numpy as np
import unittest
class TestDot(unittest.TestCase):
def test_normal(self):
m1 = np.arange(0,6).reshape(2,3)
m2 = np.arange(0,6).reshape(3,2)
m = dot_if.dot(m1, m2)
self.assertEqual(m.ndim, 2)
self.assertEqual(m.shape, (2,2))
self.assertEqual(m[0][0], 10)
self.assertEqual(m[0][1], 13)
self.assertEqual(m[1][0], 28)
self.assertEqual(m[1][1], 40)
def test_empty_input(self):
m1 = np.arange(0,0).reshape(0,0)
m2 = np.arange(0,0).reshape(0,0)
m = dot_if.dot(m1, m2)
self.assertEqual(m.shape[0], 0)
self.assertEqual(m.shape[1], 0)
def test_error_input1(self):
m1 = np.arange(1,5).reshape(2,2)
m2 = np.arange(0,9).reshape(3,3)
self.assertRaises(dot_if.ParameterError, dot_if.dot, m1, m2)
def test_error_input2(self):
m1 = np.arange(0,9).reshape(3,3)
m2 = np.arange(0,5).reshape(1,5)
self.assertRaises(dot_if.ParameterError, dot_if.dot, m1, m2)
def test_error_input3(self): #这个测试用例发现一个问题
m1 = np.arange(0,9).reshape(9)
m2 = np.arange(0,5).reshape(1,5)
self.assertRaises(dot_if.ParameterError, dot_if.dot, m1, m2)
def test_error_input4(self):
m1 = [[]]
m2 = np.arange(0,5).reshape(1,5)
self.assertRaises(dot_if.ParameterError, dot_if.dot, m1, m2)
if __name__ == '__main__':
unittest.main()