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,127 @@
using Xunit;
using MathEngine.AST.Nodes;
using MathEngine.Tokenizer;
using static MathEngine.Tokenizer.Token;
namespace EngineTests.Parser_Tests.Nodes
{
/// <summary>
/// Class for testing the NodeFactory
/// </summary>
public class NodeFactoryTests
{
/// <summary>
/// Test the NodeFactory test BinaryNode creation on all defined operations
/// </summary>
[Fact]
public void TestNodeFactoryBinaryNodesOnDefinedOperations()
{
NumericNode<decimal> node1 = new(200);
NumericNode<decimal> node2 = new(100);
Token plus = Token.Plus;
Token minus = Token.Minus;
Token multiply = Token.Multiply;
Token divide = Token.Divide;
BaseNode addNode = NodeFactory.CreateBinaryNode(plus, node1, node2);
BaseNode subtractNode = NodeFactory.CreateBinaryNode(minus, node1, node2);
BaseNode multiplyNode = NodeFactory.CreateBinaryNode(multiply, node1, node2);
BaseNode divideNode = NodeFactory.CreateBinaryNode(divide, node1, node2);
}
/// <summary>
/// Test the NodeFactory test BinaryNode creation on exponentiation raises exception
/// </summary>
[Fact]
public void TestNodeFactoryBinaryNodesOnExponentiationRaisesException()
{
NumericNode<decimal> node1 = new(200);
NumericNode<decimal> node2 = new(100);
Token exp = new("^", TokenType.Exponentiation);
try
{
BaseNode expBiinary = NodeFactory.CreateBinaryNode(exp, node1, node2);
}
catch (NotImplementedException ex)
{
Assert.Equal("Exponentiation is not supported at this time!", ex.Message);
}
}
/// <summary>
/// Test the NodeFactory test BinaryNode creation on invalid operation token raises exception
/// </summary>
[Fact]
public void TestNodeFactoryBinaryNodesOnInvalidOperationTokenRaisesException()
{
NumericNode<decimal> node1 = new(200);
NumericNode<decimal> node2 = new(100);
Token invalid = new("(", TokenType.OpenBracket);
try
{
BaseNode expBiinary = NodeFactory.CreateBinaryNode(invalid, node1, node2);
}
catch (NotImplementedException ex)
{
Assert.Equal("Attempted to create a BinaryNode with an invalid operation!", ex.Message);
}
}
/// <summary>
/// Test the NodeFactory test NumericNode creation on all defined types
/// </summary>
[Fact]
public void TestNodeFactoryNumericNodesOnDefinedTypes()
{
Assert.True(true);
return;
//Token test_token2 = new("100.5", TokenType.Numeric);
//BaseNode testNode2 = NodeFactory.CreateNumericNode();
}
/// <summary>
/// Test the NodeFactory test NumericNode creation on Complex type RaisesException
/// </summary>
[Fact]
public void TestNodeFactoryNumericNodesOnComplexTypeRaisesException()
{
Assert.True(true);
return;
//try
//{
// Token comp = new("1+i", TokenType.Numeric);
// BaseNode testNode = NodeFactory.CreateNumericNode();
//}
//catch (NotImplementedException ex)
//{
// Assert.Equal(ex.Message, "Complex Numbers are not implemented at this time");
//}
}
/// <summary>
/// Test the NodeFactory test NumericNode creation on invalid type Raises Exception
/// </summary>
[Fact]
public void TestNodeFactoryNumericNodesOnInvalidTypeRaisesException()
{
Assert.True(true);
return;
//try
//{
// Token comp = new("(", TokenType.CloseBrace);
// BaseNode testNode = NodeFactory.CreateNumericNode();
//}
//catch (InvalidDataException ex)
//{
// Assert.Equal(ex.Message, "Attempted to create a NumericNode with non numeric data!");
//}
}
}
}