Esempio n. 1
0
        public void CalculatorTests()
        {
            var    calculator = new Divider();
            double actual     = calculator.Calculate(4, 2);

            Assert.AreEqual(2, actual: actual);
        }
Esempio n. 2
0
        public void Calculate()
        {
            Divider calculator = new Divider();
            double  result     = calculator.Calculate(10, 5);

            Assert.AreEqual(2, result);
        }
Esempio n. 3
0
        public void DividerTest()
        {
            Divider calculator = new Divider();
            double  result     = calculator.Calculate(6, 3);

            Assert.AreEqual(2, result);
        }
Esempio n. 4
0
 public void CalculateTestByZero()
 {
     ITwoArgumentsCalculator calculator = new Divider();
     double result = calculator.Calculate(4, 2);
     //Assert.Throws<>(() =>
     //calculator.Calculate());
 }
Esempio n. 5
0
        public void CalculateTest()
        {
            ITwoArgumentsCalculator calculator = new Divider();
            double result = calculator.Calculate(4, 2);

            Assert.AreEqual(2, result);
        }
Esempio n. 6
0
        public void CalculateTest(
            double firstValue,
            double secondValue,
            double expected)
        {
            var calculator   = new Divider();
            var actualResult = calculator.Calculate(firstValue, secondValue);

            Assert.AreEqual(expected, actualResult);
        }
Esempio n. 7
0
        public void TestComplex()
        {
            IExpression e =
                new Divider(
                    new Multiplier(
                        new Negate(new Constant(5.0)),
                        new Divider(new Constant(9.0), new Constant(6.0))
                        ),
                    new Adder(
                        new Constant(7.0),
                        new Subtracter(new Constant(2.0), new Constant(1.5))
                        )
                    );

            Assert.AreEqual(-1, e.Calculate());
        }
Esempio n. 8
0
        public ActionResult <Adder> Post([FromBody] CalculatorRequest calculatorRequest)
        {
            CalculatorOperatorBase calculator;

            switch (calculatorRequest.CalculatorOperatorType)
            {
            case CalculatorOperatorTypeEnum.Adder:
            {
                calculator = new Adder(calculatorRequest.LeftVal, calculatorRequest.RightVal);
                break;
            }

            case CalculatorOperatorTypeEnum.Substracter:
            {
                calculator = new Substracter(calculatorRequest.LeftVal, calculatorRequest.RightVal);
                break;
            }

            case CalculatorOperatorTypeEnum.Multiplier:
            {
                calculator = new Multiplier(calculatorRequest.LeftVal, calculatorRequest.RightVal);
                break;
            }

            case CalculatorOperatorTypeEnum.Divider:
            {
                calculator = new Divider(calculatorRequest.LeftVal, calculatorRequest.RightVal);
                break;
            }

            default:
            {
                return(BadRequest("Invalid CalculatorOperatorType"));
            }
            }

            calculator.Calculate();

            var calculatorResponse = new CalculatorResponse
            {
                Result = calculator.Result
            };

            return(Ok(calculatorResponse));
        }
Esempio n. 9
0
        public void TestDivider()
        {
            IExpression e = new Divider(new Constant(5.0), new Constant(2.0));

            Assert.AreEqual(2.5, e.Calculate());
        }
Esempio n. 10
0
        public void ExceptionTest()
        {
            var calculator = new Divider();

            Assert.Throws <Exception>(() => calculator.Calculate(3, 0));
        }
Esempio n. 11
0
        public void NegativeCalculateTest()
        {
            var calculator = new Divider();

            Assert.Throws <System.Exception>(() => calculator.Calculate(2, 0));
        }
Esempio n. 12
0
        public void CalculateTestExceptionTest()
        {
            ITwoArgumentsCalculator calculator = new Divider();

            Assert.Throws <Exception>(() => calculator.Calculate(2, 0));
        }