private IEnumerable<ResponseMessage> CalculateHandler(IncomingMessage message, string matchedHandle) { string response = string.Empty; if (matchedHandle != null) { string expression = message.FullText.Substring(matchedHandle.Length).Trim(); Parser parser = new Parser(); try { IExpression parsedExpression = parser.Parse(expression); object result = parsedExpression.Calculate(); response = $"{parsedExpression} = {result}"; } catch (Exception e) { bool showErrors = !string.IsNullOrEmpty(matchedHandle); if (showErrors) { _statsPlugin.IncrementState("Calc:Failed"); response = $"Who taught you maths? {e.Message}"; } } } if (!string.IsNullOrEmpty(response)) { _statsPlugin.IncrementState("Calc:Calced"); yield return message.ReplyToChannel($"@{message.Username}: {response}"); } }
public void TestInit() { parser = new Parser(); }
public TruthTablePresenter() { parser = new Parser(); }
public void TestInit() { lexer = new MathLexerMock(); var simplifier = new Simplifier(); parser = new Parser(lexer, simplifier, new ExpressionFactory()); }
public void SaveLastExpFalseTest() { var parser = new Parser() { SaveLastExpression = false }; var e1 = parser.Parse("e"); var e2 = parser.Parse("e"); Assert.AreNotSame(e1, e2); }
public MathParserTest() { parser = new Parser(); }