diff --git a/Testliste.txt b/Testliste.txt new file mode 100644 index 0000000000000000000000000000000000000000..a883b4843cd2373cd5faebcf14a487b6bda6f269 --- /dev/null +++ b/Testliste.txt @@ -0,0 +1,23 @@ +Addition: + +Normale Addition add(2, 3) 5 Standardfall +Addition mit Null add(0, 5) 5 Null sollte keinen Einfluss haben +Addition mit negativen Zahlen add(-2, -3) -5 Beide Zahlen negativ +Gemischte Addition (positiv & negativ) add(-5, 10) 5 Addition mit negativem Wert +Addition mit Fließkommazahlen add(2.5, 3.5) 6.0 Floats sollten unterstützt werden +Addition mit sehr großen Zahlen add(1000000, 2000000) 3000000 Test für große Werte +Addition mit sehr kleinen Zahlen add(0.0001, 0.0002) 0.0003 Test für Genauigkeit +Addition mit Ganzzahl und Float add(3, 4.5) 7.5 Mischung aus Int und Float + +Subtraktion: + +Normale Subtraktion sub(5, 3) 2 Standardfall +Subtraktion mit Null sub(7, 0) 7 Null sollte keinen Einfluss haben +Subtraktion mit negativem Ergebnis sub(3, 7) -4 Ergebnis ist negativ +Subtraktion mit negativen Zahlen sub(-5, -3) -2 Beide Zahlen negativ +Subtraktion mit negativem Minuend sub(-2, 5) -7 Negative Zahl als Minuend +Subtraktion mit negativem Subtrahend sub(10, -5) 15 Negative Zahl als Subtrahend +Subtraktion mit Fließkommazahlen sub(5.5, 2.5) 3.0 Floats sollten unterstützt werden +Subtraktion mit sehr großen Zahlen sub(5000000, 2000000) 3000000 Test für große Werte +Subtraktion mit sehr kleinen Zahlen sub(0.0003, 0.0001) 0.0002 Test für Genauigkeit + diff --git a/__pycache__/calculator.cpython-313.pyc b/__pycache__/calculator.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5bcc7e346cb931b9b825f4145da5214858e13549 Binary files /dev/null and b/__pycache__/calculator.cpython-313.pyc differ diff --git a/__pycache__/test_calculator.cpython-313.pyc b/__pycache__/test_calculator.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e302281147138d3432262dea829951a67f760c78 Binary files /dev/null and b/__pycache__/test_calculator.cpython-313.pyc differ diff --git a/calculator.py b/calculator.py new file mode 100644 index 0000000000000000000000000000000000000000..229895766c218af5be1e0a110da8e7f72cb07964 --- /dev/null +++ b/calculator.py @@ -0,0 +1,21 @@ +from abc import ABC, abstractmethod + +class ICalculator(ABC): + """Interface Taschenrechner""" + + @abstractmethod + def add(self, a, b): + pass + + @abstractmethod + def sub(self, a, b): + pass + +class Calculator(ICalculator): + """Implementierung des Taschenrechners""" + + def add(self, a, b): + return a + b + + def sub(self, a, b): + return a - b diff --git a/calculator_interface.py b/calculator_interface.py new file mode 100644 index 0000000000000000000000000000000000000000..5522240786fcbb802251f0cc1c45a706c5e93c3f --- /dev/null +++ b/calculator_interface.py @@ -0,0 +1,16 @@ +from abc import ABC, abstractmethod + +class ICalculator(ABC): + """Interface für einen Taschenrechner""" + + @abstractmethod + def add(self, a, b): + """Addiert zwei Zahlen""" + pass + + @abstractmethod + def sub(self, a, b): + """Subtrahiert zwei Zahlen""" + pass + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000000000000000000000000000000000000..27faabb0798e4dc5a28f186967a342c3543dbcbc --- /dev/null +++ b/main.py @@ -0,0 +1,15 @@ +from calculator import Calculator + +# Instanz der Calculator-Klasse erstellen +calc = Calculator() + +# Funktionen des Taschenrechners verwenden +print("Addition:", calc.add(10, 5)) # → 15 +print("Subtraktion:", calc.sub(10, 5)) # → 5 + + +# Fehlerbehandlung testen (Division durch Null) +try: + print(calc.div(10, 0)) +except ValueError as e: + print("Fehler:", e) # → "Division durch 0 ist nicht erlaubt." diff --git a/test_calculator.py b/test_calculator.py new file mode 100644 index 0000000000000000000000000000000000000000..30a242d2a382346a9646e428b022a5dad7387939 --- /dev/null +++ b/test_calculator.py @@ -0,0 +1,25 @@ +import unittest +from calculator import Calculator + +class TestCalculator(unittest.TestCase): + """Testfälle für den Taschenrechner""" + + def setUp(self): + """Vor jedem Test wird eine neue Instanz von Calculator erstellt""" + self.calc = Calculator() + + def test_addition(self): + """Testfälle für die Addition""" + self.assertEqual(self.calc.add(2, 3), 5) + self.assertEqual(self.calc.add(-1, 1), 0) + self.assertEqual(self.calc.add(0, 0), 0) + self.assertEqual(self.calc.add(3, 4.5), 7.5) + + def test_subtraction(self): + """Testfälle für die Subtraktion""" + self.assertEqual(self.calc.sub(5, 3), 2) + self.assertEqual(self.calc.sub(10, 20), -10) + self.assertEqual(self.calc.sub(0, 0), 0) + +if __name__ == '__main__': + unittest.main()