Major refactor

This commit is contained in:
Jim
2025-07-10 20:02:32 +01:00
committed by 0xJ1M
parent fb81730adb
commit c527e59b57
37 changed files with 1252 additions and 1493 deletions

View File

@@ -0,0 +1,135 @@
using Xunit;
using MathEngine.AST.Nodes;
namespace EngineTests.Parser_Tests.Nodes
{
/// <summary>
/// Class for testing the TreeNodes
/// </summary>
public class NumericNodeTests
{
/// <summary>
/// Test two NumericNodes with same generic type can be added
/// /// </summary>
[Fact]
public void TestNumericNodeAdd()
{
NumericNode<decimal> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
BaseNode result = testNode1 + testNode2;
Assert.Equal("200", result.ToString());
}
/// <summary>
/// Test two NumericNodes being added of different generic types raises exception
/// </summary>
[Fact]
public void TestNumericNodeAddDifferentTypesRaisesException()
{
NumericNode<int> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
try
{
BaseNode result = testNode1 + testNode2;
}
catch (InvalidOperationException ex)
{
Assert.Equal("Attempted Invalid operation", ex.Message);
}
}
/// <summary>
/// Test two NumericNodes with same generic type can be subtracted
/// /// </summary>
[Fact]
public void TestNumericNodeSubtract()
{
NumericNode<decimal> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
BaseNode result = testNode1 - testNode2;
Assert.Equal("0", result.ToString());
}
/// <summary>
/// Test two NumericNodes being subtracted of different generic types raises exception
/// </summary>
[Fact]
public void TestNumericNodeSubtractDifferentTypesRaisesException()
{
NumericNode<int> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
try
{
BaseNode result = testNode1 - testNode2;
}
catch (InvalidOperationException ex)
{
Assert.Equal("Attempted Invalid operation", ex.Message);
}
}
/// <summary>
/// Test two NumericNodes with same generic type can be multiplied
/// </summary>
[Fact]
public void TestNumericNodeMultiply()
{
NumericNode<decimal> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
BaseNode result = testNode1 * testNode2;
Assert.Equal("10000", result.ToString());
}
/// <summary>
/// Test two NumericNodes being multiplied of different generic types raises exception
/// </summary>
[Fact]
public void TestNumericNodeMultiplyDifferentTypesRaisesException()
{
NumericNode<int> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
try
{
BaseNode result = testNode1 * testNode2;
}
catch (InvalidOperationException ex)
{
Assert.Equal("Attempted Invalid operation", ex.Message);
}
}
/// <summary>
/// Test two NumericNodes with same generic type can be divided
/// /// </summary>
[Fact]
public void TestNumericNodeDivide()
{
NumericNode<decimal> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
BaseNode result = testNode1 / testNode2;
Assert.Equal("1", result.ToString());
}
/// <summary>
/// Test two NumericNodes being divided of different generic types raises exception
/// </summary>
[Fact]
public void TestNumericNodeDividedDifferentTypesRaisesException()
{
NumericNode<int> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
try
{
BaseNode result = testNode1 / testNode2;
}
catch (InvalidOperationException ex)
{
Assert.Equal("Attempted Invalid operation", ex.Message);
}
}
}
}