This commit is contained in:
Jim
2025-11-06 20:48:05 +00:00
parent 16c27a0070
commit 89d41e512f
10 changed files with 64 additions and 46 deletions

View File

@@ -19,8 +19,8 @@ namespace EngineTests.Parser_Tests.Nodes
[Fact]
public void TestNodeFactoryBinaryNodesOnDefinedOperations()
{
NumericNode node1 = new(new DecimalValue(200));
NumericNode node2 = new(new DecimalValue(100));
NumericNode<DecimalValue> node1 = new(new DecimalValue(200));
NumericNode<DecimalValue> node2 = new(new DecimalValue(100));
Token plus = Token.Plus;
Token minus = Token.Minus;
@@ -39,8 +39,8 @@ namespace EngineTests.Parser_Tests.Nodes
[Fact]
public void TestNodeFactoryBinaryNodesOnExponentiationRaisesException()
{
NumericNode<decimal> node1 = new(200);
NumericNode<decimal> node2 = new(100);
NumericNode<DecimalValue> node1 = new(new DecimalValue(200));
NumericNode<DecimalValue> node2 = new(new DecimalValue(100));
Token exp = new("^", TokenType.Exponentiation);
try
@@ -59,8 +59,8 @@ namespace EngineTests.Parser_Tests.Nodes
[Fact]
public void TestNodeFactoryBinaryNodesOnInvalidOperationTokenRaisesException()
{
NumericNode<decimal> node1 = new(200);
NumericNode<decimal> node2 = new(100);
NumericNode<DecimalValue> node1 = new(new DecimalValue(200));
NumericNode<DecimalValue> node2 = new(new DecimalValue(100));
Token invalid = new("(", TokenType.OpenBracket);
try

View File

@@ -1,6 +1,7 @@
using Xunit;
using MathEngine.AST.Nodes;
using MathEngine.Types;
namespace EngineTests.Parser_Tests.Nodes
{
@@ -15,8 +16,8 @@ namespace EngineTests.Parser_Tests.Nodes
[Fact]
public void TestNumericNodeAdd()
{
NumericNode<decimal> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
NumericNode<DecimalValue> testNode1 = new(new DecimalValue(100));
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(100));
BaseNode result = testNode1 + testNode2;
Assert.Equal("200", result.ToString());
}
@@ -27,8 +28,8 @@ namespace EngineTests.Parser_Tests.Nodes
[Fact]
public void TestNumericNodeAddDifferentTypesRaisesException()
{
NumericNode<int> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
NumericNode<DecimalValue> testNode1 = new(new DecimalValue(100));
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(100));
try
{
BaseNode result = testNode1 + testNode2;
@@ -46,8 +47,8 @@ namespace EngineTests.Parser_Tests.Nodes
[Fact]
public void TestNumericNodeSubtract()
{
NumericNode<decimal> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
NumericNode<DecimalValue> testNode1 = new(new DecimalValue(100));
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(100));
BaseNode result = testNode1 - testNode2;
Assert.Equal("0", result.ToString());
}
@@ -58,8 +59,8 @@ namespace EngineTests.Parser_Tests.Nodes
[Fact]
public void TestNumericNodeSubtractDifferentTypesRaisesException()
{
NumericNode<int> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
NumericNode<DecimalValue> testNode1 = new(new DecimalValue(100));
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(100));
try
{
BaseNode result = testNode1 - testNode2;
@@ -77,8 +78,8 @@ namespace EngineTests.Parser_Tests.Nodes
[Fact]
public void TestNumericNodeMultiply()
{
NumericNode<decimal> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
NumericNode<DecimalValue> testNode1 = new(new DecimalValue(100));
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(100));
BaseNode result = testNode1 * testNode2;
Assert.Equal("10000", result.ToString());
}
@@ -89,8 +90,8 @@ namespace EngineTests.Parser_Tests.Nodes
[Fact]
public void TestNumericNodeMultiplyDifferentTypesRaisesException()
{
NumericNode<int> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
NumericNode<DecimalValue> testNode1 = new(new DecimalValue(100));
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(100));
try
{
BaseNode result = testNode1 * testNode2;
@@ -108,8 +109,8 @@ namespace EngineTests.Parser_Tests.Nodes
[Fact]
public void TestNumericNodeDivide()
{
NumericNode<decimal> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
NumericNode<DecimalValue> testNode1 = new(new DecimalValue(100));
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(100));
BaseNode result = testNode1 / testNode2;
Assert.Equal("1", result.ToString());
}
@@ -120,8 +121,8 @@ namespace EngineTests.Parser_Tests.Nodes
[Fact]
public void TestNumericNodeDividedDifferentTypesRaisesException()
{
NumericNode<int> testNode1 = new(100);
NumericNode<decimal> testNode2 = new(100);
NumericNode<DecimalValue> testNode1 = new(new DecimalValue(100));
NumericNode<DecimalValue> testNode2 = new(new DecimalValue(100));
try
{
BaseNode result = testNode1 / testNode2;

View File

@@ -0,0 +1,20 @@
using Xunit;
using MathEngine.Types;
namespace EngineTests.Types
{
public class DecimalValueTests
{
/// <summary>
/// Test that an ArgumentException is raised if zero is given for SegmentSize
/// </summary>
[Fact]
public void ConstructorReturnsValidDecimalValueInstance()
{
decimal expected = 123;
var value1 = new DecimalValue(123);
}
}
}

View File

@@ -1,4 +1,6 @@
namespace MathEngine.AST.Nodes
using Newtonsoft.Json.Linq;
namespace MathEngine.AST.Nodes
{
/// <summary>
/// Abstract class representing a Node in a Tree structure

View File

@@ -1,4 +1,5 @@
using MathEngine.Types.Interfaces;
using Newtonsoft.Json.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -111,5 +112,10 @@ namespace MathEngine.AST.Nodes
return new NumericNode<T>(trig.Tan());
throw new NotImplementedException();
}
public override string ToString()
{
return _value.ToString();
}
}
}

View File

@@ -5,6 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>

View File

@@ -1,4 +1,5 @@
using MathEngine.Types.Interfaces;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
namespace MathEngine.Types
@@ -55,7 +56,6 @@ namespace MathEngine.Types
1.0m,
-2.646821446601517372109605e-37m};
/// <summary>
/// Pre-computed Chebyshev coefficients for a degree 30 Cosine approximation
/// </summary>
@@ -93,8 +93,6 @@ namespace MathEngine.Types
};
public Type UnderlyingType => throw new NotImplementedException();
public DecimalValue Value => throw new NotImplementedException();
public DecimalValue(decimal value)
@@ -102,12 +100,6 @@ namespace MathEngine.Types
_value = value;
}
public DecimalValue(string value)
{
_value = decimal.Parse(value);
}
/// <summary>
/// Performs radian angle range reduction into the range -Pi/2 &lt;= x &lt;= Pi/2
/// </summary>
@@ -336,11 +328,6 @@ namespace MathEngine.Types
return mys._value == _value;
}
public override string ToString()
{
return "DecimalValue: " + _value.ToString();
}
public DecimalValue Sin()
{
decimal reduced_x = DecimalValue.RangeReduction(_value);
@@ -369,5 +356,10 @@ namespace MathEngine.Types
{
return this.LessThanOrEqual(other) ? this : other;
}
public override string ToString()
{
return _value.ToString();
}
}
}

View File

@@ -7,7 +7,6 @@ namespace MathEngine.Types.Interfaces
/// </summary>
internal interface INumeric<T> where T : struct, INumeric<T>
{
T Value { get; }
/// <summary>
/// Adds this numeric value to another
@@ -70,10 +69,5 @@ namespace MathEngine.Types.Interfaces
/// <c>true</c> if this value is not equal to <paramref name="other"/>; otherwise, <c>false</c>.
/// </returns>
bool NotEqual(T other);
/// <summary>
/// Returns the <see cref="Type"/> of the <see cref="INumeric"/> instance
/// </summary>
Type UnderlyingType { get; }
}
}

View File

@@ -28,7 +28,6 @@ namespace MathEngine.Types.Interfaces
/// <returns>True if this &lt; other, False otherwise</returns>
bool LessThan(T other);
/// <summary>
/// Determines whether this value is less than or equal to the specified other value.
/// </summary>

File diff suppressed because one or more lines are too long