[TestCase(-2, CalcOperatorType.Division, 3, 2, -0.67)] // 1 / 6 public void Precision(double op1, CalcOperatorType calcType, double op2, int precision, double expected) { var sut = new CalculatorAPI(); sut.AddNumber(op1); sut.AddOperator(new CalcOperator(calcType)); sut.AddNumber(op2); Assert.AreEqual(expected, sut.Value(precision)); }
[TestCase(6, CalcOperatorType.Division, 0.5, 12)] // 6 / 0.5 public void TwoOperandsAPI(double op1, CalcOperatorType calcType, double op2, double expected) { var sut = new CalculatorAPI(); sut.AddNumber(op1); sut.AddOperator(new CalcOperator(calcType)); sut.AddNumber(op2); Assert.AreEqual(expected, sut.Value()); }
[TestCase(3, CalcOperatorType.Addition)] // 3 + public void SingleOperandExceptionAPI(double op1, CalcOperatorType calcType) { var sut = new CalculatorAPI(); sut.AddNumber(op1); sut.AddOperator(new CalcOperator(calcType)); double x; var ex = Assert.Throws <System.AggregateException>(() => x = sut.Value()); Assert.AreEqual("One or more errors occurred. (Response status code does not indicate success: 400 (Bad Request).)", ex.Message); }