diff --git a/Test.py b/Test.py index 3dc0985eb6e8ba97965d0638d33d747171278b1a..903e6d75502eb48a50b99ba6c5a6ba3d97140231 100644 --- a/Test.py +++ b/Test.py @@ -1 +1,2 @@ -print("Hello WORLD") \ No newline at end of file +print("Hello WORLD") +print("test") \ No newline at end of file diff --git a/calculator.py b/calculator.py new file mode 100644 index 0000000000000000000000000000000000000000..e799761a891c6add0f8c76442f7d6d523992d0e0 --- /dev/null +++ b/calculator.py @@ -0,0 +1,29 @@ +#Test1: Addition 2 positiver Zaheln (2+5) erwartetes Ergebnis 8 +#Test2: Addition negativer und positiver Zahl (-1+1) erwartetes Ergebnis 0 +#Test3: Addition (0+0), erwartetes Ergebnis 0 +#Test4: Addition von 2 Dezimalzahlen (2,5+3,5), erwartetes Ergebnis 6 + +from abc import ABC, abstractmethod +class ICalculator(ABC): + @abstractmethod + def add(self, a: float, b: float) -> float: + pass + +class Calculator(ICalculator): + def add(self, a: float, b: float) -> float: + return a + b + +class TestCalculator: + def __init__(self, calculator: ICalculator): + self.calculator = calculator + def test_add(self): + assert self.calculator.add(2,3) == 5, "Fehler falls nicht 5" + assert self.calculator.add(-1,1) == 0, "Fegler falls nich 0" + assert self.calculator.add(0,0) == 0, "Fehler falls nicht 0" + assert self.calculator.add(2.5,3.5) == 6, "Fehler falls nicht 5" + print("Test erfolgreich") + +if __name__ == "__main__": + calc = Calculator() + tester = TestCalculator(calc) + tester.test_add()