public void StackWithNoInitializationThrowsException() { BoundedStack <double> stack = null; "When stack is not initialized" .x(() => { stack = new BoundedStack <double>(); }); "Then system must generate exception's on every stack's methods: push pop peek clear and size" .x(() => { Action actionPush = () => stack.Push(234); Action actionPop = () => stack.Pop(); Action actionPeek = () => stack.Peek(); Action actionClear = () => stack.Clear(); Action actionSize = () => stack.Size(); actionPush.Should().Throw <Exception>(); actionPop.Should().Throw <Exception>(); actionPeek.Should().Throw <Exception>(); actionClear.Should().Throw <Exception>(); actionSize.Should().Throw <Exception>(); }); }
public void WhenPushHappensWithFullOfItemsStackPushResultShouldBeError() { BoundedStack <string> stack = null; "Given there is an stack with item's count equal to capacity" .x(() => { stack = new BoundedStack <string>(); stack.Initialize(2); // items stack.Push("I"); stack.Push("Processing"); }); "When push operation happens" .x(() => { stack.Push("New string"); }); "Then get last push operation result should be 'Error'" .x(() => { var status = stack.GetPushStatus(); status.Should().Be(OpResult.ERROR); }); }
public void DefaultBoundedStackCanContainsOnly32Items() { BoundedStack <int> stack = null; "Given there is a default bounded stack model with 32 capacity" .x(() => { stack = new BoundedStack <int>(); stack.Initialize(); }); "When user pushes 33 items into bounded stack" .x(() => { for (int index = 0; index < 33; index++) { stack.Push(index); } }); "Then bounded stack model should add only 32 items" .x(() => { stack.Size().Should().Be(32); }); }
public void ClearNotEmptyStackCanRemoveAllItems() { BoundedStack <double> stack = null; "Given there is a bounded stack with items" .x(() => { stack = new BoundedStack <double>(); stack.Initialize(); // elements stack.Push(1); stack.Push(2); stack.Push(3); stack.Push(4); stack.Push(5); }); "When clear operation on this stack happens" .x(() => { stack.Clear(); }); "Then such stack must not have any elements" .x(() => { var count = stack.Size(); count.Should().Be(0); }); }
public void BoundedStackWithUserCapacityCanHaveNotGreaterItemsCount(int capacity) { BoundedStack <string> stack = null; $"Given there is a user's capacity bounded stack model with '{capacity}' capacity" .x(() => { stack = new BoundedStack <string>(); stack.Initialize(capacity); }); $"When user pushes '{2*capacity}' items into such bounded stack" .x(() => { for (int index = 0; index < 2 * capacity; index++) { stack.Push(index.ToString()); } }); $"Then bounded stack model should add only '{capacity}' items" .x(() => { stack.Size().Should().Be(capacity); }); }
public void WhenAfterErrorPopOperationHappensSuccessfulPopOperationSystemSetSuccessLastStatus() { BoundedStack <double> stack = null; "Given there is a empty bounded stack with last pop error status" .x(() => { stack = new BoundedStack <double>(); stack.Initialize(); // peek operation for empty stack set error status stack.Pop(); }); "When some item has been pushed" .x(() => { stack.Push(2); }); "And pop operation happens again" .x(() => { stack.Pop(); }); "Then last pop operation status should be 'OK'" .x(() => { var status = stack.GetPopStatus(); status.Should().Be(OpResult.OK); }); }
public void PeekOperationDoNotRemoveItemFromHeadPosition() { BoundedStack <double> stack = null; const double firstItem = 0.12; $"Given there is a bounded stack model with items {firstItem} 3.45 -23.02 11" .x(() => { stack = new BoundedStack <double>(); stack.Initialize(); stack.Push(firstItem); stack.Push(3.45); stack.Push(-23.02); stack.Push(11); }); "When peek operation happens" .x(() => { stack.Peek(); }); $"Then another stack's peek operation should return same item '{firstItem}'" .x(() => { var item = stack.Peek(); item.Should().Be(firstItem); }); }
public void MyTestInitialize() { my_stack = new Stack <DSString>(); my_b_stack = new BoundedStack <DSString>(MAX_STACK_ELEMENTS); addStackItems(my_stack); addStackItems(my_b_stack); }
private void testToString(BoundedStack <DSString> the_stack) { //just test for no exceptions, leave the output to the programmer, user try { the_stack.ToString(); } catch (Exception the_ex) { Assert.Fail(); } }
internal SessionStateInternal(SessionStateInternal parent, bool linkToGlobal, ExecutionContext context) { if (context == null) { throw PSTraceSource.NewArgumentNullException("context"); } ExecutionContext = context; // Create the working directory stack. This // is used for the pushd and popd commands _workingLocationStack = new Dictionary <String, Stack <PathInfo> >(StringComparer.OrdinalIgnoreCase); // Conservative choice to limit the Set-Location history in order to limit memory impact in case of a regression. const int locationHistoryLimit = 20; _SetLocationHistory = new BoundedStack <PathInfo>(locationHistoryLimit); GlobalScope = new SessionStateScope(null); ModuleScope = GlobalScope; _currentScope = GlobalScope; InitializeSessionStateInternalSpecialVariables(false); // Create the push the global scope on as // the starting script scope. That way, if you dot-source a script // that uses variables qualified by script: it works. GlobalScope.ScriptScope = GlobalScope; if (parent != null) { GlobalScope.Parent = parent.GlobalScope; // Copy the drives and providers from the parent... CopyProviders(parent); // During loading of core modules, providers are not populated. // We set the drive information later if (Providers != null && Providers.Count > 0) { CurrentDrive = parent.CurrentDrive; } // Link it to the global scope... if (linkToGlobal) { GlobalScope = parent.GlobalScope; } } else { _currentScope.LocalsTuple = MutableTuple.MakeTuple(Compiler.DottedLocalsTupleType, Compiler.DottedLocalsNameIndexMap); } }
public void UserCanNotInitializeStackWithNegativeCapacity() { Action func = null; "When user tries to initialize stack with negative capacity" .x(() => { var stack = new BoundedStack <int>(); func = () => stack.Initialize(-4); }); "Then system must generate exception" .x(() => { func.Should().Throw <ArgumentException>(); }); }
private void testBoundedStack(BoundedStack <DSString> the_b_stack) { //add the rest of 100 elements for (int i = 0; i < 90; i++) { the_b_stack.push(new DSString((i + 10).ToString())); } try { the_b_stack.push(new DSString((101).ToString())); Assert.Fail(); //fail if no exception is thrown } catch (StackOverflowException the_exception) { //good } }
public static void TestBoundedStack() { const int capacity = 20; var boundedStack = new BoundedStack <string>(capacity); Assert.Throws <InvalidOperationException>(() => boundedStack.Pop()); for (int i = 0; i < capacity; i++) { boundedStack.Push($"{i}"); } for (int i = 0; i < capacity; i++) { var poppedItem = boundedStack.Pop(); Assert.Equal($"{20 - 1 - i}", poppedItem); } Assert.Throws <InvalidOperationException>(() => boundedStack.Pop()); }
public void When_PeekAndPopOperationsHasNotBeenProcessedSystemGetStatusMustReturnNil() { BoundedStack <double> stack = null; "When new bounded stack has been created" .x(() => { stack = new BoundedStack <double>(); stack.Initialize(); }); "Then get peek and pop statuses must be 'Nil'" .x(() => { var popStatus = stack.GetPopStatus(); var peekStatus = stack.GetPeekStatus(); popStatus.Should().Be(OpResult.NIL); peekStatus.Should().Be(OpResult.NIL); }); }
public void PopCanRemoveItemFromNotEmptyStack() { BoundedStack <int> stack = null; "Given there is an default bounded stack model with 32 capacity" .x(() => { stack = new BoundedStack <int>(); stack.Initialize(); }); "And stack has items 5 4 3 2 8" .x(() => { stack.Push(5); stack.Push(4); stack.Push(3); stack.Push(2); stack.Push(8); }); "When pop operation happens" .x(() => { stack.Pop(); }); "Then peek operation should return 4" .x(() => { stack.Peek().Should().Be(4); }); "And last pop operation status should be 'OK'" .x(() => { stack.GetPopStatus().Should().Be(OpResult.OK); }); }
public void PeekOperationForEmptyStackSetPeekOperationResultToError() { BoundedStack <double> stack = null; $"Given there is a bounded stack model with no elements" .x(() => { stack = new BoundedStack <double>(); stack.Initialize(); }); "When peek operation happens" .x(() => { stack.Peek(); }); $"Then last peek operation result should be 'Error'" .x(() => { stack.GetPeekStatus().Should().Be(OpResult.ERROR); }); }
public void PopCanNotRemoveItemFromEmptyStack() { BoundedStack <int> stack = null; "Given there is a default bounded stack with no items" .x(() => { stack = new BoundedStack <int>(); stack.Initialize(); }); "When pop operation happens" .x(() => { stack.Pop(); }); "Then system should set last pop operation status to 'Error'" .x(() => { stack.GetPopStatus().Should().Be(OpResult.ERROR); }); }
public void PeekCanGetItemWhenStackIsNotEmpty() { BoundedStack <int> stack = null; // to assert var peekItem = 0; "Given there is a bounded stack model" .x(() => { stack = new BoundedStack <int>(); stack.Initialize(); }); "And this stack has 7 items: -2 3 5 1 0 -2 3 with first added item equal to -2" .x(() => { stack.Push(-2); stack.Push(3); stack.Push(5); stack.Push(1); stack.Push(0); stack.Push(-2); stack.Push(3); }); "When peek operation is requested" .x(() => { peekItem = stack.Peek(); }); "Then stack should represent -2" .x(() => { peekItem.Should().Be(-2); }); }
public void withZeroCapacityStack_TopShouldThrowEmptyException() { IStack stack = BoundedStack.Make(0); stack.top(); }
public void SetUp() { _boundedStack = BoundedStack.Make(CAPACITY); }
public void whenCreatingZeroCapacityStack_ShouldReturnEmptySize() { IStack stack = BoundedStack.Make(0); Assert.AreEqual(stack.getSize(), 0); }
public void whenCreatingStackWithIllegalCapacity_ShouldThrowIllegalCapacityException() { IStack stack = BoundedStack.Make(-1); }
public void initialize() { stack = BoundedStack.Make(2); }