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
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
No preview for this file type
File added
......@@ -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
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 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
......@@ -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
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