mirror of
https://github.com/0xJ1M/MathsEngine.git
synced 2026-06-05 00:10:08 +00:00
WIP
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
20
MathEngine/EngineTests/Types/DecimalValueTests.cs
Normal file
20
MathEngine/EngineTests/Types/DecimalValueTests.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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 <= x <= Pi/2
|
/// Performs radian angle range reduction into the range -Pi/2 <= x <= 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ namespace MathEngine.Types.Interfaces
|
|||||||
/// <returns>True if this < other, False otherwise</returns>
|
/// <returns>True if this < 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
Reference in New Issue
Block a user