public void AdditionTest() { //Arrange double a = 5; double b = 5; double result; //Act ICalculatorComponent calculator = new Calculator(); ICalculatorComponent addition = new AdditionDecorator(calculator); addition.CreateCalculation(calculator, a, b); result = addition.GetResult(calculator); //Assert Assert.AreEqual(10, result); }
public void Decorator_DesignPatternTest() { //Arrange double a = 5; double b = 5; double c = 144; double d = 12; double result1, result2, result3, result4, result5, result6; //Act ICalculatorComponent calculator = new Calculator(); ICalculatorComponent addition = new AdditionDecorator(calculator); ICalculatorComponent subtraction = new SubtractionDecorator(calculator); ICalculatorComponent multiplication = new MultiplicationDecorator(calculator); ICalculatorComponent division = new DivisionDecorator(calculator); ICalculatorComponent squareroot = new SquareRootDecorator(calculator); ICalculatorComponent square = new SquareDecorator(calculator); addition.CreateCalculation(calculator, a, b); result1 = addition.GetResult(calculator); subtraction.CreateCalculation(calculator, a, b); result2 = subtraction.GetResult(calculator); multiplication.CreateCalculation(calculator, a, b); result3 = multiplication.GetResult(calculator); division.CreateCalculation(calculator, a, b); result4 = division.GetResult(calculator); squareroot.CreateCalculation(calculator, c); result5 = squareroot.GetResult(calculator); square.CreateCalculation(calculator, d); result6 = square.GetResult(calculator); //Assert Assert.AreEqual(10, result1); Assert.AreEqual(0, result2); Assert.AreEqual(25, result3); Assert.AreEqual(1, result4); Assert.AreEqual(12, result5); Assert.AreEqual(144, result6); }