Files
Misaki.HighPerformance/Misaki.HighPerformance.Test/UnitTest/Collections/TestUnsafeStack.cs
Misaki f3b0f295a8 Added new TempJobAllocator
Added new AllocationHandle property in Stack.Scope.

Changed the ref AllocationHandle constructor parameter to AllocationHandle on of all UnsafeCollection types
Removed Allocator.Stack. Use Stack.Scope.AllocationHandle to allocate on stack instead.
2025-12-06 22:16:39 +09:00

64 lines
1.3 KiB
C#

using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.LowLevel.Collections;
namespace Misaki.HighPerformance.Test.UnitTest.Collections;
[TestClass]
public class TestUnsafeStack
{
private UnsafeStack<int> _stack;
[TestInitialize]
public void Initialize()
{
_stack = new UnsafeStack<int>(16, Allocator.Persistent);
}
[TestCleanup]
public void Cleanup()
{
_stack.Dispose();
}
[TestMethod]
public void TestPushPop()
{
for (int i = 0; i < 10; i++)
{
_stack.Push(i);
}
Assert.AreEqual(10, _stack.Count);
for (int i = 9; i >= 0; i--)
{
int value = _stack.Pop();
Assert.AreEqual(i, value);
}
Assert.AreEqual(0, _stack.Count);
}
[TestMethod]
public void TestPeek()
{
_stack.Push(42);
int value = _stack.Peek();
Assert.AreEqual(42, value);
Assert.AreEqual(1, _stack.Count);
}
[TestMethod]
public void TestEnumeration()
{
for (int i = 0; i < 5; i++)
{
_stack.Push(i);
}
int expected = 4;
foreach (var item in _stack)
{
Assert.AreEqual(expected, item);
expected--;
}
}
}