public void GetVariable_Function_ReturnsEnvironmentVariable() { Environment environment = new Environment(); environment.AddFunction("x", null); EnvironmentVariable variable = environment.Get("x"); Assert.AreEqual(EnvironmentVariableType.Function, variable.Type); }
public void AddFunction_AlreadyDefinedSymbol_ThrowsException() { Environment environment = new Environment(); DefinedSymbolException exception = Assert.Throws <DefinedSymbolException>(() => { environment.AddFunction("sin", null); }); Assert.AreEqual("Symbol sin has already been defined", exception.Message); }
public void Simplify_OperatorWithNumberAndFunction_ReturnsOperatorNode() { Environment environment = new Environment(); environment.AddSymbol("x"); environment.AddFunction("f", GetExpression("x", environment)); SyntaxNode node = GetExpression("2 + f(x)", environment); node = OperatorSimplification.Simplify((OperatorNode)node, environment); Assert.NotNull(node); Assert.AreEqual("2 + f(x)", node.ToString()); }
public void Analyze_AmbigiousFunction_ReturnsFunctionNode() { IdentifierNode left = new IdentifierNode("x"); SyntaxNode right = new NumberNode(1); SyntaxNode root = new FunctionOrDistributionNode(left, right); Environment environment = new Environment(); environment.AddFunction("x", null); root = SemanticAnalyzer.Analyze(root, environment); Assert.AreEqual("x(1)", root.ToString()); }