mirror of
https://github.com/0xJ1M/MathsEngine.git
synced 2026-06-05 04:30:07 +00:00
140
MathEngine/EngineTests/Parser Tests/Nodes/NumericNodeTests.cs
Normal file
140
MathEngine/EngineTests/Parser Tests/Nodes/NumericNodeTests.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Class for testing the TreeNodes
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class NumericNodeTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Test two NumericNodes with same generic type can be added
|
||||
/// /// </summary>
|
||||
[TestMethod]
|
||||
public void TestNumericNodeAdd()
|
||||
{
|
||||
NumericNode<decimal> testNode1 = new(100);
|
||||
NumericNode<decimal> testNode2 = new(100);
|
||||
BaseNode result = testNode1 + testNode2;
|
||||
Assert.AreEqual(result.ToString(), "200");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test two NumericNodes being added of different generic types raises exception
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestNumericNodeAddDifferentTypesRaisesException()
|
||||
{
|
||||
NumericNode<int> testNode1 = new(100);
|
||||
NumericNode<decimal> testNode2 = new(100);
|
||||
try
|
||||
{
|
||||
BaseNode result = testNode1 + testNode2;
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
Assert.AreEqual(ex.Message, "Attempted Invalid operation");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test two NumericNodes with same generic type can be subtracted
|
||||
/// /// </summary>
|
||||
[TestMethod]
|
||||
public void TestNumericNodeSubtract()
|
||||
{
|
||||
NumericNode<decimal> testNode1 = new(100);
|
||||
NumericNode<decimal> testNode2 = new(100);
|
||||
BaseNode result = testNode1 - testNode2;
|
||||
Assert.AreEqual(result.ToString(), "0");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test two NumericNodes being subtracted of different generic types raises exception
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestNumericNodeSubtractDifferentTypesRaisesException()
|
||||
{
|
||||
NumericNode<int> testNode1 = new(100);
|
||||
NumericNode<decimal> testNode2 = new(100);
|
||||
try
|
||||
{
|
||||
BaseNode result = testNode1 - testNode2;
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
Assert.AreEqual(ex.Message, "Attempted Invalid operation");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test two NumericNodes with same generic type can be multiplied
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestNumericNodeMultiply()
|
||||
{
|
||||
NumericNode<decimal> testNode1 = new(100);
|
||||
NumericNode<decimal> testNode2 = new(100);
|
||||
BaseNode result = testNode1 * testNode2;
|
||||
Assert.AreEqual(result.ToString(), "10000");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test two NumericNodes being multiplied of different generic types raises exception
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestNumericNodeMultiplyDifferentTypesRaisesException()
|
||||
{
|
||||
NumericNode<int> testNode1 = new(100);
|
||||
NumericNode<decimal> testNode2 = new(100);
|
||||
try
|
||||
{
|
||||
BaseNode result = testNode1 * testNode2;
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
Assert.AreEqual(ex.Message, "Attempted Invalid operation");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test two NumericNodes with same generic type can be divided
|
||||
/// /// </summary>
|
||||
[TestMethod]
|
||||
public void TestNumericNodeDivide()
|
||||
{
|
||||
NumericNode<decimal> testNode1 = new(100);
|
||||
NumericNode<decimal> testNode2 = new(100);
|
||||
BaseNode result = testNode1 / testNode2;
|
||||
Assert.AreEqual(result.ToString(), "1");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test two NumericNodes being divided of different generic types raises exception
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestNumericNodeDividedDifferentTypesRaisesException()
|
||||
{
|
||||
NumericNode<int> testNode1 = new(100);
|
||||
NumericNode<decimal> testNode2 = new(100);
|
||||
try
|
||||
{
|
||||
BaseNode result = testNode1 / testNode2;
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
Assert.AreEqual(ex.Message, "Attempted Invalid operation");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user