Example #1
0
        public void CannotPeekEmptyLocked_Peek_Test()
        {
            //  Arrange
            var stack = new UncheckedLayeredStack <string>();

            stack.Push("p");
            stack.Push("q");
            stack.Lock();
            //  Assert
            stack.Peek();   // No exceptio thrown - unchecked.
        }
Example #2
0
        public void CannotPopEmptyLocked_Pop_Test()
        {
            //  Arrange
            var stack = new UncheckedLayeredStack <string>();

            stack.Push("p");
            stack.Push("q");
            stack.Lock();
            //  Assert
            stack.Pop();    //  Does not throw an exception. Unchecked.
        }
Example #3
0
        public void CanUnlock_Unlock_Test()
        {
            //  Arrange
            var stack = new UncheckedLayeredStack <string>();

            stack.Push("p");
            stack.Push("q");
            stack.Lock();
            //  Act
            stack.Unlock();
            //  Assert
            Assert.Equal(0, stack.LockCount());
            Assert.Equal(2, stack.Size());
        }
Example #4
0
        public void Simple_PeekAndPeekItem_Test()
        {
            //  Arrange
            var stack = new UncheckedLayeredStack <string>();

            //  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);
        }
Example #5
0
        public void Index2Stack_Indexer_Test()
        {
            //  Arrange
            var stack = new UncheckedLayeredStack <string>();

            stack.Push("a");
            stack.Push("b");
            //  Act
            var a = stack[0];
            var b = stack[1];

            //  Assert
            Assert.Equal("a", a);
            Assert.Equal("b", b);
        }
Example #6
0
        public void StartsEmptyLocked_IsEmpty_Test()
        {
            //  Arrange
            var stack = new UncheckedLayeredStack <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);
        }
Example #7
0
        public void CanPeekOrElseEmptyLocked_PeekOrElse_Test()
        {
            //  Arrange
            var stack = new UncheckedLayeredStack <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);
        }
Example #8
0
        public void SimplePop_Pop_Test()
        {
            //  Arrange
            var stack = new UncheckedLayeredStack <string>();

            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);
        }