mirror of
https://github.com/0xJ1M/MathsEngine.git
synced 2026-06-05 01:10:08 +00:00
137 lines
4.6 KiB
C#
137 lines
4.6 KiB
C#
using Xunit;
|
|
|
|
using MathEngine.AST.Nodes;
|
|
using MathEngine.Types;
|
|
|
|
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<DecimalValue> testNode1 = new(new DecimalValue(100));
|
|
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(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<DecimalValue> testNode1 = new(new DecimalValue(100));
|
|
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(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<DecimalValue> testNode1 = new(new DecimalValue(100));
|
|
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(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<DecimalValue> testNode1 = new(new DecimalValue(100));
|
|
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(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<DecimalValue> testNode1 = new(new DecimalValue(100));
|
|
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(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<DecimalValue> testNode1 = new(new DecimalValue(100));
|
|
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(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<DecimalValue> testNode1 = new(new DecimalValue(100));
|
|
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(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<DecimalValue> testNode1 = new(new DecimalValue(100));
|
|
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(100));
|
|
try
|
|
{
|
|
BaseNode result = testNode1 / testNode2;
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
Assert.Equal("Attempted Invalid operation", ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|