Exemplo n.º 1
0
    def test_invert3_stress(self):

        #NOTE: u testu nikada ne sme da se koristi rand funkcija

        import random

        dim = 100

        data = []
        data2 = []
        for row in range(dim):
            r = [random.randint(0, 100) for _ in range(dim)]
            data.append(r)
            data2.append(r[:])

        A = matrix.SquareMatrix(dim, data=data)
        B = matrix.SquareMatrix(dim, data=data2)

        print(A)

        A.invert()

        print(A)

        C = matrix.Matrix.multiplicate(A, B)

        print(C)
Exemplo n.º 2
0
    def test_invert(self):

        A = matrix.SquareMatrix(3, [[1, 2, 7], [3, 2, 5], [1, 5, 2]])
        B = matrix.SquareMatrix(3, [[1, 2, 7], [3, 2, 5], [1, 5, 2]])

        print(A)
        A.invert()

        print(A)

        C = matrix.Matrix.multiplicate(A, B)

        print(C)
Exemplo n.º 3
0
    def test_invert2(self):

        A = matrix.SquareMatrix(
            4, [[1, 2, 7, 1], [3, 2, 2, 5], [1, 11, 5, 2], [5, 21, 5, 1]])
        B = matrix.SquareMatrix(
            4, [[1, 2, 7, 1], [3, 2, 2, 5], [1, 11, 5, 2], [5, 21, 5, 1]])

        print(A)
        A.invert()

        print(A)

        C = matrix.Matrix.multiplicate(A, B)

        print(C)
Exemplo n.º 4
0
 def test_lower_zero_triangle(self):
     A = matrix.SquareMatrix(3, [[1, 2, 3], [2, 2, 2], [4, 3, 3]])
     A.make_zeros_below_diagonal()
     self.assertEqual(A.data, [[
         1,
         2,
         3,
     ], [0, -2, -4], [0, 0, 1]])
Exemplo n.º 5
0
    def test_upper_zero_triangle(self):
        A = matrix.SquareMatrix(3, [[1, 2, 3], [1, 3, 2], [4, 3, 3]])
        print(A)

        # TODO: ova funkcija, je implementirana samo na sqm
        # TODO: pomerite njenu implementaciju na matricu
        # TODO: po uradjenom poslu. brisite je iz squer matrice i moraju svi testovi
        # TODO: da prodju

        A.make_upper_zero_triangle()
        print(A)
Exemplo n.º 6
0
 def test_matrix_multiplication(self):
     A = matrix.SquareMatrix(3, [[1, 2, 3], [2, 2, 2], [3, 3, 3]])
     B = matrix.SquareMatrix(3, [[4, 4, 4], [5, 6, 7], [6, 6, 6]])
     C = matrix.SquareMatrix.multiplicate(A, B)
     self.assertEqual(C.data, [[32, 34, 36], [30, 32, 34], [45, 48, 51]])
Exemplo n.º 7
0
 def test_constructor_width_and_height(self):
     M = matrix.SquareMatrix(3)
     self.assertEqual(M.get_dimension(), 3)
     self.assertEqual(M.get_width(), 3)
     self.assertEqual(M.get_height(), 3)
Exemplo n.º 8
0
 def test_constructor_makes_identity(self):
     self.assertEqual(m.SquareMatrix(2), m.Matrix([[1,0],[0,1]]))