using Xunit;
using MathEngine.AST.Nodes;
using MathEngine.Tokenizer;
using static MathEngine.Tokenizer.Token;
using MathEngine.Types;
namespace EngineTests.Parser_Tests.Nodes
{
///
/// Class for testing the NodeFactory
///
public class NodeFactoryTests
{
///
/// Test the NodeFactory test BinaryNode creation on all defined operations
///
[Fact]
public void TestNodeFactoryBinaryNodesOnDefinedOperations()
{
NumericNode node1 = new(new DecimalValue(200));
NumericNode node2 = new(new DecimalValue(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);
}
///
/// Test the NodeFactory test BinaryNode creation on exponentiation raises exception
///
[Fact]
public void TestNodeFactoryBinaryNodesOnExponentiationRaisesException()
{
NumericNode node1 = new(200);
NumericNode 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);
}
}
///
/// Test the NodeFactory test BinaryNode creation on invalid operation token raises exception
///
[Fact]
public void TestNodeFactoryBinaryNodesOnInvalidOperationTokenRaisesException()
{
NumericNode node1 = new(200);
NumericNode 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);
}
}
///
/// Test the NodeFactory test NumericNode creation on all defined types
///
[Fact]
public void TestNodeFactoryNumericNodesOnDefinedTypes()
{
Assert.True(true);
return;
//Token test_token2 = new("100.5", TokenType.Numeric);
//BaseNode testNode2 = NodeFactory.CreateNumericNode();
}
///
/// Test the NodeFactory test NumericNode creation on Complex type RaisesException
///
[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");
//}
}
///
/// Test the NodeFactory test NumericNode creation on invalid type Raises Exception
///
[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!");
//}
}
}
}