Files
Misaki.HighPerformance/Misaki.HighPerformance.Test/UnitTest/Collections/TestUnsafeArray.cs
Misaki 9c4faa107a feat(memory): transition to AllocationHandle API
Replaced the deprecated Allocator API with the new AllocationHandle API across the codebase. Updated constructors, methods, and tests to use AllocationHandle for memory management. Marked Allocator-based methods as [Obsolete] and provided alternatives.

Added OwnershipTransferAnalyzer to detect ownership transfer issues and introduced OwnershipTransferAttribute for marking parameters. Enhanced DefensiveCopyAnalyzer with additional checks for readonly and ValueType instances.

Refactored internal memory management in AllocationManager and updated benchmarks, utilities, and documentation to reflect the changes.

BREAKING CHANGE: Deprecated Allocator API in favor of AllocationHandle. Updated constructors and methods to use AllocationHandle. Users must migrate to the new API.
2026-04-12 17:50:12 +09:00

62 lines
1.2 KiB
C#

using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.LowLevel.Collections;
namespace Misaki.HighPerformance.Test.UnitTest.Collections;
[TestClass]
public class TestUnsafeArray
{
private UnsafeArray<int> _arr;
[TestInitialize]
public void Initialize()
{
_arr = new UnsafeArray<int>(16, AllocationHandle.Persistent);
}
[TestCleanup]
public void Cleanup()
{
_arr.Dispose();
}
[GlobalTestCleanup]
public static void GlobalCleanup(TestContext ctx)
{
AllocationManager.Dispose();
}
[TestMethod]
public void TestIndexAccess()
{
for (var i = 0; i < _arr.Count; i++)
{
_arr[i] = i * 10;
}
for (var i = 0; i < _arr.Count; i++)
{
Assert.AreEqual(i * 10, _arr[i]);
}
}
[TestMethod]
public void TestEnumeration()
{
_arr.Clear();
var expectedValue = 0;
foreach (var item in _arr)
{
Assert.AreEqual(expectedValue, item);
}
}
[TestMethod]
public void TestIsCreated()
{
Assert.IsTrue(_arr.IsCreated);
_arr.Dispose();
Assert.IsFalse(_arr.IsCreated);
}
}