コード例 #1
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))
コード例 #2
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() == [])
コード例 #3
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() == [])
コード例 #4
0
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]])
コード例 #5
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() == [])
コード例 #6
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() == [])
コード例 #7
0
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)
コード例 #8
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() == [])
コード例 #9
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)
コード例 #10
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]])
コード例 #11
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]])
コード例 #12
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)
コード例 #13
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() == [])
コード例 #14
0
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)
コード例 #15
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]])
コード例 #16
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() == [])
コード例 #17
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() == [])
コード例 #18
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() == [])
コード例 #19
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() == [])
コード例 #20
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() == [])
コード例 #21
0
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() == [])
コード例 #22
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],
    ])
コード例 #23
0
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() == [])
コード例 #24
0
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() == [])
コード例 #25
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() == [])
コード例 #26
0
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],
    ])
コード例 #27
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() == [])
コード例 #28
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() == [])
コード例 #29
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() == [])
コード例 #30
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() == [])