예제 #1
0
        [TestCase(10, CalcOperatorType.Subtraction, 4, CalcOperatorType.Division, 2, 8)]   // 10 - 4 / 2
        public void ThreeOperandsException(double op1, CalcOperatorType calcType1, double op2, CalcOperatorType calcType2, double op3, double result)
        {
            var sut = new CalculatorAPI();

            sut.AddNumber(op1);
            sut.AddOperator(new CalcOperator(calcType1));
            sut.AddNumber(op2);

            var ex = Assert.Throws <CalculatorException>(() => sut.AddOperator(new CalcOperator(calcType2)));

            Assert.AreEqual("API does not support BEDMAS processing.", ex.Message);
        }
예제 #2
0
        [TestCase(1, CalcOperatorType.Multiplication, 4, CalcOperatorType.Addition, 5, 9)] // 1 * 4 + 5
        public void ThreeOperandsAPI(double op1, CalcOperatorType calcType1, double op2, CalcOperatorType calcType2, double op3, double expected)
        {
            var sut = new CalculatorAPI();

            sut.AddNumber(op1);
            sut.AddOperator(new CalcOperator(calcType1));
            sut.AddNumber(op2);
            sut.AddOperator(new CalcOperator(calcType2));
            sut.AddNumber(op3);

            Assert.AreEqual(expected, sut.Value());
        }
예제 #3
0
        [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));
        }
예제 #4
0
        [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);
        }