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