Esempio n. 1
0
        public void TestStackCalculatorException()
        {
            Calculator calculator = new StackCalculator();

            Assert.AreEqual(6.2, calculator.Calculate("23 -29.3 - 12.5"));
            Assert.AreEqual(6.2, calculator.Calculate("23 -( 29.3 - * 12.5 )"));
            Assert.AreEqual(6.2, calculator.Calculate("1 +s)"));
            Assert.AreEqual(2546.2, calculator.Calculate("( 100 / 500 + 20 ) + 150 * 23 - ( ( ( ( 29.3 - 12.5 ) * ( 22 + 33 ) ) ) ) ) )"));
        }
Esempio n. 2
0
        public void StackCalculatorTest()
        {
            StackCalculator c   = new StackCalculator();
            int             res = c.Calculate("1 3 + 6 2 * 7 + *");

            Assert.AreEqual(76, res);

            res = c.Calculate("5 9 8 + 4 6 * * 7 + *");
            Assert.AreEqual(2075, res);

            res = c.Calculate("500 10 *");
            Assert.AreEqual(5000, res);
        }
Esempio n. 3
0
        public void Calculate_12p5_minus_2_10p5returned()
        {
            double expected   = 10.5;
            string expression = "12.5 2 -";

            double actual = StackCalculator.Calculate(expression);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 4
0
        public void Calculate_12p5_multiply_2_25returned()
        {
            double expected   = 25;
            string expression = "12.5 2 *";

            double actual = StackCalculator.Calculate(expression);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 5
0
        public void Calculate_12p5_divide_2_6p25returned()
        {
            double expected   = 6.25;
            string expression = "12.5 2 /";

            double actual = StackCalculator.Calculate(expression);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 6
0
        public void Calculate_6_10_plus_4_minus_1_1_2_multiply_plus_divide_1_plus_5returned()
        {
            double expected   = 5;
            string expression = "6 10 + 4 - 1 1 2 * + / 1 +";

            double actual = StackCalculator.Calculate(expression);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 7
0
            public static async Task <IActionResult> Run(
                [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
                ILogger log)
            {
                var lines = new List <string>();

                using (var reader = new StreamReader(req.Body))
                {
                    while (!reader.EndOfStream)
                    {
                        var line = await reader.ReadLineAsync();

                        Console.WriteLine(line);
                        lines.Add(line);
                    }
                }

                var calculator = new StackCalculator();
                var response   = calculator.Calculate(lines.ToArray());

                return(new OkObjectResult(response));
            }
 public void DivisionByZero()
 {
     calculator = new StackCalculator("2 / 0", new Stack());
     double result = calculator.Calculate();
     Assert.AreEqual(-1, result, delta);
 }
 public void ErrorInput()
 {
     calculator = new StackCalculator("2 + 7 * 1", new Stack());
     double result = calculator.Calculate();
     Assert.AreEqual(-1, result, delta);
 }
 public void Sum_2Plus5_7Returned()
 {
     calculator = new StackCalculator("2 5 +", new Stack());
     double result = calculator.Calculate();
     Assert.AreEqual(7, result, delta);
 }
 public void ExpressionWithTwoOperations()
 {
     calculator = new StackCalculator("2 5 + 7 *", new Stack());
     double result = calculator.Calculate();
     Assert.AreEqual(49, result, delta);
 }
Esempio n. 12
0
 public void DivideByZeroTest(IStack stack)
 {
     Assert.AreEqual((false, 0), StackCalculator.Calculate("9 0 / 5 3 +", stack));
 }
Esempio n. 13
0
 public void EmptyStringTest(IStack stack)
 {
     Assert.AreEqual((false, 0), StackCalculator.Calculate("", stack));
 }
Esempio n. 14
0
 public void NotEnoughOperationTest(IStack stack)
 {
     Assert.AreEqual((false, 0), StackCalculator.Calculate("4 5 + 3 2 *", stack));
 }
Esempio n. 15
0
 public void OneOperandBeforeOperationTest(IStack stack)
 {
     Assert.AreEqual((false, 0), StackCalculator.Calculate("3 - 2", stack));
 }
Esempio n. 16
0
 public void StackShouldBeEmpty3Test(IStack stack)
 {
     StackCalculator.Calculate("9 6", stack);
     Assert.IsTrue(stack.IsEmpty());
 }
Esempio n. 17
0
 public void WithInvalidSymbolsTest(IStack stack)
 {
     Assert.AreEqual((false, 0), StackCalculator.Calculate("1 3 * a -", stack));
 }
Esempio n. 18
0
        public void TestStackCalculator()
        {
            Calculator calculator = new StackCalculator();

            //for (var i = 0; i < 100000; i++)
            //{
            Assert.AreEqual(200.55, calculator.Calculate("200.55"));
            Assert.AreEqual(2, calculator.Calculate("1 + 1"));
            Assert.AreEqual(4, calculator.Calculate("2 * 2"));
            Assert.AreEqual(6, calculator.Calculate("1 + 2 + 3"));
            Assert.AreEqual(3, calculator.Calculate("6 / 2"));
            Assert.AreEqual(34, calculator.Calculate("11 + 23"));
            Assert.AreEqual(34.1, calculator.Calculate("11.1 + 23"));
            Assert.AreEqual(37, calculator.Calculate("( 11.5 + 15.4 ) + 10.1"));
            Assert.AreEqual(6.2, calculator.Calculate("23 - ( 29.3 - 12.5 )"));
            Assert.AreEqual(4020, calculator.Calculate("( 1 + 1 ) * 100.5 * 20"));
            Assert.AreEqual(5, calculator.Calculate("2 * 2 + 4 / 4"));
            Assert.AreEqual(2526, calculator.Calculate("150 * 23 - ( ( 29.3 - 12.5 ) * ( 22 + 33 ) )"));
            Assert.AreEqual(2546.2, calculator.Calculate("( 100 / 500 + 20 ) + 150 * 23 - ( ( ( ( 29.3 - 12.5 ) * ( 22 + 33 ) ) ) )"));
            //}
        }
Esempio n. 19
0
 public void CalculateCorrectExpression2Test(IStack stack)
 {
     Assert.AreEqual((true, 110), StackCalculator.Calculate("26 42 2 * +", stack));
 }
Esempio n. 20
0
 public void CalculateCorrectExpression1Test(IStack stack)
 {
     Assert.AreEqual((true, 3), StackCalculator.Calculate("96 6 - 17 13 + /", stack));
 }