-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixTest.py
More file actions
84 lines (61 loc) · 2.96 KB
/
MatrixTest.py
File metadata and controls
84 lines (61 loc) · 2.96 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
73
74
75
76
77
78
79
80
81
82
83
84
'''
@author William Ray Johnson
9/4/17
'''
import unittest
import Matrix
class MatrixTest(unittest.TestCase):
def setUp(self):
self.matrix2x2 = Matrix.Matrix(2, 2, [7, 19, 8, 3])
self.matrix3x3 = Matrix.Matrix(3, 3, [2, 1, 1, 3, 2, 1, 2, 1, 2])
def testBuildMatrix2x2(self):
matrix = Matrix.Matrix(2, 2, [1,1,1,1])
expectedMatrixValue = [[1,1],
[1,1]]
actualMatrixValue = matrix.getMatrixValue()
self.assertEqual(actualMatrixValue, expectedMatrixValue)
def testBuildMatrix3x3(self):
matrix = Matrix.Matrix(3, 3, [1,1,1,1,1,1,1,1,1])
expectedMatrixValue = [[1,1,1],
[1,1,1],
[1,1,1]]
actualMatrixValue = matrix.getMatrixValue()
self.assertEqual(actualMatrixValue, expectedMatrixValue)
def testMultiply2x2(self):
matrixToMultiply = Matrix.Matrix(2, 1, [5, 17])
expectedMatrixValue = [[358],
[91]]
actualMatrixValue = self.matrix2x2.multiply(matrixToMultiply).getMatrixValue()
self.assertEqual(actualMatrixValue, expectedMatrixValue)
def testMultiply3x3(self):
matrixToMultiply = Matrix.Matrix(3, 1, [5, 17, 14])
expectedMatrixValue = [[41],
[63],
[55]]
actualMatrixValue = self.matrix3x3.multiply(matrixToMultiply).getMatrixValue()
self.assertEqual(actualMatrixValue, expectedMatrixValue)
def testGetSize(self):
self.assertEqual(self.matrix2x2.getSize(), "2x2")
self.assertEqual(self.matrix3x3.getSize(), "3x3")
def testEquals(self):
matrixA = Matrix.Matrix(2, 2, [1,2,3,4])
matrixB = Matrix.Matrix(2, 2, [1,2,3,4])
self.assertEqual(matrixA, matrixB)
def testCalcAdjugateMatrix2x2(self):
expectedAdjugateMatrix = Matrix.Matrix(2,2,[3,-19,-8,7])
actualAdjugateMatrix = self.matrix2x2.calcAdjugateMatrix()
self.assertEqual(actualAdjugateMatrix.getMatrixValue(), expectedAdjugateMatrix.getMatrixValue())
def testCalcAdjugateMatrix3x3(self):
expectedAdjugateMatrix = Matrix.Matrix(3,3,[3,-1,-1,-4,2,1,-1,0,1])
actualAdjugateMatrix = self.matrix3x3.calcAdjugateMatrix()
self.assertEqual(actualAdjugateMatrix.getMatrixValue(), expectedAdjugateMatrix.getMatrixValue())
def testCalcDeterminant2x2(self):
expectedDeterminant = 9**-1
actualDeterminant = Matrix.Matrix(2,2,[3,3,2,5]).calcDeterminant()
self.assertEqual(actualDeterminant, expectedDeterminant)
def testCalcDeterminant3x3(self):
expectedDeterminant = 1**-1
actualDeterminant = self.matrix3x3.calcDeterminant()
self.assertEqual(actualDeterminant, expectedDeterminant)
if __name__ == '__main__':
unittest.main()