mirror of
https://github.com/0xJ1M/MathsEngine.git
synced 2026-06-05 04:00:07 +00:00
* Refactor * Updated TreeNode system to use abstract base class and inheritence * Updated unit test coverage * Improved code coverage
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using MathEngine.Parser.Tokeniser;
|
|
using MathEngine.Parser.Parser;
|
|
namespace EngineTests
|
|
{
|
|
/// <summary>
|
|
/// Class for testing the ExpressionTree Class
|
|
/// </summary>
|
|
[TestClass]
|
|
public class ExpressionTreeTests
|
|
{
|
|
|
|
/// <summary>
|
|
/// Test to see if a simple expression is constructed correctly
|
|
/// </summary>
|
|
[TestMethod]
|
|
public void TestExpressionTreeSimpleExpression()
|
|
{
|
|
string testExp = "3+4";
|
|
ExpressionTree returnedTree = new(testExp);
|
|
Assert.IsTrue(returnedTree.ToString() == "7");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test to see if a simple expression is evaluated correctly
|
|
/// </summary>
|
|
[TestMethod]
|
|
public void TestExpressionTreeSimpleExpressionEvaluation()
|
|
{
|
|
string testExp = "3+4*7";
|
|
ExpressionTree returnedTree = new(testExp);
|
|
Assert.IsTrue(returnedTree.ToString() == "31");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test to see if a simple expression using all base operators (+,-,*,/) is evaluated correctly
|
|
/// </summary>
|
|
[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));
|
|
}
|
|
}
|
|
} |