Skip to content
Snippets Groups Projects
Commit e177c9e7 authored by Hatice Yildirim's avatar Hatice Yildirim
Browse files

Implementierung von GotsisWasili mit meinen Testfällen getestet

parent 079adc39
No related branches found
No related tags found
2 merge requests!8Develop2,!3GotsisWasili
import unittest
from abc import ABC, abstractmethod
#Interface für Counter
class IRomanNumber(ABC):
@abstractmethod
def convert_int_to_str(self, n: int) -> str:
pass
# Implementierung Converter Klasse
class RomanNumber(IRomanNumber):
def convert_int_to_str(self, n: int) -> str:
#Eingabe anders als int
if not isinstance(n, int):
return "Fehler: Bitte Zahl eingeben"
#Int Eingabe kleiner gleich 0
if n <= 0:
return "Integer muss größer als 0 sein"
# Bekannte Werte umwandeln
roman_convert = {1: "I", 21: "XXI", 1000: "M"}
return roman_convert.get(n)
# Testklasse (TestConverter)
class TestRomanNumber (unittest.TestCase):
def setUp(self):
self.r = RomanNumber()
def test_convert_1(self):
self.assertEqual(self.r.convert_int_to_str(1), "I")
def test_convert_21(self):
self.assertEqual(self.r.convert_int_to_str(21), "XXI")
def test_convert_empty(self):
self.assertEqual(self.r.convert_int_to_str(None), "Fehler: Bitte Zahl eingeben")
def test_convert_string(self):
self.assertEqual(self.r.convert_int_to_str("Hello"), "Fehler: Bitte Zahl eingeben")
def test_convert_downzero(self):
self.assertEqual(self.r.convert_int_to_str(-5), "Integer muss größer als 0 sein")
def test_convert_downzero(self):
self.assertEqual(self.r.convert_int_to_str(1000), "M")
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