예제 #1
0
def test_addition_csc_wrong_matrix_format_1():
    matrix_1 = [[12, 12], "21"]
    matrix_2 = [[0, 0], [0, 0]]
    with pytest.raises(
            ValueError,
            match=
            r"Every row in matrix must best list or tuple and have the same length"
    ):
        csc_addition_matrices(matrix_1, matrix_2)
예제 #2
0
def test_addition_csc_mxn():
    matrix_1 = [[1, 0, 3], [0, 0, 5]]
    matrix_2 = [[1, 0, 3], [0, 0, 5]]
    ar, ia, ja = csc_addition_matrices(matrix_1, matrix_2)
    assert ar == [2, 6, 10]
    assert ia == [0, 0, 1]
    assert ja == [0, 1, 1, 3]
예제 #3
0
def test_addition_csc_zero_matrices():
    matrix_1 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    matrix_2 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    ar, ia, ja = csc_addition_matrices(matrix_1, matrix_2)
    assert ar == []
    assert ia == []
    assert ja == [0, 0, 0, 0, 0]
예제 #4
0
def test_addition_csc_nxn():
    matrix_1 = [[1, 0, 3], [0, 0, 5], [1, 5, 0]]
    matrix_2 = [[0, 2, 0], [0, 1, 5], [0, 2, 0]]
    ar, ia, ja = csc_addition_matrices(matrix_1, matrix_2)
    assert ar == [1, 1, 2, 1, 7, 3, 10]
    assert ia == [0, 2, 0, 1, 2, 0, 1]
    assert ja == [0, 2, 5, 7]
예제 #5
0
def test_addition_csc_empty_matrix():
    matrix_1 = []
    matrix_2 = [[0, 2, 0], [0, 1, 5]]
    with pytest.raises(ValueError, match=r"First given matrix is empty"):
        csc_addition_matrices(matrix_1, matrix_2)
예제 #6
0
def test_addition_csc_wrong_matrix_format_3():
    matrix_1 = [[1, 0, 3], [0, 0], [1, 5, 0]]
    matrix_2 = [[1, 0, 3], [0, 0, 5], [1, 5, 0]]
    with pytest.raises(ValueError,
                       match=r"All matrix_1's rows must have equal length"):
        csc_addition_matrices(matrix_1, matrix_2)
예제 #7
0
def test_addition_csc_wrong_matrix_format_2():
    matrix_1 = [[0, 0], [0, 0]]
    matrix_2 = [[12, 12], {"21"}]
    with pytest.raises(ValueError,
                       match=r"All matrix_2's rows must have equal length"):
        csc_addition_matrices(matrix_1, matrix_2)
예제 #8
0
def test_addition_csc_different_matrices_rows():
    matrix_1 = [[1, 0, 3], [0, 0, 5], [1, 5, 0]]
    matrix_2 = [[0, 2, 0], [0, 1, 5]]
    with pytest.raises(ValueError,
                       match=r"Both matrices must have same number of rows."):
        csc_addition_matrices(matrix_1, matrix_2)