public void Should_Pop() { //arrange var stack = new MyArrayStack <int>(new[] { 1 }); //act var result = stack.Pop(); Action act = () => stack.Pop(); //assert result.ShouldBeEquivalentTo(1); stack.Count.ShouldBeEquivalentTo(0); stack.Capacity.ShouldBeEquivalentTo(1); act.ShouldThrow <InvalidOperationException>(); }
private void RearrangeStacks(MyArrayStack<T> first, MyArrayStack<T> second) { if (first == null || second == null) throw new ArgumentNullException(); MyArrayStack<T> temp = new MyArrayStack<T>(second.Capacity); while (second.Count != 1) temp.Push(second.Pop()); first.Push(second.Pop()); while (temp.Count != 0) second.Push(temp.Pop()); }
static void Main() { MyArrayStack<int> myStack = new MyArrayStack<int>(); for (int i = 1; i <= 10; i++) { myStack.Push(i); } Console.WriteLine("{0}", string.Join("-", myStack.ToArray())); foreach (var item in myStack) { Console.Write("{0}-", item); } Console.WriteLine(); while (myStack.Count > 0) { Console.WriteLine(myStack.Pop()); } Console.Read(); }
public void PushPopTest() { MyStack <int> Stack = new MyArrayStack <int>(); Stack.Push(85); Stack.Push(48); Assert.AreEqual(Stack.Pop(), 48); }
public void Pop_TwoItem_ShouldDecrementStackCountbyTwo() { // Arrange var myArrayStack = new MyArrayStack <int>(); myArrayStack.Push(1); myArrayStack.Push(2); myArrayStack.Push(3); myArrayStack.Push(4); myArrayStack.Push(5); // Act myArrayStack.Pop(); myArrayStack.Pop(); // Assert Assert.AreEqual(3, myArrayStack.Count); }
public void Should_Pop_Multiple() { //arrange var array = new[] { 1, 2, 3 }; var stack = new MyArrayStack <int>(array); //act var first = stack.Pop(); var second = stack.Pop(); var third = stack.Pop(); Action act = () => stack.Pop(); //assert first.ShouldBeEquivalentTo(array[2]); second.ShouldBeEquivalentTo(array[1]); third.ShouldBeEquivalentTo(array[0]); act.ShouldThrow <InvalidOperationException>(); }
public void PopAndPushTwoTimesInitCapcityOne_ResizeAndCountShouldBehaveCorectly() { MyArrayStack<string> myStack = new MyArrayStack<string>(1); Assert.AreEqual(0, myStack.Count); myStack.Push("One"); Assert.AreEqual(1, myStack.Count); myStack.Push("Two"); Assert.AreEqual(2, myStack.Count); var poppedElement = myStack.Pop(); Assert.AreEqual("Two", poppedElement); Assert.AreEqual(1, myStack.Count); poppedElement = myStack.Pop(); Assert.AreEqual("One", poppedElement); Assert.AreEqual(0, myStack.Count); }
public void Should_Pop_Throw_If_Stack_Is_Empty() { //arrange var stack = new MyArrayStack <int>(); //act Action act = () => stack.Pop(); //assert act.ShouldThrow <InvalidOperationException>(); }
public void PopFromEmptyStackTest() { MyStack <int> Stack = new MyArrayStack <int>(); try { Stack.Pop(); } catch (InvalidOperationException e) { StringAssert.Contains(e.Message, "Стек пуст."); } }
/// <summary> /// 基于数组的栈的测试 /// </summary> static void StackWithArrayTest() { MyArrayStack <int> stack = new MyArrayStack <int>(10); Console.WriteLine(stack.IsEmpty()); Random rand = new Random(); for (int i = 0; i < 10; i++) { stack.Push(rand.Next(1, 10)); } Console.WriteLine("IsEmpty:{0}", stack.IsEmpty()); Console.WriteLine("Size:{0}", stack.Size); Console.WriteLine("-------------------------------"); for (int i = 0; i < 10; i++) { int node = stack.Pop(); Console.Write(node + " "); } Console.WriteLine(); Console.WriteLine("IsEmpty:{0}", stack.IsEmpty()); Console.WriteLine("Size:{0}", stack.Size); Console.WriteLine("-------------------------------"); for (int i = 0; i < 15; i++) { stack.Push(rand.Next(1, 15)); } for (int i = 0; i < 15; i++) { int node = stack.Pop(); Console.Write(node + " "); } Console.WriteLine(); }
public void PopOneThousandTimesFromMyStackWithOneThousendElements_CountShoulBeZero() { MyArrayStack<int> myStack = new MyArrayStack<int>(); for (int i = 0; i < 1000; i++) { myStack.Push(i); } for (int i = 0; i < 1000; i++) { myStack.Pop(); } Assert.AreEqual(0, myStack.Count); }
public void Pop_OneItem_ShouldReturnLastAddedItem() { // Arrange var myArrayStack = new MyArrayStack <int>(); myArrayStack.Push(1); myArrayStack.Push(2); myArrayStack.Push(3); myArrayStack.Push(4); myArrayStack.Push(5); // Act var item = myArrayStack.Pop(); // Assert Assert.AreEqual(5, item); }
public void PopFromEmptyStackTest() { MyStack<int> Stack = new MyArrayStack<int>(); try { Stack.Pop(); } catch (InvalidOperationException e) { StringAssert.Contains(e.Message, "Стек пуст."); } }
public void PushPopTest() { MyStack<int> Stack = new MyArrayStack<int>(); Stack.Push(85); Stack.Push(48); Assert.AreEqual(Stack.Pop(), 48); }
public void PopElementFromEmptyMyStack_ShouldThrow() { MyArrayStack<int> myStack = new MyArrayStack<int>(); myStack.Pop(); }