Files
MathsEngine/MathEngine/EngineTests/Parser Tests/Nodes/NumericNodeTests.cs
0xJ1M 461a60ff77 Bugfix/improve code coverage (#4)
* Improved coverage

* Finished
2023-09-11 21:48:27 +01:00

141 lines
4.4 KiB
C#

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");
}
}
}
}