示例#1
0
        public void KeyNotFoundException()
        {
            var     calculator = new Calculator();
            decimal a          = 18;
            decimal b          = 21;
            string  oper       = "f";

            Assert.ThrowsException <KeyNotFoundException>(() => calculator.Calc(a, b, oper));
        }
示例#2
0
        public void OutPut()
        {
            var     calculator = new Calculator();
            string  input      = "4.8 + 2.8";
            decimal result     = calculator.Calc(input);
            decimal expected   = 7.6m;

            Assert.AreEqual(expected, result);
        }
示例#3
0
        public void DivideByZeroException()
        {
            var     calculator = new Calculator();
            decimal a          = 20;
            decimal b          = 0;
            string  oper       = "/";

            Assert.ThrowsException <DivideByZeroException>(() => calculator.Calc(a, b, oper));
        }
示例#4
0
        public void Multiply_6dot3multiply6dot3_39dot69Returned()
        {
            var calculator = new Calculator();
            var a          = 6.3m;
            var b          = 6.3m;
            var oper       = "*";
            var expected   = 39.69m;
            var result     = calculator.Calc(a, b, oper);

            Assert.AreEqual(expected, result);
        }
示例#5
0
        public void Minus_17dot4minus5dot5_11dot9Returned()
        {
            var     calculator = new Calculator();
            decimal a          = 17.4m;
            decimal b          = 5.5m;
            string  oper       = "-";
            decimal expected   = 11.9m;
            decimal result     = calculator.Calc(a, b, oper);

            Assert.AreEqual(expected, result);
        }
示例#6
0
        public void Plus_2plus2dot4_4dot4Returned()
        {
            var     calculator = new Calculator();
            decimal a          = 2;
            decimal b          = 2.4m;
            string  oper       = "+";
            decimal expected   = 4.4m;
            decimal result     = calculator.Calc(a, b, oper);

            Assert.AreEqual(expected, result);
        }
示例#7
0
        public void Devide_20devide5dot5_3dot6363Returned()
        {
            var     calculator = new Calculator();
            decimal a          = 20;
            decimal b          = 5.5m;
            string  oper       = "/";
            double  delta      = 0.0001;
            double  expected   = 3.6363;
            decimal result     = calculator.Calc(a, b, oper);
            double  actual     = (double)result;

            Assert.AreEqual(expected, actual, delta);
        }