Пример #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Enter expression: ");
            var expression = Console.ReadLine();

            IExpressionValidator validator = new ExpressionValidator();
            var validationResult           = validator.Validate(expression);

            if (validationResult != null)
            {
                Console.WriteLine(validationResult);
                Console.ReadKey();
                return;
            }

            IExpressionCorrector corrector = new ExpressionCorrector();

            expression = corrector.Correct(expression);

            ICalculator calculator = new Calculator(new Parser(), new OperationPerformer());
            var         result     = calculator.Compute(expression);

            Console.WriteLine($"Result: {result}");
            Console.ReadKey();
        }
Пример #2
0
        public void UnitTestWithAllOperatorsReturns45_0()
        {
            // arrange
            var expression = "42+5.2-2*5.5/5";

            var corrector = new CalculatorProject.ExpressionCorrector();

            expression = corrector.Correct(expression);

            var calculator = new CalculatorProject.Calculator(
                new Parser(),
                new OperationPerformer());

            // act
            var actualResult = calculator.Compute(expression);

            // assert
            Assert.AreEqual(45.0, actualResult);
        }
Пример #3
0
        public void UnitTestWithBracketsReturnsMin1_4()
        {
            // arrange
            var expression = "8.4+(6-7.8)-(9*(7-6)-1)";

            var corrector = new CalculatorProject.ExpressionCorrector();

            expression = corrector.Correct(expression);

            var calculator = new CalculatorProject.Calculator(
                new Parser(),
                new OperationPerformer());

            // act
            var actualResult = calculator.Compute(expression);

            // assert
            Assert.AreEqual(-1.4, actualResult);
        }