diff --git a/src/__pycache__/interfaces.cpython-310.pyc b/src/__pycache__/interfaces.cpython-310.pyc index 9c2c27ce8dbc3a9cbbc432aef7c2022428ab19de..d7953f25e6f8b9e6f58dfc3cdb55b061b176f472 100644 Binary files a/src/__pycache__/interfaces.cpython-310.pyc and b/src/__pycache__/interfaces.cpython-310.pyc differ diff --git a/src/__pycache__/stringcalculator.cpython-310.pyc b/src/__pycache__/stringcalculator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..938708f3482e2cedde5ca28d3caf0cfceea2ad7f Binary files /dev/null and b/src/__pycache__/stringcalculator.cpython-310.pyc differ diff --git a/src/interfaces.py b/src/interfaces.py index bc8c8c3ef35efbce40861f4feeedc7c44c0a04dd..7a3cc8e1962344df1a13d7895841f695451edb06 100644 --- a/src/interfaces.py +++ b/src/interfaces.py @@ -3,4 +3,9 @@ from abc import ABC, abstractmethod class IRomanNumber(ABC): @abstractmethod def convert(self, n: int) -> str: + pass + +class IStringCalculator(ABC): + @abstractmethod + def add(self, numbers: str) -> int: pass \ No newline at end of file diff --git a/src/stringcalculator.py b/src/stringcalculator.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..41f666fdc4d0e39d619a00d678088cdbfca15376 100644 --- a/src/stringcalculator.py +++ b/src/stringcalculator.py @@ -0,0 +1,7 @@ +from src.interfaces import IStringCalculator + +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 diff --git a/tests/__pycache__/test_romannumerals.cpython-310.pyc b/tests/__pycache__/test_romannumerals.cpython-310.pyc index 2ef85d1aa0aaa5d708fc349e4ed24856b6f600f4..1809b2b966feaa1479662587eca1207db19195ad 100644 Binary files a/tests/__pycache__/test_romannumerals.cpython-310.pyc and b/tests/__pycache__/test_romannumerals.cpython-310.pyc differ diff --git a/tests/__pycache__/test_stringcalculator.cpython-310.pyc b/tests/__pycache__/test_stringcalculator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..31a224455e3a18f535acc76eafba13b427a27f89 Binary files /dev/null and b/tests/__pycache__/test_stringcalculator.cpython-310.pyc differ diff --git a/tests/test_romannumerals.py b/tests/test_romannumerals.py index abc5266bfc1e67c1c6007e637d7a5648b218e114..35e2af35f754d89a2da55ab9537741a29fd40960 100644 --- a/tests/test_romannumerals.py +++ b/tests/test_romannumerals.py @@ -97,4 +97,5 @@ class TestRomanNumber(unittest.TestCase): if __name__ == "__main__": unittest.main() -#python -m unittest discover -s tests \ No newline at end of file +# python -m unittest tests.test_romannumerals +# python -m unittest discover -s tests \ No newline at end of file diff --git a/tests/test_stringcalculator.py b/tests/test_stringcalculator.py index b8e4935f3a5abe52c006b13965c8f9abf2433d46..f7c4c1221c4d42297357b1fccd3569a34afc3a21 100644 --- a/tests/test_stringcalculator.py +++ b/tests/test_stringcalculator.py @@ -2,4 +2,27 @@ # Bei Eingabe keiner Zahl soll eine 0 ausgegeben werden # Bei Eingabe einer 1 soll 1 ausgegeben werden # Bei Eingabe einer 3,4 soll 7 ausgegeben werden -# Bei Eingabe einer 10,20 soll 30 ausgegeben werden \ No newline at end of file +# Bei Eingabe einer 10,20 soll 30 ausgegeben werden + +import unittest +from src.interfaces import IStringCalculator +from src.stringcalculator import StringCalculator + +class TestStringCalculator(unittest.TestCase): + def setUp(self): + self.calculator: IStringCalculator = StringCalculator() # Zugriff über das Interface + + def test_add_empty_string(self): + self.assertEqual(self.calculator.add(""), 0) + + def test_add_single_number(self): + self.assertEqual(self.calculator.add("1"), 1) + + def test_add_two_numbers(self): + self.assertEqual(self.calculator.add("10,20"), 30) + +if __name__ == "__main__": + unittest.main() + +# python -m unittest tests.test_stringcalculator +# python -m unittest discover -s tests \ No newline at end of file