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

Umsetzung UML Digramm + Tests geschrieben

parent ecc1640e
No related branches found
No related tags found
1 merge request!2StringCalculatorTestListBasic
No preview for this file type
File added
......@@ -4,3 +4,8 @@ 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
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
No preview for this file type
File added
......@@ -97,4 +97,5 @@ class TestRomanNumber(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
# python -m unittest tests.test_romannumerals
# python -m unittest discover -s tests
\ No newline at end of file
......@@ -3,3 +3,26 @@
# 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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment