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))); }); }
internal double Calculate() { LexicalAnalyzer = new LexicalAnalyzer(Input); RPNConverter = new RPNConverter(LexicalAnalyzer.Analyse()); RPNComputer = new RPNComputer(RPNConverter.Convert()); return(RPNComputer.Compute()); }
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]); } }
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()); } }
protected static void Fails(IList <Element> input) { var rpnConverter = new RPNConverter(); Assert.Throws <ParserException>(() => { rpnConverter.Convert(new List <Element>(input)); }); }
public IActionResult Calculate([FromBody] Post post) { string tokens = RPNConverter.infixToRPN(post.Data.Split(" ")); return(Json(new { tokens = tokens, result = RPNEvaluator.CalculateRPN(tokens) })); }