public static void PeekTest() { var array = new UnmanagedArray <int>(3); array[0] = 1; array[1] = 2; array[2] = 3; using (var valueStack = new UnmanagedValueStack <int>(array, takeOwnership: true)) { Assert.That(() => valueStack.Peek(), Is.EqualTo(3) ); valueStack.Push(4); Assert.That(() => valueStack.Peek(), Is.EqualTo(4) ); _ = valueStack.Pop(); valueStack.Push(5); Assert.That(() => valueStack.Peek(), Is.EqualTo(5) ); _ = valueStack.Pop(); valueStack.Push(6); valueStack.Push(7); Assert.That(() => valueStack.Peek(), Is.EqualTo(7) ); Assert.That(() => valueStack, Has.Property("Capacity").EqualTo((nuint)6) .And.Count.EqualTo((nuint)5) ); } using (var valueStack = new UnmanagedValueStack <int>()) { Assert.That(() => valueStack.Peek(), Throws.InvalidOperationException ); } }
public static void PeekNUIntTest() { var array = new UnmanagedArray <int>(3); array[0] = 1; array[1] = 2; array[2] = 3; using (var valueStack = new UnmanagedValueStack <int>(array, takeOwnership: true)) { Assert.That(() => valueStack.Peek(0), Is.EqualTo(3) ); valueStack.Push(4); Assert.That(() => valueStack.Peek(0), Is.EqualTo(4) ); Assert.That(() => valueStack.Peek(3), Is.EqualTo(1) ); _ = valueStack.Pop(); valueStack.Push(5); Assert.That(() => valueStack.Peek(0), Is.EqualTo(5) ); Assert.That(() => valueStack.Peek(1), Is.EqualTo(3) ); _ = valueStack.Pop(); valueStack.Push(6); valueStack.Push(7); Assert.That(() => valueStack.Peek(0), Is.EqualTo(7) ); Assert.That(() => valueStack.Peek(2), Is.EqualTo(3) ); Assert.That(() => valueStack, Has.Property("Capacity").EqualTo((nuint)6) .And.Count.EqualTo((nuint)5) ); } using (var valueStack = new UnmanagedValueStack <int>()) { Assert.That(() => valueStack.Peek(0), Throws.InstanceOf <ArgumentOutOfRangeException>() .And.Property("ActualValue").EqualTo((nuint)0) .And.Property("ParamName").EqualTo("index") ); } }