示例#1
0
        public void ShouldThrowExceptionWhenPushOnExceededSize()
        {
            var cut = new ListBasedStackImplementation <int>(1);

            cut.Push(3);
            cut.Push(12);
        }
示例#2
0
        public void ShouldReturnDifferentSizeWhenPush()
        {
            var cut   = new ListBasedStackImplementation <int>(10);
            var items = new List <int> {
                18, 5, -6, 36, 48
            };

            for (int i = 0; i < items.Count; i++)
            {
                cut.Push(items[i]);
                Assert.AreEqual(i + 1, cut.CurrentSize);
            }
        }
示例#3
0
        public void ShouldReturnSameSizeWhenPeek()
        {
            var cut   = new ListBasedStackImplementation <int>(10);
            var items = new List <int> {
                18, 5, -6, 36, 48
            };

            items.ForEach(item => cut.Push(item));

            foreach (var item in items)
            {
                Assert.AreEqual(items.Last(), cut.Peek());
                Assert.AreEqual(items.Count, cut.CurrentSize);
            }
        }
示例#4
0
        public void ShouldReturnItemsInRevertedOrderThanWasInserted()
        {
            var items = new List <int> {
                18, 5, -6, 36, 48
            };
            var expectedList = new List <int>(items);

            expectedList.Reverse();

            var cut = new ListBasedStackImplementation <int>(items.Capacity);


            items.ForEach(item => cut.Push(item));

            expectedList.ForEach(expectedItem => { Assert.AreEqual(expectedItem, cut.Pop()); });
        }
示例#5
0
        public void ShouldReturnDifferentSizeWhenPop()
        {
            var cut   = new ListBasedStackImplementation <int>(10);
            var items = new List <int> {
                18, 5, -6, 36, 48
            };

            items.ForEach(item => cut.Push(item));

            var size = cut.CurrentSize;

            do
            {
                cut.Pop();
                size--;
                Assert.AreEqual(size, cut.CurrentSize);
            }while (size > 0);
        }