Files
Misaki.HighPerformance/Misaki.HighPerformance.Test/UnitTest/Mathematics/TestDouble2.cs
Misaki a2a760594e Enhance mathematical capabilities and job system
Added new numeric types for unsigned integers, including uint2, uint3, and uint4, along with their matrix types.
Added a new `quaternion` struct with constructors and methods for creating and manipulating quaternions.
Added methods for projecting and reflecting vectors, enhancing geometric operations.
Added utility functions for generating orthonormal bases and changing vector signs.
Added comprehensive unit tests for new mathematical functions and quaternion operations.
Added a high-performance job scheduling system with job management features and worker thread management.
Added new structs for job execution, allowing efficient job scheduling and execution.
Added utility functions for job execution, including methods for obtaining unique job IDs.

Changed access modifiers and property definitions in several files for improved clarity and maintainability.
Changed property definitions and method implementations in `ImageInfo.cs`, `ImageResult.cs`, and `ImageResultFloat.cs` for better readability.
Changed memory management functions in `CRuntime.cs` and improved memory allocation tracking in `MemoryStats.cs`.
Changed the project file to include references to necessary projects and enable unsafe code blocks.

Removed the `WorkerThreadPool.cs` file, integrating worker thread management directly into the `JobScheduler`.
Removed the `float4` struct and its associated methods and properties, transitioning to a new code generation strategy.
Removed the `float4.tt` template and other related files, indicating a shift in code generation approach.
Removed the `Vectorize.cs` file, indicating a change in how vector operations are handled.

Updated the `.gitignore` file to include IDE-specific settings.
Updated various XML files to define project components and structure.
Updated the `AllocationManager.cs` to improve memory allocation management and introduce new strategies.
Updated the `UnsafeArray.cs`, `UnsafeHashMap.cs`, and `UnsafeList.cs` to enhance performance and safety in unsafe contexts.
Updated error handling and function pointer management in `MemoryLeakException.cs` and `FunctionPointer.cs`.
Updated the `AssemblyInfo.cs` file to include global using directives for better code organization.
2025-09-06 12:07:02 +09:00

124 lines
3.2 KiB
C#

using Misaki.HighPerformance.Mathematics;
namespace Misaki.HighPerformance.Test.UnitTest.Mathematics;
[TestClass]
public class TestDouble2
{
[TestMethod]
public void TestConstructors()
{
// Default constructor
var v1 = new double2();
Assert.AreEqual(0.0, v1.x, 1e-15);
Assert.AreEqual(0.0, v1.y, 1e-15);
// Single value constructor
var v2 = new double2(5.5);
Assert.AreEqual(5.5, v2.x, 1e-15);
Assert.AreEqual(5.5, v2.y, 1e-15);
// Component constructor
var v3 = new double2(1.5, 2.5);
Assert.AreEqual(1.5, v3.x, 1e-15);
Assert.AreEqual(2.5, v3.y, 1e-15);
}
[TestMethod]
public void TestArithmeticOperators()
{
var a = new double2(10.5, 20.5);
var b = new double2(5.5, 4.5);
// Addition
var add = a + b;
Assert.AreEqual(16.0, add.x, 1e-15);
Assert.AreEqual(25.0, add.y, 1e-15);
// Subtraction
var sub = a - b;
Assert.AreEqual(5.0, sub.x, 1e-15);
Assert.AreEqual(16.0, sub.y, 1e-15);
// Multiplication
var mul = a * b;
Assert.AreEqual(57.75, mul.x, 1e-15);
Assert.AreEqual(92.25, mul.y, 1e-15);
// Division
var div = a / b;
Assert.AreEqual(10.5 / 5.5, div.x, 1e-15);
Assert.AreEqual(20.5 / 4.5, div.y, 1e-15);
// Scalar operations
var scalarMul = a * 2.0;
Assert.AreEqual(21.0, scalarMul.x, 1e-15);
Assert.AreEqual(41.0, scalarMul.y, 1e-15);
var scalarDiv = a / 2.0;
Assert.AreEqual(5.25, scalarDiv.x, 1e-15);
Assert.AreEqual(10.25, scalarDiv.y, 1e-15);
}
[TestMethod]
public void TestComparisonOperators()
{
var a = new double2(10.5, 20.5);
var b = new double2(10.5, 20.5);
var c = new double2(5.5, 30.5);
// Equality (approximate for floating point)
Assert.IsTrue(math.all(math.abs(a - b) < 1e-15));
Assert.IsFalse(math.all(math.abs(a - c) < 1e-15));
}
[TestMethod]
public void TestSwizzleProperties()
{
var v = new double2(1.5, 2.5);
Assert.AreEqual(1.5, v.x, 1e-15);
Assert.AreEqual(2.5, v.y, 1e-15);
// Test common swizzles
var xy = v.xy;
Assert.AreEqual(1.5, xy.x, 1e-15);
Assert.AreEqual(2.5, xy.y, 1e-15);
}
[TestMethod]
public void TestUnaryOperators()
{
var a = new double2(5.5, -3.5);
// Unary minus
var neg = -a;
Assert.AreEqual(-5.5, neg.x, 1e-15);
Assert.AreEqual(3.5, neg.y, 1e-15);
// Unary plus
var pos = +a;
Assert.AreEqual(5.5, pos.x, 1e-15);
Assert.AreEqual(-3.5, pos.y, 1e-15);
}
[TestMethod]
public void TestMathFunctions()
{
var v = new double2(3.0, 4.0);
// Test dot product
var dot = math.dot(v, v);
Assert.AreEqual(25.0, dot, 1e-15);
// Test length
var length = math.length(v);
Assert.AreEqual(5.0, length, 1e-15);
// Test normalize
var normalized = math.normalize(v);
var expectedLength = math.length(normalized);
Assert.AreEqual(1.0, expectedLength, 1e-15);
}
}