using MathEngine.Parser.Tokeniser; using MathEngine.Parser.Parser; namespace EngineTests { /// /// Class for testing the ExpressionTree Class /// [TestClass] public class ExpressionTreeTests { /// /// Test to see if a simple expression is constructed correctly /// [TestMethod] public void TestExpressionTreeSimpleExpression() { string testExp = "3+4"; ExpressionTree returnedTree = new(testExp); Assert.IsTrue(returnedTree.ToString() == "7"); } /// /// Test to see if a simple expression is evaluated correctly /// [TestMethod] public void TestExpressionTreeSimpleExpressionEvaluation() { string testExp = "3+4*7"; ExpressionTree returnedTree = new(testExp); Assert.IsTrue(returnedTree.ToString() == "31"); } /// /// Test to see if a simple expression using all base operators (+,-,*,/) is evaluated correctly /// [TestMethod] public void TestExpressionTreeSimpleExpressionAllBaseOperatorsEvaluation() { string testExp = "3+4*7-8/7"; decimal testValue = decimal.Divide(209 , 7); ExpressionTree returnedTree = new(testExp); Assert.IsTrue(returnedTree.ToString() == testValue.ToString()); } [TestMethod] public void TestExpressionTreeGetHashCodeReturnsHashCode() { string testExp = "1+1"; ExpressionTree returnedTree1 = new(testExp); int hash = returnedTree1.GetHashCode(); Assert.IsInstanceOfType(hash, typeof(int)); } } }