public void Peek_PushTwoItems_ReturnsHeadItem() { var stack = new MyStack <int>(); stack.Push(1); stack.Push(2); Assert.AreEqual(2, stack.Peek()); }
public void Peek_PushTwoItemsAndPop_ReturnsHeadElement() { var stack = new MyStack <int>(); stack.Push(1); stack.Push(2); stack.Pop(); Assert.AreEqual(1, stack.Peek()); }
public void TestStack() { Stack <int> stdStack = new Stack <int>(); // standard queue implemented by C# MyStack <int> ourStack = new MyStack <int>(); // our manually implemented stack // Test generates 100 random integers and adds to both queues Random r = new Random(); for (int i = 0; i < 100; i++) { int randVal = r.Next(); stdStack.Push(randVal); ourStack.Push(randVal); } // Test reading back half the added integers for (int i = 0; i < 50; i++) { Assert.AreEqual(stdStack.Pop(), ourStack.Pop()); Assert.AreEqual(stdStack.Peek(), ourStack.Peek()); Assert.AreEqual(stdStack.Count, ourStack.Count()); } // Test adding 50 more random integers for (int i = 0; i < 50; i++) { int randVal = r.Next(); stdStack.Push(randVal); ourStack.Push(randVal); } // Test reading back all the remaining values for (int i = 0; i < 100; i++) { Assert.AreEqual(stdStack.Peek(), ourStack.Peek()); Assert.AreEqual(stdStack.Pop(), ourStack.Pop()); Assert.AreEqual(stdStack.Count, ourStack.Count()); } }