using AcDream.App.Rendering.Gpu.Gl; namespace AcDream.App.Tests.Rendering.Gpu.Gl; public sealed class GlTextureSlotAllocatorTests { [Fact] public void AllocationsBumpSequentiallyFromZero() { var allocator = new GlTextureSlotAllocator(capacity: 4); Assert.Equal(0u, allocator.Allocate()); Assert.Equal(1u, allocator.Allocate()); Assert.Equal(2u, allocator.Allocate()); Assert.Equal(3, allocator.LiveCount); } [Fact] public void ExhaustingCapacityThrows() { var allocator = new GlTextureSlotAllocator(capacity: 2); allocator.Allocate(); allocator.Allocate(); Assert.Throws(() => allocator.Allocate()); } [Fact] public void ReleasedSlotsAreReusedBeforeBumpingFurther() { var allocator = new GlTextureSlotAllocator(capacity: 4); uint first = allocator.Allocate(); allocator.Allocate(); allocator.Release(first); Assert.Equal(1, allocator.LiveCount); uint reused = allocator.Allocate(); Assert.Equal(first, reused); Assert.Equal(2, allocator.LiveCount); } [Fact] public void ReleasingAnUnallocatedSlotThrows() { var allocator = new GlTextureSlotAllocator(capacity: 4); allocator.Allocate(); Assert.Throws(() => allocator.Release(3)); } [Fact] public void FreeingThenExhaustingTheBumpRangeStillThrowsPastCapacity() { var allocator = new GlTextureSlotAllocator(capacity: 2); uint first = allocator.Allocate(); allocator.Allocate(); allocator.Release(first); allocator.Allocate(); Assert.Throws(() => allocator.Allocate()); } }