Files
MathsEngine/MathEngine/EngineTests/AST Tests/Nodes/NumericNodeTests.cs
2025-10-14 17:59:24 +01:00

136 lines
4.2 KiB
C#

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);
}
}
}
}