Exemplo n.º 1
0
 def test_round(self):
     a = m.Matrix([-0.093, 0.131, 0.323], [-0.092, 0.242, 0.211],
                  [0.272, -0.173, -0.192]).round(2)
     self.assertEqual(
         a.round(2),
         m.Matrix([-0.09, 0.13, 0.32], [-0.09, 0.24, 0.21],
                  [0.27, -0.17, -0.19]))
Exemplo n.º 2
0
 def test_inversed(self):
     a = m.Matrix([1, 3, 5], [-4, 7, 1], [5, -2, 1])
     self.assertEqual(
         a.inversed().round(2),
         m.Matrix([-0.09, 0.13, 0.32], [-0.09, 0.24, 0.21],
                  [0.27, -0.17, -0.19]))
     self.assertEqual(a, m.Matrix([1, 3, 5], [-4, 7, 1], [5, -2, 1]))
Exemplo n.º 3
0
 def test_multiply_number(self):
     a1 = m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10])
     self.assertEqual(a1 * 2, m.Matrix([2, 4, 6], [10, 12, 14],
                                       [16, 18, 20]))
     self.assertEqual(a1, m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10]))
Exemplo n.º 4
0
 def test_get_item_1(self):
     a1 = m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10])
     self.assertEqual(a1[1], m.Vector(5, 6, 7))
Exemplo n.º 5
0
 def test_i_sub_number(self):
     a1 = m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10])
     a1 -= 2
     self.assertEqual(a1, m.Matrix([-1, 0, 1], [3, 4, 5], [6, 7, 8]))
Exemplo n.º 6
0
 def test_sub_different_dimension(self):
     a1 = m.Matrix([1, 2, 3], [5, 6, 7])
     a2 = m.Matrix([1, -2, 3], [5, 3, 7], [-8, 9, 10])
     with self.assertRaises(m.matrix.MatrixDimensionError):
         a1 - a2
Exemplo n.º 7
0
 def test_i_add_number(self):
     a1 = m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10])
     a1 += 2
     self.assertEqual(a1, m.Matrix([3, 4, 5], [7, 8, 9], [10, 11, 12]))
Exemplo n.º 8
0
 def test_same_dimension_false(self):
     a1 = m.Matrix([1, 2, 3], [5, 6, 7])
     a2 = m.Matrix([1, -2, 3], [5, 3, 7], [-8, 9, 10])
     self.assertEqual(a1.is_same_dimension(a2), False)
Exemplo n.º 9
0
 def test_get_column(self):
     a = m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10])
     self.assertEqual(a.get_column(1), m.Vector(2, 6, 9))
Exemplo n.º 10
0
 def test_minor(self):
     a = m.Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
     self.assertEqual(a.minor(1, 1), m.Matrix([1, 3], [7, 9]))
Exemplo n.º 11
0
 def test_multiply_vector_unsutable(self):
     a = m.Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
     v = m.Vector(1, 2, 3, 4)
     with self.assertRaises(m.matrix.MatrixDimensionError):
         a * v
Exemplo n.º 12
0
 def test_multiply_vector(self):
     a1 = m.Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
     a2 = m.Vector(1, 2, 3)
     self.assertEqual(a1 * a2, m.Vector(14, 32, 50))
Exemplo n.º 13
0
 def test_multiply_matrix_unsutable(self):
     a1 = m.Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
     a2 = m.Matrix([1, 2], [3, 4])
     with self.assertRaises(m.matrix.MatrixDimensionError):
         a1 * a2
Exemplo n.º 14
0
 def test_multiply_matrix_2(self):
     a1 = m.Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
     a2 = m.Matrix([1, 2], [3, 4], [5, 6])
     self.assertEqual(a1 * a2, m.Matrix([22, 28], [49, 64], [76, 100]))
     self.assertEqual(a1, m.Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9]))
Exemplo n.º 15
0
 def test_multiply_matrix_1(self):
     a1 = m.Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
     self.assertEqual(a1 * a1,
                      m.Matrix([30, 36, 42], [66, 81, 96], [102, 126, 150]))
Exemplo n.º 16
0
 def test_get_row(self):
     a = m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10])
     self.assertEqual(a.get_row(1), m.Vector(5, 6, 7))
Exemplo n.º 17
0
 def test_repr(self):
     a = m.Matrix([1, 2], [3, 4])
     self.assertEqual(repr(a), 'Matrix(Vector(1, 2),\n       Vector(3, 4))')
Exemplo n.º 18
0
 def test_minor_out_of_range(self):
     a = m.Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
     with self.assertRaises(IndexError):
         a.minor(3, 3)
Exemplo n.º 19
0
 def test_get_column_out_of_range(self):
     a = m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10])
     with self.assertRaises(IndexError):
         a.get_column(3)
Exemplo n.º 20
0
 def test_determinant_1(self):
     a = m.Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
     self.assertEqual(a.determinant(), 0)
Exemplo n.º 21
0
 def test_rows(self):
     self.assertEqual(m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10]).rows(), 3)
Exemplo n.º 22
0
 def test_determinant_2(self):
     a = m.Matrix([1, 3, 5], [-4, 7, 1], [5, -2, 1])
     self.assertEqual(a.determinant(), -99)
Exemplo n.º 23
0
 def test_i_add_matrix(self):
     a1 = m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10])
     a1 += m.Matrix([1, -2, 3], [5, 3, 7], [-8, 9, 10])
     self.assertEqual(a1, m.Matrix([2, 0, 6], [10, 9, 14], [0, 18, 20]))
Exemplo n.º 24
0
 def test_determinant_3(self):
     a = m.Matrix([5, 4, 9, -1], [-2, 5, 1, 3], [2, -3, 4, 1],
                  [8, 3, -3, 0])
     self.assertEqual(a.determinant(), 1943)
Exemplo n.º 25
0
 def test_columns(self):
     self.assertEqual(
         m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10]).columns(), 3)
Exemplo n.º 26
0
 def test_determinant_not_square(self):
     a = m.Matrix([1, 3], [-4, 7], [5, -2])
     with self.assertRaises(m.matrix.MatrixDimensionError):
         a.determinant()
Exemplo n.º 27
0
 def test_i_sub_matrix(self):
     a1 = m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10])
     a1 -= m.Matrix([1, -2, 3], [5, 3, 7], [-8, 9, 10])
     self.assertEqual(a1, m.Matrix([0, 4, 0], [0, 3, 0], [16, 0, 0]))
Exemplo n.º 28
0
 def test_inversed_zero_det(self):
     a = m.Matrix([1, 2, 3], [4, 5, 6], [7, 8, 9])
     with self.assertRaises(ZeroDivisionError):
         a.inversed()
Exemplo n.º 29
0
 def test_get_item_2(self):
     a1 = m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10])
     self.assertEqual(a1[1][2], 7)
Exemplo n.º 30
0
 def test_transposed(self):
     a1 = m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10])
     self.assertEqual(a1.transposed(),
                      m.Matrix([1, 5, 8], [2, 6, 9], [3, 7, 10]))
     self.assertEqual(a1, m.Matrix([1, 2, 3], [5, 6, 7], [8, 9, 10]))