コード例 #1
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 CalculatorRPN();

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

            Assert.AreEqual(expected, sut.Value(precision));
        }
コード例 #2
0
        [TestCase(6, CalcOperatorType.Division, 0.5, 12)]        // 6 / 0.5
        public void TwoOperands(double op1, CalcOperatorType calcType, double op2, double expected)
        {
            var sut = new CalculatorRPN();

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

            Assert.AreEqual(expected, sut.Value());
        }
コード例 #3
0
        [TestCase(3, CalcOperatorType.Addition)] // 3 +
        public void SingleOperandException(double op1, CalcOperatorType calcType)
        {
            var sut = new CalculatorRPN();

            sut.AddNumber(op1);
            sut.AddOperator(new CalcOperator(calcType));

            double x;
            var    ex = Assert.Throws <TokenException>(() => x = sut.Value());

            Assert.AreEqual("Not enough values to perform operation.", ex.Message);
        }
コード例 #4
0
        [TestCase(3, CalcOperatorType.Addition, 2, 1)] // 3 + 2 1
        public void TooManyOperandException(double op1, CalcOperatorType calcType, double op2, double op3)
        {
            var sut = new CalculatorRPN();

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

            double x;
            var    ex = Assert.Throws <TokenException>(() => x = sut.Value());

            Assert.AreEqual("Too many remaining operands.", ex.Message);
        }