public void Size_ForNonEmptyStackAfterPushAndPop_Success() { IBasicStack <int> stack = new BasicStack <int>(); stack.Push(1); stack.Push(2); stack.Push(3); stack.Pop(); Assert.Equal(2, stack.Size()); }
public void Push_WithValidValue_Success() { IBasicStack <int> stack = new BasicStack <int>(); stack.Push(1); Assert.Equal(1, stack.Size()); }
public void PushOverCapacity(int capacity) { var sut = new BasicStack <int>(GenerateArray(capacity)); // Assert Assert.DoesNotThrow(() => sut.Push(12)); Assert.Greater(sut.Count, capacity); }
public void IsEmpty_ForNonEmptyStack_ReturnsFalse() { IBasicStack <int> stack = new BasicStack <int>(); for (var i = 0; i < 3; i++) { stack.Push(i); } Assert.False(stack.IsEmpty()); }
public void Size_ForNonEmptyStack_ReturnsOne() { IBasicStack <int> stack = new BasicStack <int>(); for (var i = 0; i < 3; i++) { stack.Push(i); } Assert.Equal(3, stack.Size()); }
public void Pop_ForNonEmptyStack_Success() { IBasicStack <int> stack = new BasicStack <int>(); for (var i = 0; i < 3; i++) { stack.Push(i); } var itemValue = stack.Pop(); Assert.Equal(2, itemValue); }
public int Check(string input) { BasicStack <char> stack = new BasicStack <char>(); BasicStack <int> stackIndex = new BasicStack <int>(); int index = 0; foreach (var ch in input) { index++; //if (!"{}[]()".Contains(ch)) continue; if (!(ch.Equals('[') || ch.Equals(']') || ch.Equals('(') || ch.Equals(')') || ch.Equals('{') || ch.Equals('}'))) { continue; } stackIndex.Push(index); if (ch.Equals('[') || ch.Equals('(') || ch.Equals('{')) { stack.Push(ch); continue; } else { if (stack.Count == 0) { return(stackIndex.Pop()); } var top = stack.Pop(); if ( (top == '[' && ch != ']') || (top == '(' && ch != ')') || (top == '{' && ch != '}')) { return(stackIndex.Pop()); } stackIndex.Pop(); stackIndex.Pop(); } } if (stack.Count != 0) { return(stackIndex.Pop()); // index; } return(0); }
public void CorrectPushAndPop(int capacity) { int[] inputArray = GenerateArray(capacity); int[] resultArray = new int[capacity]; var sut = new BasicStack <int>(); Array.ForEach(inputArray, x => sut.Push(x)); for (int i = 0; i < capacity; i++) { resultArray[i] = sut.Pop(); } // Assert Assert.AreEqual(inputArray.Reverse(), resultArray); }