Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var ep = new ExpressionProcessor();

            ep.Variables.Add('x', 3);
            Console.WriteLine($"1+2+3={ep.Calculate("1+2+3")}");
            Console.WriteLine($"1+2+xy={ep.Calculate("1+2+xy")}");
            Console.WriteLine($"10-2-x={ep.Calculate("10-2-x")}");
        }
Ejemplo n.º 2
0
        public void TestOneValue()
        {
            ep.Variables.Add('y', 7);
            var result = ep.Calculate("y");

            Assert.That(result, Is.EqualTo(7));
            result = ep.Calculate("8");
            Assert.That(result, Is.EqualTo(8));
        }
        public void Test()
        {
            var ep = new ExpressionProcessor();

            ep.Variables.Add('x', 5);
            Assert.That(ep.Calculate("1"), Is.EqualTo(1));
            Assert.That(ep.Calculate("1+2"), Is.EqualTo(3));
            Assert.That(ep.Calculate("1+x"), Is.EqualTo(6));
            Assert.That(ep.Calculate("1+xy"), Is.EqualTo(0));
        }
Ejemplo n.º 4
0
        public void Run()
        {
            //this.SimpleInterpreter();
            var processor = new ExpressionProcessor();

            processor.Variables.Add('x', 123);
            Console.WriteLine($"{"1+2+x"} {processor.Calculate("1+2+x")}");

            Console.WriteLine($"{"1+2+xx"} {processor.Calculate("1+2+xx")}");

            Console.WriteLine($"{"1+2+3+4"} {processor.Calculate("1+2+3+4")}");

            Console.WriteLine($"{"1"} {processor.Calculate("1")}");
        }
        public void Calculate_ValidInputOfNumbers_CheckResult()
        {
            var ep     = new ExpressionProcessor();
            var result = ep.Calculate("1+2+3");

            Assert.That(result, Is.EqualTo(6));
        }
        public void Calculate_InvalidInputOfNumbersAndVariables_CheckResult()
        {
            var ep = new ExpressionProcessor();

            ep.Variables['x'] = 10;
            var result = ep.Calculate("1+3+xy");

            Assert.That(result, Is.EqualTo(0));
        }
        public void Calculate_1_plus_2_plus_xy_should_be_0_cause_xy_not_legal()
        {
            // Arrange
            var target = new ExpressionProcessor();

            // Act
            var result = target.Calculate("1+2+xy");

            // Assert
            result.Should().Be(0);
        }
        public void Calculate_123_plus_456_plus_789_should_be_1368()
        {
            // Arrange
            var target = new ExpressionProcessor();

            // Act
            var result = target.Calculate("123+456+789");

            // Assert
            result.Should().Be(1368);
        }
        public void Calculate_1_plus_2_plus_3_should_be_6()
        {
            // Arrange
            var target = new ExpressionProcessor();

            // Act
            var result = target.Calculate("1+2+3");

            // Assert
            result.Should().Be(6);
        }
        public void Calculate_10_minus_2_minus_x_variable_should_be_0_when_x_not_exist_in_variables()
        {
            // Arrange
            var target = new ExpressionProcessor();

            // Act
            var result = target.Calculate("10-2-x");

            // Assert
            result.Should().Be(0);
        }
        public void Calculate_10_minus_2_minus_x_variable_should_be_5_when_x_equals_to_3()
        {
            // Arrange
            var target = new ExpressionProcessor();

            target.Variables.Add('x', 3);

            // Act
            var result = target.Calculate("10-2-x");

            // Assert
            result.Should().Be(5);
        }