예제 #1
0
        public MainPageViewModel()
        {
            Equation = "";

            RPNConverter.ClearAll();
            AddCharacterCommand = new RelayCommand<object>(x =>
            {
                Equation += x as string;
                RPNConverter.AddToInputList(x as string);
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Equation)));
            });

            RemoveCharacterCommand = new RelayCommand(() =>
            {
                RemoveCharacterFromEquation();
                RPNConverter.RemoveFromInputList();
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Equation)));
            });

            ClearAllCommand = new RelayCommand(() =>
            {
                Equation = "";
                RPNConverter.ClearAll();
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Equation)));
            });
        }
예제 #2
0
 internal double Calculate()
 {
     LexicalAnalyzer = new LexicalAnalyzer(Input);
     RPNConverter    = new RPNConverter(LexicalAnalyzer.Analyse());
     RPNComputer     = new RPNComputer(RPNConverter.Convert());
     return(RPNComputer.Compute());
 }
예제 #3
0
        protected static void Succeeds(IList <Element> input, IList <Element> expected)
        {
            var rpnConverter = new RPNConverter();

            rpnConverter.Convert(new List <Element>(input));

            var output = rpnConverter.Rpn;

            Assert.Equal(output.Count, expected.Count);

            for (var i = 0; i < output.Count; ++i)
            {
                Assert.Equal(output[i], expected[i]);
            }
        }
예제 #4
0
 private string GetResoult()
 {
     if (!RPNConverter.input.Any())
     {
         return("Input can't be empty!");
     }
     else if (RPNConverter.input.Count(x => x == "(") != RPNConverter.input.Count(x => x == ")"))
     {
         return("Each open parenthesis must be closed!");
     }
     else
     {
         return(RPNConverter.NormalToRPN());
     }
 }
예제 #5
0
        protected static void Fails(IList <Element> input)
        {
            var rpnConverter = new RPNConverter();

            Assert.Throws <ParserException>(() => { rpnConverter.Convert(new List <Element>(input)); });
        }
예제 #6
0
        public IActionResult Calculate([FromBody] Post post)
        {
            string tokens = RPNConverter.infixToRPN(post.Data.Split(" "));

            return(Json(new { tokens = tokens, result = RPNEvaluator.CalculateRPN(tokens) }));
        }