public void ClearNotEmptyStackCanRemoveAllItems() { BoundedStack <double> stack = null; "Given there is a bounded stack with items" .x(() => { stack = new BoundedStack <double>(); stack.Initialize(); // elements stack.Push(1); stack.Push(2); stack.Push(3); stack.Push(4); stack.Push(5); }); "When clear operation on this stack happens" .x(() => { stack.Clear(); }); "Then such stack must not have any elements" .x(() => { var count = stack.Size(); count.Should().Be(0); }); }
public void WhenPushHappensWithFullOfItemsStackPushResultShouldBeError() { BoundedStack <string> stack = null; "Given there is an stack with item's count equal to capacity" .x(() => { stack = new BoundedStack <string>(); stack.Initialize(2); // items stack.Push("I"); stack.Push("Processing"); }); "When push operation happens" .x(() => { stack.Push("New string"); }); "Then get last push operation result should be 'Error'" .x(() => { var status = stack.GetPushStatus(); status.Should().Be(OpResult.ERROR); }); }
public void PeekOperationDoNotRemoveItemFromHeadPosition() { BoundedStack <double> stack = null; const double firstItem = 0.12; $"Given there is a bounded stack model with items {firstItem} 3.45 -23.02 11" .x(() => { stack = new BoundedStack <double>(); stack.Initialize(); stack.Push(firstItem); stack.Push(3.45); stack.Push(-23.02); stack.Push(11); }); "When peek operation happens" .x(() => { stack.Peek(); }); $"Then another stack's peek operation should return same item '{firstItem}'" .x(() => { var item = stack.Peek(); item.Should().Be(firstItem); }); }
public static void TestBoundedStack() { const int capacity = 20; var boundedStack = new BoundedStack <string>(capacity); Assert.Throws <InvalidOperationException>(() => boundedStack.Pop()); for (int i = 0; i < capacity; i++) { boundedStack.Push($"{i}"); } for (int i = 0; i < capacity; i++) { var poppedItem = boundedStack.Pop(); Assert.Equal($"{20 - 1 - i}", poppedItem); } Assert.Throws <InvalidOperationException>(() => boundedStack.Pop()); }