Ejemplo n.º 1
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() == [])
Ejemplo n.º 2
0
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() == [])
Ejemplo n.º 3
0
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() == [])
Ejemplo n.º 4
0
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() == [])
Ejemplo n.º 5
0
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')
Ejemplo n.º 6
0
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() == [])
Ejemplo n.º 7
0
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() == [])
Ejemplo n.º 8
0
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')
Ejemplo n.º 9
0
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() == [])
Ejemplo n.º 10
0
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() == [])
Ejemplo n.º 11
0
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() == [])
Ejemplo n.º 12
0
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() == [])
Ejemplo n.º 13
0
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() == [])
Ejemplo n.º 14
0
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() == [])
Ejemplo n.º 15
0
def test_flipped_left_right():
    matrix = MyMatrix(some_matrix)
    new_matrix = matrix.flipped_left_right()
    assert (new_matrix.size() == (3, 2))
    assert (new_matrix.get_data() == [[2, 1], [4, 3], [6, 5]])

    empty_matrix = MyMatrix([])
    empty_matrix.flip_left_right()
    assert (empty_matrix.size() == (0, 0))
    assert (empty_matrix.get_data() == [])
Ejemplo n.º 16
0
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))
Ejemplo n.º 17
0
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))
Ejemplo n.º 18
0
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() == [])
Ejemplo n.º 19
0
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() == [])
Ejemplo n.º 20
0
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() == [])
Ejemplo n.º 21
0
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() == [])
Ejemplo n.º 22
0
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() == [])
Ejemplo n.º 23
0
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]])
Ejemplo n.º 24
0
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]])
Ejemplo n.º 25
0
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]])
Ejemplo n.º 26
0
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],
    ])
Ejemplo n.º 27
0
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)
Ejemplo n.º 28
0
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]])
Ejemplo n.º 29
0
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]])
Ejemplo n.º 30
0
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)