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

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,7 +7,6 @@ namespace MathEngine.Types.Interfaces
/// </summary> /// </summary>
internal interface INumeric<T> where T : struct, INumeric<T> internal interface INumeric<T> where T : struct, INumeric<T>
{ {
T Value { get; }
/// <summary> /// <summary>
/// Adds this numeric value to another /// 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>. /// <c>true</c> if this value is not equal to <paramref name="other"/>; otherwise, <c>false</c>.
/// </returns> /// </returns>
bool NotEqual(T other); 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> /// <returns>True if this &lt; other, False otherwise</returns>
bool LessThan(T other); bool LessThan(T other);
/// <summary> /// <summary>
/// Determines whether this value is less than or equal to the specified other value. /// Determines whether this value is less than or equal to the specified other value.
/// </summary> /// </summary>

File diff suppressed because one or more lines are too long