mirror of
https://github.com/0xJ1M/MathsEngine.git
synced 2026-06-05 01:10:08 +00:00
Major refactor
This commit is contained in:
127
MathEngine/EngineTests/AST Tests/Nodes/NodeFactoryTests.cs
Normal file
127
MathEngine/EngineTests/AST Tests/Nodes/NodeFactoryTests.cs
Normal 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!");
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user