def test_negatives_are_not_allowed():
    with pytest.raises(NegativeNumbersException) as excinfo:
        Add("-1,2,-3,4")

    assert "Negatives not allowed: -1 -3 " == str(excinfo.value)

    with pytest.raises(NegativeNumbersException) as excinfo:
        Add("1\n2,-3,-4")

    assert "Negatives not allowed: -3 -4 " == str(excinfo.value)

    with pytest.raises(NegativeNumbersException) as excinfo:
        Add("-100\n-2,9999,-10")

    assert "Negatives not allowed: -100 -2 -10 " == str(excinfo.value)
def test_many_integers_with_newline():
    assert Add("1\n2,3") == 6
    assert Add("50,10\n3") == 63
    assert Add("8\n2\n22,3") == 35
Пример #3
0
def test_empty_string():
    assert Add("") == 0
Пример #4
0
def test_negatives():
    with pytest.raises(ValueError, match=r"Negatives not allowed:-1"):
        Add("-1,2")

    with pytest.raises(ValueError, match=r"Negatives not allowed:-4,-5"):
        Add("2,-4,3,-5")
Пример #5
0
def test_wit_comma_and_newline():
    assert Add("1\n2,3") == 6
Пример #6
0
def test_two_digits():
    assert Add("1,2") == 3
    assert Add("5,7") == 12
Пример #7
0
def test_handle_newline():
    assert Add("1\n2,3") == 6
def test_single_number():
    assert Add("3") == 3
    assert Add("4") == 4
    assert Add("25") == 25
    assert Add("60") == 60
Пример #9
0
 def test_negative_numbers(self):
     self.assertEqual(Add("-1,2"), 2)
Пример #10
0
 def test_ignore_bigger_1000(self):
     self.assertEqual(Add("1001,2"), 2)
Пример #11
0
 def test_split_on_newline(self):
     self.assertEqual(Add("1\n2"), 3)
Пример #12
0
 def test_unknown_numbers(self):
     self.assertEqual(Add("10,2,5,22,1,1"), 41)
Пример #13
0
 def test_two_num(self):
     self.assertEqual(Add("1,2"), 3)
def test_one_integer():
    assert Add("1") == 1
    assert Add("45") == 45
    assert Add("101") == 101
def test_numbers_bigger_than_thousand():
    assert Add("1001,2") == 2
    assert Add("3\n3000") == 3
    assert Add("1000,500\n1042") == 1500
Пример #16
0
 def test_different_delimiters(self):
     self.assertEqual(Add("//%\n1%2%3"), 6)
def test_different_delimiter():
    assert Add("//X\n1X2") == 3
    assert Add("//%\n1%2%3") == 6
    assert Add("//[delimiter]\n") == 0
Пример #18
0
 def test_empty(self):
     self.assertEqual(Add(""), "")
Пример #19
0
def test_unknown_number():
    assert Add("1,2,3,4,5") == 15
    assert Add("10,2,5,22,1,1") == 41
Пример #20
0
 def test_single_num(self):
     self.assertEqual(Add("1"), 1)
Пример #21
0
def test_support_delimeters():
    Add("//X\n1X2") == 3
    Add("//%\n1%2%3") == 6
def test_two_numbers():
    assert Add("3,4") == 7
    assert Add("4,5") == 9
    assert Add("2,5") == 7
    assert Add("6,0") == 6
Пример #23
0
def test_unknown_num_of_digits():
    assert Add("1,2,3,4,5") == 15
    assert Add("10,2,5,22,1,1") == 41
def test_unknown_number_of_numbers():
    assert Add("3,4,5,6") == 18
    assert Add("4,5,10") == 19
    assert Add("20,51") == 71
    assert Add("9,10,13") == 32
Пример #25
0
def test_ignore_over_1000():
    assert Add("1001,2") == 2
    assert Add("1002,3,4") == 7
def test_new_line_between_numbers():
    assert Add("3\n4,5,6") == 18
    assert Add("4\n5,10\n") == 19
    assert Add("20\n") == 20
    assert Add("9\n10\n13") == 32
Пример #27
0
def test_new_delimeter():
    assert Add("//X\n1X2") == 3

    assert Add("//%\n1%2%3") == 6
def test_numbers_bigger_than_1000():
    assert Add("3,4002,999,6") == 1008
    assert Add("4,1001,1000") == 1004
    assert Add("20\n9000") == 20
    assert Add("9000,2000,1300") == 0
Пример #29
0
def test_single_digit():
    assert Add("1") == 1
def test_many_integers_with_comma():
    assert Add("1,2,3") == 6
    assert Add("5,10,100,23,7") == 145
    assert Add("7,5,49,5") == 66