コード例 #1
0
def test_add_greater_than_100():
    result = add('2,1001')
    assert result == 2
    result = add('2,1451,5')
    assert result == 7
    result = add('2\n1001,4521,6,12')
    assert result == 20
コード例 #2
0
def test_add_any_char_length_delimiter():
    result = add('//[***][%]\n1***2%3')
    assert result == 6
    result = add('//[*][%^%^%^][==]\n1*2%^%^%^3==4')
    assert result == 10
    result = add('//[*][%][=][&****^]\n1*2%3=4&****^5')
    assert result == 15
    result = add('//[*][%%][===][&&&&][$$$$$]\n1*2%%3===4&&&&5$$$$$6')
    assert result == 21
コード例 #3
0
def test_add_multiple_delimiters():
    result = add('//[*][%]\n1*2%3')
    assert result == 6
    result = add('//[*][%][=]\n1*2%3=4')
    assert result == 10
    result = add('//[*][%][=][&]\n1*2%3=4&5')
    assert result == 15
    result = add('//[*][%][=][&][$]\n1*2%3=4&5$6')
    assert result == 21
コード例 #4
0
def test_add_any_length_delimiter():
    result = add('//[***]\n1***2***3')
    assert result == 6
    result = add('//[***]\n14***21***37')
    assert result == 72
    result = add('//[***]\n5***2***3')
    assert result == 10
    result = add('//[***]\n45***23***1002')
    assert result == 68
コード例 #5
0
def test_add_negative_exception():
    with pytest.raises(ValueError):
        result = add('-4')
    with pytest.raises(ValueError):
        result = add('1,-2')
    with pytest.raises(ValueError):
        result = add('1,2,-3,4,5,-6,7')
    with pytest.raises(ValueError):
        result = add('-1\n2,3')
    with pytest.raises(ValueError):
        result = add('1\n2\n3\n-4\n5')
    with pytest.raises(ValueError):
        result = add('//;\n-1;2')
コード例 #6
0
def test_add_single_number():
    result = add('4')
    assert result == 4
コード例 #7
0
def test_add_empty_string():
    result = add('')
    assert result == 0
コード例 #8
0
def test_add_delimiter():
    result = add('//;\n1;2')
    assert result == 3
コード例 #9
0
def test_add_new_lines():
    result = add('1\n2,3')
    assert result == 6
    result = add('1\n2\n3\n4\n5')
    assert result == 15
コード例 #10
0
def test_add_unknown_numbers():
    result = add('1,2,3,4,5,6,7')
    assert result == 28
コード例 #11
0
def test_add_two_numbers():
    result = add('1,2')
    assert result == 3