コード例 #1
0
ファイル: test_math.py プロジェクト: NP-compete/AlgoPy
    def test_matrix_transpose(self):
        X = [[12,7],
            [4 ,5],
            [3 ,8]]

        matrix = matrix_operations.Matrix(X)
        self.assertEqual(matrix.transpose(), [[12, 4, 3],[7, 5, 8]])
コード例 #2
0
ファイル: test_math.py プロジェクト: NP-compete/AlgoPy
    def test_matrix_rotate(self):
        X =[[1,  2,  3,  4 ],
            [5,  6,  7,  8 ],
            [9,  10, 11, 12 ],
            [13, 14, 15, 16 ]]

        matrix = matrix_operations.Matrix(X)
        self.assertEqual(matrix.rotate(), [[5, 1, 2, 3], [9, 10, 6, 4], [13, 11, 7, 8], [14, 15, 16, 12]])
コード例 #3
0
ファイル: test_math.py プロジェクト: NP-compete/AlgoPy
    def test_matrix_multiplication(self):
        X = [[12,7,3],
            [4,5,6],
            [7,8,9]]

        Y = [[5,8,1,2],
            [6,7,3,0],
            [4,5,9,1]]

        matrix = matrix_operations.Matrix(X, Y)
        self.assertEqual(matrix.multiply(), [[114, 160, 60, 27], [74, 97, 73, 14], [119, 157, 112, 23]])
コード例 #4
0
ファイル: test_math.py プロジェクト: NP-compete/AlgoPy
    def test_matrix_subtraction(self):
        X = [[12,7,3],
            [4,5,6],
            [7,8,9]]

        Y = [[5,8,1],
            [6,7,3],
            [4,5,9]]

        matrix = matrix_operations.Matrix(X, Y)
        self.assertEqual(matrix.subtract(), [[7, -1, 2], [-2, -2, 3], [3, 3, 0]])
コード例 #5
0
ファイル: test_math.py プロジェクト: NP-compete/AlgoPy
    def test_matrix_addition(self):
        X = [[12,7,3],
            [4 ,5,6],
            [7 ,8,9]]

        Y = [[5,8,1],
            [6,7,3],
            [4,5,9]]

        matrix = matrix_operations.Matrix(X, Y)
        self.assertEqual(matrix.add(), [[17, 15, 4], [10, 12, 9], [11, 13, 18]])
コード例 #6
0
ファイル: test_math.py プロジェクト: NP-compete/AlgoPy
    def test_matrix_exceptions(self):
        X = [[12,7,3],
            [4,5,6],
            [7,8,9]]

        Y = [[5,8],
            [6,7],
            [4,5]]

        matrix = matrix_operations.Matrix(X, Y)

        # test exception
        self.assertRaises(Exception, matrix.add)
        self.assertRaises(Exception, matrix.subtract)
コード例 #7
0
ファイル: test_math.py プロジェクト: NP-compete/AlgoPy
 def test_matrix_unique_paths(self):
     matrix = matrix_operations.Matrix()
     self.assertEqual(matrix.count_unique_paths(3, 3), 6)