using MathEngine.Parser.Parser;
using MathEngine.Parser.Parser.Nodes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EngineTests.Parser_Tests.Nodes
{
///
/// Class for testing the TreeNodes
///
[TestClass]
public class NumericNodeTests
{
///
/// Test two NumericNodes with same generic type can be added
/// ///
[TestMethod]
public void TestNumericNodeAdd()
{
NumericNode testNode1 = new(100);
NumericNode testNode2 = new(100);
BaseNode result = testNode1 + testNode2;
Assert.AreEqual(result.ToString(), "200");
}
///
/// Test two NumericNodes being added of different generic types raises exception
///
[TestMethod]
public void TestNumericNodeAddDifferentTypesRaisesException()
{
NumericNode testNode1 = new(100);
NumericNode testNode2 = new(100);
try
{
BaseNode result = testNode1 + testNode2;
}
catch (InvalidOperationException ex)
{
Assert.AreEqual(ex.Message, "Attempted Invalid operation");
}
}
///
/// Test two NumericNodes with same generic type can be subtracted
/// ///
[TestMethod]
public void TestNumericNodeSubtract()
{
NumericNode testNode1 = new(100);
NumericNode testNode2 = new(100);
BaseNode result = testNode1 - testNode2;
Assert.AreEqual(result.ToString(), "0");
}
///
/// Test two NumericNodes being subtracted of different generic types raises exception
///
[TestMethod]
public void TestNumericNodeSubtractDifferentTypesRaisesException()
{
NumericNode testNode1 = new(100);
NumericNode testNode2 = new(100);
try
{
BaseNode result = testNode1 - testNode2;
}
catch (InvalidOperationException ex)
{
Assert.AreEqual(ex.Message, "Attempted Invalid operation");
}
}
///
/// Test two NumericNodes with same generic type can be multiplied
///
[TestMethod]
public void TestNumericNodeMultiply()
{
NumericNode testNode1 = new(100);
NumericNode testNode2 = new(100);
BaseNode result = testNode1 * testNode2;
Assert.AreEqual(result.ToString(), "10000");
}
///
/// Test two NumericNodes being multiplied of different generic types raises exception
///
[TestMethod]
public void TestNumericNodeMultiplyDifferentTypesRaisesException()
{
NumericNode testNode1 = new(100);
NumericNode testNode2 = new(100);
try
{
BaseNode result = testNode1 * testNode2;
}
catch (InvalidOperationException ex)
{
Assert.AreEqual(ex.Message, "Attempted Invalid operation");
}
}
///
/// Test two NumericNodes with same generic type can be divided
/// ///
[TestMethod]
public void TestNumericNodeDivide()
{
NumericNode testNode1 = new(100);
NumericNode testNode2 = new(100);
BaseNode result = testNode1 / testNode2;
Assert.AreEqual(result.ToString(), "1");
}
///
/// Test two NumericNodes being divided of different generic types raises exception
///
[TestMethod]
public void TestNumericNodeDividedDifferentTypesRaisesException()
{
NumericNode testNode1 = new(100);
NumericNode testNode2 = new(100);
try
{
BaseNode result = testNode1 / testNode2;
}
catch (InvalidOperationException ex)
{
Assert.AreEqual(ex.Message, "Attempted Invalid operation");
}
}
}
}