public void Analyze_NumberSymbol_ReturnsIdentifierNode() { SyntaxNode node = new IdentifierNode("x"); Environment environment = new Environment(); environment.AddValue("x", 2); node = SemanticAnalyzer.Analyze(node, environment); Assert.AreEqual("x", node.ToString()); }
public void GetVariable_Number_ReturnsEnvironmentVariable() { Environment environment = new Environment(); environment.AddValue("x", 1); EnvironmentVariable variable = environment.Get("x"); Assert.AreEqual(EnvironmentVariableType.Number, variable.Type); Assert.AreEqual(1, variable.Value); }
public void AddValue_AlreadyDefinedSymbol_ThrowsException() { Environment environment = new Environment(); environment.AddValue("x", 2); DefinedSymbolException exception = Assert.Throws <DefinedSymbolException>(() => { environment.AddSymbol("x"); }); Assert.AreEqual("Symbol x has already been defined", exception.Message); }
public void Analyze_AmbigiousValueDistribution_ReturnsOperatorNode() { IdentifierNode left = new IdentifierNode("x"); SyntaxNode right = new NumberNode(1); SyntaxNode root = new FunctionOrDistributionNode(left, right); Environment environment = new Environment(); environment.AddValue("x", 2); root = SemanticAnalyzer.Analyze(root, environment); Assert.AreEqual("x * 1", root.ToString()); }