def test__add__(): matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) other = MyMatrix([[12, 2, 3], [900, 67, 4]]) m = matrix + other assert (m.get_data() == [[13, 4, 6], [904, 72, 10]]) assert (matrix.get_data() == [[1, 2, 3], [4, 5, 6]]) assert (other.get_data() == [[12, 2, 3], [900, 67, 4]])
def test_transpose(): zero_matrix = MyMatrix([]) matrix = MyMatrix([[1, 2], [5, 6], [4, 7]]) matrix.transpose() assert (matrix.size() == (2, 3)) assert (matrix.get_data() == [[1, 5, 4], [2, 6, 7]]) assert (zero_matrix.transpose().get_data() == [])
def test__repr(): matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) assert (repr(matrix) == '1 2 3 \n4 5 6') matrix = MyMatrix([]) assert (repr(matrix) == '') matrix = MyMatrix([[-1, -2, -3], [4, 5, 6]]) assert (repr(matrix) == '-1 -2 -3 \n4 5 6')
def test_flipped_left_right(): matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) assert (matrix.flipped_left_right()._get_data() == [[3, 2, 1], [6, 5, 4]]) assert (repr(matrix) == '1 2 3 \n4 5 6') matrix = MyMatrix([[1, 2], [3, 4], [5, 6]]) assert (matrix.flipped_left_right()._get_data() == [[2, 1], [4, 3], [6, 5]])
def test___sub__(): matrix2 = MyMatrix(a) matrix1 = MyMatrix(b) submatrix = matrix1 - matrix2 assert (submatrix.get_data() == [[6, 0], [2, 0], [-4, 0]]) assert (matrix1.get_data() == b) assert (matrix2.get_data() == a)
def test_size(): zero_matrix = MyMatrix([]) size = zero_matrix.size() matrix = MyMatrix([[1, 2], [5, 6], [4, 7]]) s = matrix.size() assert (zero_matrix.size() == (0, 0)) assert (matrix.size() == (3, 2))
def test___sub__(): matrix = MyMatrix([[1, 2], [5, 6], [4, 7]]) matrix1 = MyMatrix([[1, 2], [5, 6], [4, 1]]) matrixsum = matrix - matrix1 assert (matrix.get_data() == [[1, 2], [5, 6], [4, 7]]) assert (matrix1.get_data() == [[1, 2], [5, 6], [4, 1]]) assert (matrixsum.get_data() == [[0, 0], [0, 0], [0, 6]])
def test_rotate_180(): matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) empty_matrix = MyMatrix([]) matrix.rotate_180() empty_matrix.rotate_180() assert (matrix.get_data() == [[6, 5, 4], [3, 2, 1]]) assert (empty_matrix.get_data() == [])
def test_rotate_counterclockwise_90(): matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) empty_matrix = MyMatrix([]) matrix.rotate_counterclockwise_90() empty_matrix.rotate_counterclockwise_90() assert (matrix.get_data() == [[3, 6], [2, 5], [1, 4]]) assert (empty_matrix.get_data() == [])
def test___add__(): matrix1 = MyMatrix(a) matrix2 = MyMatrix(b) summatrix = matrix1 + matrix2 assert (summatrix.get_data() == [[8, 4], [8, 8], [4, 10]]) assert (matrix1.get_data() == a) assert (matrix2.get_data() == b)
def test___sub__(): m2 = MyMatrix(a) m1 = MyMatrix(b) subm = m2 - m1 assert (subm.get_data() == [[-1, 0], [-4, -3], [0, -1]]) assert (m1.get_data() == b) assert (m2.get_data() == a)
def test_transpose(): m1 = MyMatrix(a) m2 = MyMatrix(c) m1.transpose() m2.transpose() assert (m1.get_data() == [[2, 1, 0], [2, 1, 4]]) assert (m2.get_data() == [])
def test_flip_up_down(): m1 = MyMatrix(a) m2 = MyMatrix(c) m1.flip_up_down() m2.flip_up_down() assert (m1.get_data() == [[0, 4], [1, 1], [2, 2]]) assert (m2.get_data() == [])
def test___add__(): m1 = MyMatrix(a) m2 = MyMatrix(b) summ = m1 + m2 assert (summ.get_data() == [[5, 4], [6, 5], [0, 9]]) assert (m1.get_data() == a) assert (m2.get_data() == b)
def test_rotate_clockwise_90(): matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) matrix.rotate_clockwise_90() assert (matrix.get_data() == [[4, 1], [5, 2], [6, 3]]) empty_matrix = MyMatrix([]) empty_matrix.rotate_clockwise_90() assert (empty_matrix.get_data() == [])
def test_flip_left_right(): m1 = MyMatrix(a) m2 = MyMatrix(c) m1.flip_left_right() m2.flip_left_right() assert (m1.get_data() == [[2, 2], [1, 1], [4, 0]]) assert (m2.get_data() == [])
def test_size(): matrix = MyMatrix(a) assert (matrix.get_data() == a) assert (matrix.size() == (3, 2)) empty_matrix = MyMatrix(c) assert (empty_matrix.get_data() == []) assert (empty_matrix.size() == (0, 0))
def test__sub__(): matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) other = MyMatrix([[12, 2, 3], [900, 67, 4]]) m = matrix - other assert (m.get_data() == [[-11, 0, 0], [-896, -62, 2]]) assert (matrix.get_data() == [[1, 2, 3], [4, 5, 6]]) assert (other.get_data() == [[12, 2, 3], [900, 67, 4]])
def test___add__(): matrix = MyMatrix([[1, 2], [5, 6], [4, 7]]) matrix1 = MyMatrix([[1, 2], [5, 6], [4, 1]]) matrixsum = matrix + matrix1 assert (matrix.get_data() == [[1, 2], [5, 6], [4, 7]]) assert (matrix1.get_data() == [[1, 2], [5, 6], [4, 1]]) assert (matrixsum.get_data() == [[2, 4], [10, 12], [8, 8]])
def test_flip_left_right(): matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) m = matrix.flip_left_right() empty_matrix = MyMatrix([]) assert (m.get_data() == [[3, 2, 1], [6, 5, 4]]) empty_matrix.flip_left_right() assert (empty_matrix.get_data() == [])
def test_transposed(): m1 = MyMatrix(a) m2 = MyMatrix(c) res1 = m1.transposed() res2 = m2.transposed() assert (res1.get_data() == [[2, 1, 0], [2, 1, 4]]) assert (res2.get_data() == []) assert (m1.get_data() == [[2, 2], [1, 1], [0, 4]])
def test_flipped_left_right(): m1 = MyMatrix(a) m2 = MyMatrix(c) res1 = m1.flipped_left_right() res2 = m2.flipped_left_right() assert (res1.get_data() == [[2, 2], [1, 1], [4, 0]]) assert (res2.get_data() == []) assert (m1.get_data() == [[2, 2], [1, 1], [0, 4]])
def test_flipped_up_down(): m1 = MyMatrix(a) m2 = MyMatrix(c) res1 = m1.flipped_up_down() res2 = m2.flipped_up_down() assert (res1.get_data() == [[0, 4], [1, 1], [2, 2]]) assert (res2.get_data() == []) assert (m1.get_data() == [[2, 2], [1, 1], [0, 4]])
def test_flip_up_down(): m = [[1, 2, 3], [4, 5, 6]] matrix = MyMatrix(m) matrix.flip_up_down() assert (matrix.size() == (2, 3)) assert (matrix.get_data() == [[4, 5, 6], [1, 2, 3]]) empty_matrix = MyMatrix([]) assert (empty_matrix.get_data() == [])
def test_repr(): mymatrix = MyMatrix([[1, 2], [3, 4]]) assert (repr(mymatrix) == '1 2\n3 4') mymatrix = MyMatrix([[], []]) assert (repr(mymatrix) == '') mymatrix = MyMatrix([[-1, -2], [-3, -4]]) assert (repr(mymatrix) == '-1 -2\n-3 -4') mymatrix = MyMatrix([[-1, 556], [989, -4]]) assert (repr(mymatrix) == '-1 556\n989 -4')
def test_transposed(): matrix = MyMatrix([[1, 2, 3, 4], [5, 6, 7, 8]]) matrix1 = matrix.transposed() assert (matrix.get_data() == [[1, 2, 3, 4], [5, 6, 7, 8]]) assert (matrix1.get_data() == [[1, 5], [2, 6], [3, 7], [4, 8]]) empty_matrix = MyMatrix(c) em_matrix = empty_matrix.transposed() assert (empty_matrix.get_data() == []) assert (em_matrix.get_data() == [])
def test_flipped_up_down(): matrix = MyMatrix(a) flmatrix = matrix.flipped_up_down() assert (flmatrix.get_data() == [[4, 5], [3, 4], [1, 2]]) assert (matrix.get_data() == [[1, 2], [3, 4], [4, 5]]) empty_matrix = MyMatrix(c) em_matrix = empty_matrix.flipped_left_right() assert (empty_matrix.get_data() == []) assert (em_matrix.get_data() == [])
def test_flipped_up_down(): zero_matrix = MyMatrix([]) zero_matrixcopy = zero_matrix.flipped_up_down() matrix = MyMatrix([[1, 2], [5, 6], [4, 7]]) matrix2 = matrix.flipped_up_down() assert (matrix2.get_data() == [[4, 7], [5, 6], [1, 2]]) assert (matrix.get_data() == [[1, 2], [5, 6], [4, 7]]) assert (zero_matrix.get_data() == []) assert (zero_matrixcopy.get_data() == [])
def test_flipped_left_right(): zero_matrix = MyMatrix([]) zero_matrixcopy = zero_matrix.flipped_left_right() matrix = MyMatrix([[1, 2], [5, 6], [4, 7]]) matrix2 = matrix.flipped_left_right() assert (matrix2.get_data() == [[2, 1], [6, 5], [7, 4]]) assert (matrix.get_data() == [[1, 2], [5, 6], [4, 7]]) assert (zero_matrix.get_data() == []) assert (zero_matrixcopy.get_data() == [])
def test_transpose(): data = [[1, 2, 3], [4, 5, 6]] matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) matrix.transpose() assert (matrix.get_data() == [[1, 4], [2, 5], [3, 6]]) assert (matrix.size() == (3, 2)) empty_matrix = MyMatrix([]) empty_matrix.transpose() assert (empty_matrix.size() == (0, 0)) assert (empty_matrix.get_data() == [])