コード例 #1
0
def test_matrix_matrix_wrong_format_3():
    matrix_1 = [[2, 0, 0, 2], [0, 2, 2, 0], [7, 0, 0, 0], [21, 0, 0, 0]]
    matrix_2 = [[0, 0, 0, 12], [10, 0, 2, 2], [21, 0, 0, 0]]
    with pytest.raises(
            ValueError,
            match=r"Wrong inputs. Matrix_1 must be mxn and matrix_2 nxk."):
        matrix_matrix_multiplication(matrix_1, matrix_2)
コード例 #2
0
def test_matrix_matrix_mxn_1():
    matrix_1 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    matrix_2 = [[2, 0, 0], [0, 0, 12], [0, 2, 10], [1, 6, 0]]
    ar, ia, ja = matrix_matrix_multiplication(matrix_1, matrix_2)
    assert ar == []
    assert ia == [0, 0, 0, 0, 0]
    assert ja == []
コード例 #3
0
def test_matrix_matrix_mxn():
    matrix_1 = [[2, 0, 0, 2], [0, 44, 0, 12], [7, 0, 0, 0], [21, 0, 0, 0]]
    matrix_2 = [[2, 0, 0], [0, 0, 12], [0, 2, 10], [1, 6, 0]]
    ar, ia, ja = matrix_matrix_multiplication(matrix_1, matrix_2)
    assert ar == [6, 12, 12, 72, 528, 14, 42]
    assert ia == [0, 2, 5, 6, 7]
    assert ja == [0, 1, 0, 1, 2, 0, 0]
コード例 #4
0
def test_matrix_matrix_nxn_3():
    matrix_1 = [[2, 0, 0, 2], [0, 44, 0, 12], [7, 0, 0, 0], [21, 0, 0, 0]]
    matrix_2 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    ar, ia, ja = matrix_matrix_multiplication(matrix_1, matrix_2)
    assert ar == []
    assert ia == [0, 0, 0, 0, 0]
    assert ja == []
コード例 #5
0
def test_matrix_matrix_nxn_2():
    matrix_1 = [[2, 0, 0, 2], [0, 44, 0, 12], [7, 0, 0, 0], [21, 0, 0, 0]]
    matrix_2 = [[2, 0, 0, 2], [0, 0, 0, 12], [0, 2, 0, 10], [21, 0, 0, 0]]
    ar, ia, ja = matrix_matrix_multiplication(matrix_1, matrix_2)
    assert ar == [46, 4, 252, 528, 14, 14, 42, 42]
    assert ia == [0, 2, 4, 6, 8]
    assert ja == [0, 3, 0, 3, 0, 3, 0, 3]
コード例 #6
0
def test_matrix_matrix_nxn_1():
    matrix_1 = [[2, 0, 0, 2], [0, 44, 0, 12], [0, 0, 0, 0], [21, 0, 0, 0]]
    matrix_2 = [[2, 0, 0, 2], [0, 44, 0, 12], [0, 0, 0, 0], [21, 0, 0, 0]]
    ar, ia, ja = matrix_matrix_multiplication(matrix_1, matrix_2)
    assert ar == [46, 4, 252, 1936, 528, 42, 42]
    assert ia == [0, 2, 5, 5, 7]
    assert ja == [0, 3, 0, 1, 3, 0, 3]
コード例 #7
0
def test_matrix_matrix_wrong_format_2():
    matrix_1 = [[2, 0, 0, 2], [0, 2, 2, 0], [7, 0, 0, 0], [21, 0, 0, 0]]
    matrix_2 = [[2, 0, 0, 2], [0, 0, 0, 12], [10], [21, 0, 0, 0]]
    with pytest.raises(ValueError,
                       match=r"All matrix_2's rows must have equal length"):
        matrix_matrix_multiplication(matrix_1, matrix_2)
コード例 #8
0
def test_matrix_matrix_empty_matrix_2():
    matrix_1 = [[2, 0, 0], [0, 0, 12], [0, 2, 10], [1, 6, 0]]
    matrix_2 = []
    with pytest.raises(ValueError, match=r"Second given matrix is empty"):
        matrix_matrix_multiplication(matrix_1, matrix_2)