Skip to content
Snippets Groups Projects
Commit fcafdbfd authored by linopino's avatar linopino
Browse files

Umsetzung der Testszenarien von Feature2

parent b8ab3a4e
No related branches found
No related tags found
2 merge requests!7Develop into main,!2Feature2
from src.interfaces import IStringCalculator
import re
class StringCalculator(IStringCalculator):
def add(self, numbers: str) -> int:
if not numbers:
return 0
return sum(map(int, numbers.split(',')))
\ No newline at end of file
# Erlaubt Kommas und Zeilenumbrüche als Trennzeichen
tokens = re.split(r"[,\n]", numbers)
return sum(map(int, tokens))
\ No newline at end of file
......@@ -31,6 +31,10 @@ class TestStringCalculator(unittest.TestCase):
self.assertEqual(self.calculator.add("1,2,3"), 6)
self.assertEqual(self.calculator.add("10,20,30,40"), 100)
def test_add_with_newline_separator(self):
self.assertEqual(self.calculator.add("1\n2,3"), 6)
self.assertEqual(self.calculator.add("10\n20\n30"), 60)
if __name__ == "__main__":
unittest.main()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment