コード例 #1
0
        public void CalculatorTests()
        {
            var    calculator = new Divider();
            double actual     = calculator.Calculate(4, 2);

            Assert.AreEqual(2, actual: actual);
        }
コード例 #2
0
        public void Calculate()
        {
            Divider calculator = new Divider();
            double  result     = calculator.Calculate(10, 5);

            Assert.AreEqual(2, result);
        }
コード例 #3
0
        public void DividerTest()
        {
            Divider calculator = new Divider();
            double  result     = calculator.Calculate(6, 3);

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

            Assert.AreEqual(2, result);
        }
コード例 #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);
        }
コード例 #7
0
ファイル: CompositeTest.cs プロジェクト: oliwerbig/Calculator
        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());
        }
コード例 #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));
        }
コード例 #9
0
ファイル: CompositeTest.cs プロジェクト: oliwerbig/Calculator
        public void TestDivider()
        {
            IExpression e = new Divider(new Constant(5.0), new Constant(2.0));

            Assert.AreEqual(2.5, e.Calculate());
        }
コード例 #10
0
        public void ExceptionTest()
        {
            var calculator = new Divider();

            Assert.Throws <Exception>(() => calculator.Calculate(3, 0));
        }
コード例 #11
0
        public void NegativeCalculateTest()
        {
            var calculator = new Divider();

            Assert.Throws <System.Exception>(() => calculator.Calculate(2, 0));
        }
コード例 #12
0
        public void CalculateTestExceptionTest()
        {
            ITwoArgumentsCalculator calculator = new Divider();

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