public void CannotPopEmptyLocked_Pop_Test() { // Arrange var stack = new CheckedLayeredStack <string>(); stack.Push("p"); stack.Push("q"); stack.Lock(); // Assert Assert.Throws <NutmegException>(() => stack.Pop()); }
public void CanUnlock_Unlock_Test() { // Arrange var stack = new CheckedLayeredStack <string>(); stack.Push("p"); stack.Push("q"); stack.Lock(); // Act stack.Unlock(); // Assert Assert.Equal(0, stack.LockCount()); Assert.Equal(2, stack.Size()); }
public void StartsEmptyLocked_IsEmpty_Test() { // Arrange var stack = new CheckedLayeredStack <string>(); stack.Push("p"); stack.Push("q"); stack.Lock(); // Act var isEmpty = stack.IsEmpty(); var k = stack.LockCount(); // Assert Assert.True(isEmpty); Assert.Equal(1, k); }
public void CanPeekOrElseEmptyLocked_PeekOrElse_Test() { // Arrange var stack = new CheckedLayeredStack <string>(); stack.Push("p"); stack.Push("q"); stack.Lock(); var arbitrary = "foobar"; // Act var x = stack.PeekOrElse(orElse: arbitrary); var y = stack.PeekItemOrElse(0, orElse: arbitrary); // Assert Assert.Equal(arbitrary, x); Assert.Equal(arbitrary, y); }
public void SimpleLocked_PeekAndPeekItem_Test() { // Arrange var stack = new CheckedLayeredStack <string>(); stack.Push("p"); stack.Push("q"); stack.Lock(); // Act stack.Push("a"); stack.Push("b"); var b = stack.Peek(); var a = stack.PeekItem(1); // Assert Assert.Equal("b", b); Assert.Equal("a", a); }
public void UncheckedLayeredStack() { // Arrange var stack = new CheckedLayeredStack <string>(); // Act stack.Lock(); // Assert Assert.True(stack.IsEmpty()); Assert.Equal(1, stack.LockCount()); // Act stack.Unlock(); // Assert Assert.True(stack.IsEmpty()); Assert.Equal(0, stack.LockCount()); // Assert Assert.Throws <NutmegException>(() => stack.Unlock()); }
public void SimplePopLocked_Pop_Test() { // Arrange var stack = new CheckedLayeredStack <string>(); stack.Push("p"); stack.Push("q"); stack.Lock(); stack.Push("a"); stack.Push("b"); // Act var b = stack.Pop(); var a = stack.Pop(); // Assert Assert.True(stack.IsEmpty()); Assert.Equal(0, stack.Size()); Assert.Equal("b", b); Assert.Equal("a", a); }
public void Simple_RawLock_Test() { // Arrange var vstack = new CheckedLayeredStack <string>(); vstack.Lock(); vstack.Push("a"); vstack.Push("b"); var cstack = new UncheckedLayeredStack <string>(); // Act cstack.RawLock(4, vstack); // Assert Assert.Equal(1, vstack.LockCount()); Assert.Equal(0, vstack.Size()); Assert.Equal(1, cstack.LockCount()); Assert.Equal(4, cstack.Size()); Assert.Equal("a", cstack[0]); Assert.Equal("b", cstack[1]); Assert.Null(cstack[2]); Assert.Null(cstack[3]); }