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_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_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__(): 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(): 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_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___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_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___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___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___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___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_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___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__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_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_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_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_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_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_transpose(): matrix = MyMatrix(some_matrix) matrix = matrix.transpose() assert (matrix.size() == (2, 3)) assert (matrix.get_data() == [[1, 3, 5], [2, 4, 6]]) empty_matrix = MyMatrix([]) empty_matrix.transpose() assert (empty_matrix.size() == (0, 0)) assert (empty_matrix.get_data() == [])
def test___isub__(): m1 = MyMatrix([[2, 4, 7], [5, 1, 0]]) m2 = MyMatrix([[1, 2, 3], [4, 5, 6]]) assert (m1.get_data() == [[2, 4, 7], [5, 1, 0]]) m1 -= m2 assert (m2.get_data() == [[1, 2, 3], [4, 5, 6]]) assert (m1.get_data() == [ [1, 2, 4], [1, -4, -6], ])
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() == [])
def test_transpose(): matrix = MyMatrix([[1, 2, 3, 4], [5, 6, 7, 8]]) matrix.transpose() assert (matrix.size() == (4, 2)) #AssertionError assert (matrix.get_data() == [[1, 5], [2, 6], [3, 7], [4, 8]]) empty_matrix = MyMatrix(c) empty_matrix.transpose() assert (empty_matrix.size() == (0, 0)) assert (empty_matrix.get_data() == [])
def test_flipped_up_down(): matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) new_matrix = matrix.flipped_up_down() assert (matrix.get_data() == [[1, 2, 3], [4, 5, 6]]) assert (matrix.size() == (2, 3)) assert (new_matrix.get_data() == [[4, 5, 6], [1, 2, 3]]) empty_matrix = MyMatrix([]) e = empty_matrix.flipped_up_down() assert (empty_matrix.get_data() == []) assert (empty_matrix.size() == (0, 0)) assert (e.get_data() == [])
def test___iadd__(): m1 = MyMatrix([[2, 4, 7], [5, 1, 0]]) m2 = MyMatrix([[1, 2, 3], [4, 5, 6]]) assert (m1.get_data() == [[2, 4, 7], [5, 1, 0]]) m1 += m2 assert (m2.get_data() == [[1, 2, 3], [4, 5, 6]]) assert (m1.get_data() == [ [3, 6, 10], [9, 6, 6], ])
def test_flipped_up_down(): some_list = [[4, 5, 6], [1, 2, 3]] m1 = MyMatrix(some_list) m2 = m1.flipped_up_down() assert (m2.get_data() == [[1, 2, 3], [4, 5, 6]]) assert (m1.get_data() == [[4, 5, 6], [1, 2, 3]]) empty_matrix = MyMatrix([]) empty_matrix.flip_left_right() assert (empty_matrix.size() == (0, 0)) assert (empty_matrix.get_data() == [])
def test_transposed(): matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) m = matrix.transposed() assert (m.get_data() == [[1, 4], [2, 5], [3, 6]]) assert (matrix.size() == (2, 3)) assert (matrix.get_data() == [[1, 2, 3], [4, 5, 6]]) empty_matrix = MyMatrix([]) e = empty_matrix.transposed() assert (empty_matrix.size() == (0, 0)) assert (empty_matrix.get_data() == []) assert (e.get_data() == [])
def test_flipped_left_right(): matrix = MyMatrix([[1, 2, 3], [4, 5, 6]]) new_matrix = matrix.flipped_left_right() assert (matrix.get_data() == [[1, 2, 3], [4, 5, 6]]) assert (matrix.size() == (2, 3)) assert (new_matrix.get_data() == [[3, 2, 1], [6, 5, 4]]) empty_matrix = MyMatrix([]) e = empty_matrix.flipped_left_right() assert (empty_matrix.get_data() == []) assert (empty_matrix.size() == (0, 0)) assert (e.get_data() == [])
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() == [])