public void NotContainTest() { MyStack<int> Stack = new MyArrayStack<int>(); Stack.Push(31); Stack.Push(9); Assert.AreEqual(Stack.Contains(63), false); }
public void ContainTest() { MyStack<int> Stack = new MyArrayStack<int>(); Stack.Push(31); Stack.Push(9); Assert.AreEqual(Stack.Contains(31), true); }
public void NotContainTest() { MyStack <int> Stack = new MyArrayStack <int>(); Stack.Push(31); Stack.Push(9); Assert.AreEqual(Stack.Contains(63), false); }
public void PeekTest() { MyStack <int> Stack = new MyArrayStack <int>(); Stack.Push(98); Stack.Push(20); Assert.AreEqual(Stack.Peek(), 20); }
public void PushPopTest() { MyStack <int> Stack = new MyArrayStack <int>(); Stack.Push(85); Stack.Push(48); Assert.AreEqual(Stack.Pop(), 48); }
public void CopyConstructorTest() { MyStack<int> Stack = new MyArrayStack<int>(); Stack.Push(1); Stack.Push(2); MyStack<int> Stack2 = new MyArrayStack<int>(Stack); Assert.AreEqual(Stack2, Stack); }
public void ContainTest() { MyStack <int> Stack = new MyArrayStack <int>(); Stack.Push(31); Stack.Push(9); Assert.AreEqual(Stack.Contains(31), true); }
public void ClearTest() { MyStack<int> Stack = new MyArrayStack<int>(); Stack.Push(1); Stack.Push(2); Stack.Clear(); Assert.AreEqual(Stack.Count, 0); Assert.AreEqual((Stack as MyArrayStack<int>).Capacity, 10); }
public void ClearTest() { MyStack <int> Stack = new MyArrayStack <int>(); Stack.Push(1); Stack.Push(2); Stack.Clear(); Assert.AreEqual(Stack.Count, 0); Assert.AreEqual((Stack as MyArrayStack <int>).Capacity, 10); }
public void PushMoreThanCapacityTest() { int actualCapacity = 1; MyStack <int> Stack = new MyArrayStack <int>(actualCapacity); Stack.Push(70); Stack.Push(52); Assert.AreEqual(Stack.Count, 2); Assert.AreEqual((Stack as MyArrayStack <int>).Capacity, actualCapacity + 10); }
public void CopyToArray() { int[] array = new int[2]; MyStack<int> Stack = new MyArrayStack<int>(); Stack.Push(51); Stack.Push(94); Stack.CopyTo(array, 0); Assert.AreEqual(array[0], 51); Assert.AreEqual(array[1], 94); }
public void CopyConstructorTest() { MyStack <int> Stack = new MyArrayStack <int>(); Stack.Push(1); Stack.Push(2); MyStack <int> Stack2 = new MyArrayStack <int>(Stack); Assert.AreEqual(Stack2, Stack); }
public void CopyToArray() { int[] array = new int[2]; MyStack <int> Stack = new MyArrayStack <int>(); Stack.Push(51); Stack.Push(94); Stack.CopyTo(array, 0); Assert.AreEqual(array[0], 51); Assert.AreEqual(array[1], 94); }
public void Push_TwoItems_ShouldAddTwoitems() { // Arrange var myArrayStack = new MyArrayStack <int>(); // Act myArrayStack.Push(1); myArrayStack.Push(2); // Assert Assert.AreEqual(2, myArrayStack.Count); }
public void Push_FiveItems_ShouldAddFiveItems() { // Arrange var myArrayStack = new MyArrayStack <int>(); // Act myArrayStack.Push(1); myArrayStack.Push(2); myArrayStack.Push(3); myArrayStack.Push(4); myArrayStack.Push(5); // Assert Assert.AreEqual(5, myArrayStack.Count); }
public void PushedStack_ShouldIncrementCountWithOne() { MyArrayStack<int> myStack = new MyArrayStack<int>(); Assert.AreEqual(0, myStack.Count); myStack.Push(1); Assert.AreEqual(1, myStack.Count); }
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 InvalidCopyToArray() { int[] array = new int[2]; MyStack <int> Stack = new MyArrayStack <int>(); Stack.Push(51); Stack.Push(94); try { Stack.CopyTo(array, 2); } catch (IndexOutOfRangeException e) { StringAssert.Contains(e.Message, "Индекс вне диапазона."); } }
public void TestToArrayMethod_ReturnedArrayShouldBeInReversedOrder() { MyArrayStack<int> myStack = new MyArrayStack<int>(); myStack.Push(3); myStack.Push(5); myStack.Push(-2); myStack.Push(7); var arr = myStack.ToArray(); Assert.AreEqual(7, arr[0]); Assert.AreEqual(-2, arr[1]); Assert.AreEqual(5, arr[2]); Assert.AreEqual(3, arr[3]); }
static void Main() { //MyEasyStack<string> myEasyStack = new MyEasyStack<string>(); //myEasyStack.Push("Hi"); //myEasyStack.Push("Hellow"); //myEasyStack.Push("World"); //Print(myEasyStack); //var newStack = myEasyStack.Clone(); //myEasyStack.Push("People"); //Print(myEasyStack); //Console.Write("Клонированный "); //Print(newStack); //MyStack<int> myStack = new MyStack<int>(); //myStack.Push(1); //myStack.Push(3); //myStack.Push(5); //Print(myStack); //var newMyStack = myStack.Clone(); //myStack.Push(7); //Print(myStack); //Console.Write("Клонированный "); //Print(newMyStack); MyArrayStack <string> myArrayStack = new MyArrayStack <string>(6); myArrayStack.Push("1"); myArrayStack.Push("3"); myArrayStack.Push("5"); Print(myArrayStack); var newMyArrayStack = myArrayStack.Clone(); myArrayStack.Push("7"); Print(myArrayStack); Console.Write("Клонированный "); newMyArrayStack.Push("new"); Print(newMyArrayStack); }
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 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 Peek_ShouldReturnLastAddedItem() { // Arrange var myArrayStack = new MyArrayStack <int>(); var expected = 0; myArrayStack.Push(++expected); myArrayStack.Push(++expected); myArrayStack.Push(++expected); myArrayStack.Push(++expected); myArrayStack.Push(++expected); // Act var actual = myArrayStack.Peek(); // Assert Assert.AreEqual(expected, actual); }
public void Peek_ShouldNotChangeStackCount() { // Arrange var myArrayStack = new MyArrayStack <int>(); myArrayStack.Push(1); myArrayStack.Push(2); myArrayStack.Push(3); myArrayStack.Push(4); myArrayStack.Push(5); var expectedCount = myArrayStack.Count; // Act myArrayStack.Peek(); myArrayStack.Peek(); // Assert Assert.AreEqual(expectedCount, myArrayStack.Count); }
public void PushOneThousandElements_CountShouldBeOneThousand() { MyArrayStack<int> myStack = new MyArrayStack<int>(); for (int i = 0; i < 1000; i++) { myStack.Push(i); } Assert.AreEqual(1000, myStack.Count); }
public void Push_FirstItem_ShouldAddOneItem() { // Arrange var myArrayStack = new MyArrayStack <int>(); // Act myArrayStack.Push(3); // Assert Assert.AreEqual(1, myArrayStack.Count); }
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); }
/// <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 Should_Push_Element_Change_Capacity() { //arrange var stack = new MyArrayStack <int>(new[] { 1, 2, 3, 4 }); var data = 1; //act stack.Push(data); var result = stack.Peek(); //assert stack.Count.ShouldBeEquivalentTo(5); stack.Capacity.ShouldBeEquivalentTo(8); result.ShouldBeEquivalentTo(data); }
public void Should_Push_Element() { //arrange var stack = new MyArrayStack <int>(); var data = 1; //act stack.Push(data); var result = stack.Peek(); //assert stack.Count.ShouldBeEquivalentTo(1); stack.Capacity.ShouldBeEquivalentTo(4); result.ShouldBeEquivalentTo(data); }
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()); }
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 InvalidCopyToArray() { int[] array = new int[2]; MyStack<int> Stack = new MyArrayStack<int>(); Stack.Push(51); Stack.Push(94); try { Stack.CopyTo(array, 2); } catch (IndexOutOfRangeException 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 PushMoreThanCapacityTest() { int actualCapacity = 1; MyStack<int> Stack = new MyArrayStack<int>(actualCapacity); Stack.Push(70); Stack.Push(52); Assert.AreEqual(Stack.Count, 2); Assert.AreEqual((Stack as MyArrayStack<int>).Capacity, actualCapacity + 10); }
public void PeekTest() { MyStack<int> Stack = new MyArrayStack<int>(); Stack.Push(98); Stack.Push(20); Assert.AreEqual(Stack.Peek(), 20); }