コード例 #1
0
def test_matrix_vector_wrong_format_4():
    matrix = [[0, 44, 0, 12], [0, 0, 0, 0], [21, 0, 0, 0]]
    vector = [[0], [0], [0], [0, 1]]
    with pytest.raises(
            ValueError,
            match=r"All vectors's rows must contain only one element"):
        multiply_matrix_vector(matrix, vector)
コード例 #2
0
def test_matrix_vector_wrong_format_2():
    matrix = [[0, 44, 0, 12], [0, 0], [21, 0, 0, 0]]
    vector = [[2], [0], [0]]
    with pytest.raises(
            ValueError,
            match=r"Wrong inputs. Matrix must be mxn or nxn and vector nx1."):
        multiply_matrix_vector(matrix, vector)
コード例 #3
0
def test_matrix_vector_3():
    matrix = [[0, 44, 0, 12], [0, 0, 0, 0], [21, 0, 0, 0]]
    vector = [[0], [0], [0], [0]]
    ar, ia, ja = multiply_matrix_vector(matrix, vector)
    assert ar == []
    assert ia == []
    assert ja == [0, 0]
コード例 #4
0
def test_matrix_vector_1():
    matrix = [[2, 0, 0, 2], [0, 44, 0, 12], [0, 0, 0, 0], [21, 0, 0, 0]]
    vector = [[2], [0], [0], [4]]
    ar, ia, ja = multiply_matrix_vector(matrix, vector)
    assert ar == [12, 48, 42]
    assert ia == [0, 1, 3]
    assert ja == [0, 3]
コード例 #5
0
def test_vector_matrix_empty_matrix():
    matrix = []
    vector = [[2, 0, 4]]
    with pytest.raises(ValueError, match=r"Empty matrix was given"):
        multiply_matrix_vector(matrix, vector)
コード例 #6
0
def test_matrix_vector_empty_vector():
    matrix = [[0, 44, 0, 12], [0, 0, 0, 0], [21, 0, 0, 0]]
    vector = []
    with pytest.raises(ValueError, match=r"Empty vector was given"):
        multiply_matrix_vector(matrix, vector)
コード例 #7
0
def test_matrix_vector_wrong_format_3():
    matrix = [[0, 44, 0, 12], [0, 0, 0], [21, 0, 0, 0]]
    vector = [[0], [0], [0], [0]]
    with pytest.raises(ValueError,
                       match=r"All matrix's rows must have equal length"):
        multiply_matrix_vector(matrix, vector)