public static void TestStack2Methods() { var stack = new Stack2 <int>(); Assert.AreEqual(0, stack.Size(), "TestSize must be 0, but not"); stack.Push(1); Assert.AreEqual(1, stack.Size(), "TestSize must be 1, but not"); stack.Push(2); Assert.AreEqual(2, stack.Size(), "TestSize must be 2, but not"); stack.Push(3); Assert.AreEqual(3, stack.Size(), "TestSize must be 3, but not"); var top = stack.Peek(); Assert.AreEqual(3, top, "TestStackMethods Peek value must be 3"); var value = stack.Pop(); Assert.AreEqual(3, value, "TestStackMethods Pop value must be 3"); Assert.AreEqual(2, stack.Size(), "TestSize must be 2, but not"); value = stack.Pop(); Assert.AreEqual(2, value, "TestStackMethods Pop value must be 2"); Assert.AreEqual(1, stack.Size(), "TestSize must be 1, but not"); value = stack.Pop(); Assert.AreEqual(1, value, "TestStackMethods Pop value must be 1"); Assert.AreEqual(0, stack.Size(), "TestSize must be 0, but not"); value = stack.Pop(); Assert.AreEqual(0, stack.Peek(), "TestStackMethods stack is not empty"); Assert.AreEqual(0, value, "TestStackMethods stack is not empty"); Assert.AreEqual(0, stack.Peek(), "TestStackMethods stack is not empty"); }
static void Main() { Stack2 stk1 = new Stack2(10); char ch; int i; // Put some characters into stk1. Console.WriteLine("Push A through J onto stk1."); for (i = 0; !stk1.IsFull(); i++) { stk1.Push((char)('A' + i)); } // Create a copy of stck1. Stack2 stk2 = new Stack2(stk1); // Display the contents of stk1. Console.Write("Contents of stk1: "); while (!stk1.IsEmpty()) { ch = stk1.Pop(); Console.Write(ch); } Console.WriteLine(); Console.Write("Contents of stk2: "); while (!stk2.IsEmpty()) { ch = stk2.Pop(); Console.Write(ch); } Console.WriteLine("\n"); }
public void Test_Pop() { var stack = new Stack2(); stack.Push(1); stack.Push(2); stack.Push(3); var popped = stack.Pop(); Assert.AreEqual(3, popped); }
public static void Main(string[] args) { Stack2 s = new Stack2(10); for (int i = 1; i <= 100; i++) { s.Push(i); } for (int i = 1; i <= 100; i++) { s.Pop(); } s.print(); }
public void Pop_StackWithAFewObjects_RemoveObjectFromStack() { //Arrange var stack = new Stack2 <string>(); stack.Push("a"); stack.Push("b"); stack.Push("c"); //Act var result = stack.Pop(); //Assert Assert.That(stack.Count, Is.EqualTo(2)); }
public void Pop_StackWithAFewObjects_ReturnObjectOnTheTop() { //Arrange var stack = new Stack2 <string>(); stack.Push("a"); stack.Push("b"); stack.Push("c"); //Act var result = stack.Pop(); //Assert Assert.That(result, Is.EqualTo("c")); //pre uistenie sa ze test funguje spravne je treba po jeho napisani a uspesnom zbehnuti zmenit business logiku s predpokladom ze by mal test zlyhat pre overenie }
/// <summary> /// Add a new item to the "rear" of the queue, which is actually the bottom of the primary stack /// </summary> /// <param name="val">Value to be enqueued</param> public void Enqueue(string val) { if (Stack1.Top == null) { Stack1.Push(val); Front = Stack1.Top; } else { while (Stack1.Top != null) { Stack2.Push(Stack1.Pop()); } Stack1.Push(val); while (Stack2.Top != null) { Stack1.Push(Stack2.Pop()); } Front = Stack1.Top; } }
public void Pop_EmptyStack_ThrowInvalidOperationException() { var stack = new Stack2 <string>(); Assert.That(() => stack.Pop(), Throws.InvalidOperationException); }