public static void EnsureCapacityTest() { var array = new UnmanagedArray <int>(3); array[0] = 1; array[1] = 2; array[2] = 3; using var valueStack = new UnmanagedValueStack <int>(array); valueStack.EnsureCapacity(0); Assert.That(() => valueStack, Has.Property("Capacity").EqualTo((nuint)3) .And.Count.EqualTo((nuint)3) ); valueStack.EnsureCapacity(3); Assert.That(() => valueStack, Has.Property("Capacity").EqualTo((nuint)3) .And.Count.EqualTo((nuint)3) ); valueStack.EnsureCapacity(4); Assert.That(() => valueStack, Has.Property("Capacity").EqualTo((nuint)6) .And.Count.EqualTo((nuint)3) ); valueStack.EnsureCapacity(16); Assert.That(() => valueStack, Has.Property("Capacity").EqualTo((nuint)16) .And.Count.EqualTo((nuint)3) ); }
public static void TrimExcessTest() { var array = new UnmanagedArray <int>(3); array[0] = 1; array[1] = 2; array[2] = 3; using (var valueStack = new UnmanagedValueStack <int>(array, takeOwnership: false)) { valueStack.TrimExcess(); Assert.That(() => valueStack, Has.Property("Capacity").EqualTo((nuint)3) .And.Count.EqualTo((nuint)3) ); } using (var valueStack = new UnmanagedValueStack <int>(array, takeOwnership: false)) { _ = valueStack.Pop(); valueStack.Push(4); valueStack.TrimExcess(); Assert.That(() => valueStack, Has.Property("Capacity").EqualTo((nuint)3) .And.Count.EqualTo((nuint)3) ); } using (var valueStack = new UnmanagedValueStack <int>(array, takeOwnership: true)) { valueStack.Push(4); valueStack.Push(5); valueStack.TrimExcess(); Assert.That(() => valueStack, Has.Property("Capacity").EqualTo((nuint)5) .And.Count.EqualTo((nuint)5) ); valueStack.EnsureCapacity(15); valueStack.TrimExcess(0.3f); Assert.That(() => valueStack, Has.Property("Capacity").EqualTo((nuint)15) .And.Count.EqualTo((nuint)5) ); } using (var valueStack = new UnmanagedValueStack <int>()) { valueStack.TrimExcess(); Assert.That(() => valueStack, Has.Property("Capacity").EqualTo((nuint)0) .And.Count.EqualTo((nuint)0) ); } }