Files
Misaki.HighPerformance/Misaki.HighPerformance.Test/UnitTest/Collections/TestUnsafeBitSet.cs
Misaki 3269244ab1 Refactor memory management with MemoryHandle
Replaced `SafeHandle` with a new `MemoryHandle` system for improved memory tracking, safety, and leak detection. Updated allocators (`ArenaAllocator`, `HeapAllocator`, `StackAllocator`) and collections (`UnTypedArray`, `UnsafeArray<T>`, `UnsafeBitSet`) to use `MemoryHandle`.

Refactored `AllocationManager` to use `ConcurrentSlotMap` for live allocation tracking and added methods for managing `MemoryHandle` instances. Simplified alignment and padding logic across allocators and collections.

Enhanced performance with optimized memory operations (`MemClear`, `MemSet`, `MemCpy`) and vectorized operations in `MemoryUtility` and `UnsafeBitSet`. Fixed alignment issues in vectorized memory operations.

Updated tests to reflect the new memory management system and added new tests for `UnsafeBitSet` bitwise operations. Enabled `ENABLE_COLLECTION_CHECKS` for debug builds and improved error messages and documentation.

Removed unused `SafeHandle` code and adjusted project configuration to include necessary references.
2025-11-25 12:27:10 +09:00

109 lines
2.2 KiB
C#

using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.LowLevel.Collections;
namespace Misaki.HighPerformance.Test.UnitTest.Collections;
[TestClass]
public class TestUnsafeBitSet
{
private UnsafeBitSet _set1;
private UnsafeBitSet _set2;
[TestInitialize]
public void Initialize()
{
_set1 = new UnsafeBitSet(16, Allocator.Persistent, AllocationOption.Clear);
_set2 = new UnsafeBitSet(16, Allocator.Persistent, AllocationOption.Clear);
}
[TestCleanup]
public void Cleanup()
{
_set1.Dispose();
_set2.Dispose();
}
[TestMethod]
public void TestBitCount()
{
Assert.AreEqual(256, _set1.Count);
}
[TestMethod]
public void TestSetAndGet()
{
Assert.IsFalse(_set1.IsSet(0));
_set1.SetBit(0);
Assert.IsTrue(_set1.IsSet(0));
_set1.ClearBit(0);
Assert.IsFalse(_set1.IsSet(0));
}
[TestMethod]
public void TestClearAll()
{
for (var i = 0; i < _set1.Count; i++)
{
_set1.SetBit(i);
}
_set1.ClearAll();
for (var i = 0; i < _set1.Count; i++)
{
Assert.IsFalse(_set1.IsSet(i));
}
}
[TestMethod]
public void TestAnd()
{
_set1.SetBit(0);
_set1.SetBit(1);
_set2.SetBit(1);
_set2.SetBit(2);
_set1.And(_set2);
Assert.IsFalse(_set1.IsSet(0));
Assert.IsTrue(_set1.IsSet(1));
Assert.IsFalse(_set1.IsSet(2));
}
[TestMethod]
public void TestNot()
{
_set1.SetBit(0);
_set1.SetBit(1);
_set2.SetBit(1);
_set2.SetBit(2);
_set1.Not();
_set2.Not();
Assert.IsFalse(_set1.IsSet(0));
Assert.IsFalse(_set1.IsSet(1));
Assert.IsTrue(_set1.IsSet(2));
Assert.IsTrue(_set1.IsSet(3));
Assert.IsTrue(_set2.IsSet(0));
Assert.IsFalse(_set2.IsSet(1));
}
[TestMethod]
public void TestANDC()
{
_set1.SetBit(0);
_set1.SetBit(1);
_set2.SetBit(1);
_set2.SetBit(2);
_set1.ANDC(_set2);
Assert.IsTrue(_set1.IsSet(0));
Assert.IsFalse(_set1.IsSet(1));
Assert.IsFalse(_set1.IsSet(2));
}
}