Skip to content

Commit eb96af6

Browse files
Cover test case #2
1 parent 9bb1545 commit eb96af6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/string_calculator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
def calculate_sum(input_string):
2-
numbers = input_string.split(',')
3-
number1, number2 = map(int, numbers)
4-
return number1 + number2
2+
if input_string is None or input_string == "":
3+
return 0
4+
else:
5+
numbers = input_string.split(',')
6+
number1, number2 = map(int, numbers)
7+
return number1 + number2

test/test_string_calculator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@
1616
("5,99", 104)
1717
]
1818

19+
test_cases_for_empty_or_null_input = [
20+
("", 0),
21+
(None, 0)
22+
]
23+
1924

2025
@pytest.mark.parametrize("input_string, expected", test_cases_for_sum_calculation)
2126
def test_sum_calculation(input_string, expected):
2227
assert calculate_sum(input_string) == expected
28+
29+
30+
@pytest.mark.parametrize("input_string, expected", test_cases_for_empty_or_null_input)
31+
def test_empty_or_null_input(input_string, expected):
32+
assert calculate_sum(input_string) == expected

0 commit comments

Comments
 (0)