public void EmtyStackToArray_ShouldReturnEmtyArray() { var stack = new ArrayBasedStack<int>(); var arr = stack.ToArray(); Assert.AreEqual(0, arr.Length); }
public void EC_Constructor_2() { Assert.Throws <InvalidOperationException>(delegate { ArrayBasedStack <int> stack = new ArrayBasedStack <int>(-1); }); }
public static void ClearTest() { var stack = new ArrayBasedStack <int>(new[] { 0, 1, 2, 3, 4 }); stack.Clear(); Assert.IsTrue(stack.Count == 0); }
public void EC_Push_1() { ArrayBasedStack <int> stack = new ArrayBasedStack <int> (4); stack.Push(1); stack.Push(2); Assert.AreEqual(2, stack.Count); }
public void Empty_stack_to_array_should_create_an_empty_array() { var arr = new ArrayBasedStack <DateTime>(); var result = arr.ToArray(); Assert.AreEqual(0, result.Length); }
public void EmtyStackToArray_ShouldReturnEmtyArray() { var stack = new ArrayBasedStack <int>(); var arr = stack.ToArray(); Assert.AreEqual(0, arr.Length); }
public static void ClearTest() { var stack = new ArrayBasedStack <int>(new[] { 0, 1, 2, 3, 4 }); stack.Clear(); stack.Top.Should().Be(-1); }
public static void PeekTest() { var stack = new ArrayBasedStack <int>(new[] { 0, 1, 2, 3, 4 }); Assert.IsTrue(stack.Peek() == 4); Assert.IsTrue(stack.Peek() == 4); Assert.IsTrue(stack.Peek() == 4); }
public void EC_Clear() { ArrayBasedStack <int> stack = new ArrayBasedStack <int> (1); stack.Push(1); Assert.AreEqual(1, stack.Count); stack.Clear(); Assert.AreEqual(0, stack.Count); }
public void EC_Pop_2() { ArrayBasedStack <int> stack = new ArrayBasedStack <int>(1); Assert.Throws <InvalidOperationException>(delegate { stack.Pop(); }); }
public void EC_Contains() { ArrayBasedStack <int> stack = new ArrayBasedStack <int> (2); stack.Push(1); stack.Push(2); Assert.IsTrue(stack.Contains(1)); Assert.IsFalse(stack.Contains(5)); }
public void BCC_6() { ArrayBasedStack <int> stack = new ArrayBasedStack <int> (4); Assert.AreEqual(0, stack.Count); stack.Push(1); Assert.IsTrue(stack.Contains(1)); Assert.AreNotEqual(stack.Count, stack.Capacity); }
public static void PopTest() { var stack = new ArrayBasedStack <int>(new[] { 0, 1, 2, 3, 4 }); Assert.IsTrue(stack.Pop() == 4); Assert.IsTrue(stack.Pop() == 3); Assert.IsTrue(stack.Pop() == 2); Assert.IsTrue(stack.Pop() == 1); Assert.IsTrue(stack.Pop() == 0); }
public static void ShouldThrowStackEmptyExceptionOnEmptyPeekTest() { var stack = new ArrayBasedStack <int>(); Action peekingAnEmptyStack = () => stack.Peek(); peekingAnEmptyStack.Should() .Throw <InvalidOperationException>() .WithMessage(StackEmptyErrorMessage); }
public static void ContainsTest() { var stack = new ArrayBasedStack <int>(new[] { 0, 1, 2, 3, 4 }); Assert.IsTrue(stack.Contains(0)); Assert.IsTrue(stack.Contains(1)); Assert.IsTrue(stack.Contains(2)); Assert.IsTrue(stack.Contains(3)); Assert.IsTrue(stack.Contains(4)); }
public void BCC_5() { ArrayBasedStack <int> stack = new ArrayBasedStack <int> (4); Assert.AreEqual(0, stack.Count); Assert.Throws <InvalidOperationException>(delegate { stack.Pop(); }); }
public void PushPop1000Elements_ShouldAuthoGrowCorrectly() { var stack = new ArrayBasedStack<string>(); for (int i = 0; i < 1000; i++) { stack.Push(i.ToString()); } Assert.AreEqual(1000, stack.Count); }
public void PushPop1000Elements_ShouldAuthoGrowCorrectly() { var stack = new ArrayBasedStack <string>(); for (int i = 0; i < 1000; i++) { stack.Push(i.ToString()); } Assert.AreEqual(1000, stack.Count); }
public void BCC_13() { ArrayBasedStack <int> stack = new ArrayBasedStack <int> (4); stack.Push(1); stack.Push(2); stack.Push(3); Assert.AreEqual(3, stack.Count); Assert.IsFalse(stack.Contains(-2)); Assert.AreNotEqual(stack.Count, stack.Capacity); }
public static void PeekTest() { var stack = new ArrayBasedStack <int>(new[] { 0, 1, 2, 3, 4 }); Assert.Multiple(() => { stack.Peek().Should().Be(4); stack.Peek().Should().Be(4); stack.Peek().Should().Be(4); }); }
public void EC_Push_2() { ArrayBasedStack <int> stack = new ArrayBasedStack <int> (2); stack.Push(1); stack.Push(2); Assert.AreEqual(stack.Capacity, stack.Count); stack.Push(3); // Capacity is doubled to 8 Assert.AreNotEqual(stack.Capacity, stack.Count); }
private static void Run() { IStack <int> arrayBasedStack = new ArrayBasedStack <int>(); Console.WriteLine("Array Based Stack Test"); RunIStackTest(arrayBasedStack); IStack <int> listBasedStack = new ListBasedStack <int>(); Console.WriteLine("List Based Stack Test"); RunIStackTest(listBasedStack); }
public void ToArray_ShouldReturnArray() { var stack = new ArrayBasedStack<int>(); stack.Push(3); stack.Push(5); stack.Push(-2); stack.Push(7); var arr = stack.ToArray(); CollectionAssert.AreEqual(new int[] { 3, 5, -2, 7}, arr); }
public static void AutomaticResizesTest() { var stack = new ArrayBasedStack <int>(); stack.Capacity = 2; stack.Push(0); stack.Push(1); stack.Push(2); stack.Push(3); stack.Push(4); Assert.IsTrue(stack.Capacity > 2); }
public void Run() { ArrayBasedStack stack = new ArrayBasedStack(); stack.Push(1); stack.Push(2); stack.Push(3); stack.Push(4); Console.WriteLine(stack); Console.WriteLine("Popping"); Console.WriteLine($"Popped {stack.Pop()}"); Console.WriteLine(stack); }
public static void PushTest() { var stack = new ArrayBasedStack <int>(); Assert.Multiple(() => Enumerable.Range(0, 5) .ToList() .ForEach(number => { stack.Push(number); stack.Peek().Should().Be(number); })); }
public static void ContainsTest() { var stack = new ArrayBasedStack <int>(new[] { 0, 1, 2, 3, 4 }); Assert.Multiple(() => { stack.Contains(0).Should().BeTrue(); stack.Contains(1).Should().BeTrue(); stack.Contains(2).Should().BeTrue(); stack.Contains(3).Should().BeTrue(); stack.Contains(4).Should().BeTrue(); }); }
public void ToArray_ShouldReturnArray() { var stack = new ArrayBasedStack <int>(); stack.Push(3); stack.Push(5); stack.Push(-2); stack.Push(7); var arr = stack.ToArray(); CollectionAssert.AreEqual(new int[] { 3, 5, -2, 7 }, arr); }
public void Push_element_should_encrease_the_Count_and_Pop_should_decrease_the_Count_and_return_the_same_element() { var arr = new ArrayBasedStack <int>(); arr.Push(5); Assert.AreEqual(1, arr.Count); int element = arr.Pop(); Assert.AreEqual(0, arr.Count); Assert.AreEqual(5, element); }
public void PushPopElements_ShouldPushAndPopCorrectly() { var stack = new ArrayBasedStack<int>(); Assert.AreEqual(0, stack.Count); int num = 5; stack.Push(num); Assert.AreEqual(1, stack.Count); var element = stack.Pop(); Assert.AreEqual(num, element); Assert.AreEqual(0, stack.Count); }
public void Convert_stack_to_array_should_return_elements_in_reversed_order() { var arr = new ArrayBasedStack <int>(); arr.Push(3); arr.Push(5); arr.Push(-2); arr.Push(7); var result = arr.ToArray(); var expectedArr = new int[] { 7, -2, 5, 3 }; CollectionAssert.AreEqual(expectedArr, result); }
public static void PushTest() { var stack = new ArrayBasedStack <int>(); stack.Push(0); Assert.IsTrue(stack.Peek() == 0); stack.Push(1); Assert.IsTrue(stack.Peek() == 1); stack.Push(2); Assert.IsTrue(stack.Peek() == 2); stack.Push(3); Assert.IsTrue(stack.Peek() == 3); stack.Push(4); Assert.IsTrue(stack.Peek() == 4); }
public void PushPopElements_ShouldPushAndPopCorrectly() { var stack = new ArrayBasedStack <int>(); Assert.AreEqual(0, stack.Count); int num = 5; stack.Push(num); Assert.AreEqual(1, stack.Count); var element = stack.Pop(); Assert.AreEqual(num, element); Assert.AreEqual(0, stack.Count); }
public static void AutomaticResizesTest() { const int initialCapacity = 2; var stack = new ArrayBasedStack <int> { Capacity = initialCapacity, }; stack.Push(0); stack.Push(1); stack.Push(2); stack.Push(3); stack.Push(4); stack.Capacity.Should().BeGreaterThan(initialCapacity); }
public void PushPopWithGivenCapacity_ShouldWorkCorrectly() { var stack = new ArrayBasedStack<int>(1); Assert.AreEqual(0, stack.Count); stack.Push(10); Assert.AreEqual(1, stack.Count); stack.Push(15); Assert.AreEqual(2, stack.Count); var element = stack.Pop(); Assert.AreEqual(15, element); Assert.AreEqual(1, stack.Count); var anotherElement = stack.Pop(); Assert.AreEqual(10, anotherElement); Assert.AreEqual(0, stack.Count); }
public void PopFromEmptyStack_ShouldThrowException() { var stack = new ArrayBasedStack<int>(); var element = stack.Pop(); }