public void should_throw_when_pop_from_empty() { IStack <int> stack = new Services.Stack <int>(); Action act = () => stack.Pop(); act.Should().Throw <InvalidOperationException>(); }
public void should_still_contain_items_after_trypop() { IStack <int> stack = new Services.Stack <int>(); stack.Push(321); int popped; stack.TryPop(out popped); Action act = () => stack.Pop(); act.Should().NotThrow(); }
public void should_be_empty_after_popping_all_items() { IStack <string> stack = new Services.Stack <string>(); var items = new[] { "Alpha", "Bravo", "Charlie", "Delta" }; foreach (string s in items) { stack.Push(s); } for (int i = 0; i < items.Length; i++) { stack.Pop(); } stack.Invoking(s => s.Pop()).Should().Throw <InvalidOperationException>(); }
public void should_pop_items_correctly(int itemCount) { IStack <int> stack = new Services.Stack <int>(); int[] range = Enumerable.Range(1, itemCount).ToArray(); int[] expected = range.Reverse().ToArray(); foreach (int i in range) { stack.Push(i); } var actual = new int[range.Length]; int index = 0; foreach (int _ in range) { actual[index++] = stack.Pop(); } actual.Should().BeEquivalentTo(expected); }