mirror of
https://github.com/0xJ1M/MathsEngine.git
synced 2026-06-05 02:20:07 +00:00
Major refactor
This commit is contained in:
12
MathEngine/EngineTests/AST Tests/Nodes/BaseNodeTests.cs
Normal file
12
MathEngine/EngineTests/AST Tests/Nodes/BaseNodeTests.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EngineTests.Parser_Tests.Nodes
|
||||
{
|
||||
internal class BaseNodeTests
|
||||
{
|
||||
}
|
||||
}
|
||||
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!");
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
135
MathEngine/EngineTests/AST Tests/Nodes/NumericNodeTests.cs
Normal file
135
MathEngine/EngineTests/AST Tests/Nodes/NumericNodeTests.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user