Exemple #1
0
        public void Pop_1()
        {
            var ii = new IntList(10);

            ii.Push(1);
            ii.Push(7);
            ii.Push(3);
            ii.Push(2);

            Assert.AreEqual(2, ii.Pop());
            Assert.AreEqual(3, ii.Pop());
            Assert.AreEqual(7, ii.Pop());
            Assert.AreEqual(1, ii.Pop());
        }
        public void GivenAnEmptyList_WhenCallAddMultipleTimes_ThenCallPopWithIndexReturnCorrectItem()
        {
            IntList l = new IntList();

            l.Add(1);
            l.Add(2);
            l.Add(3);
            l.Add(4);
            l.Add(5);
            Assert.Equal(5, l.Count);
            Assert.Equal(1, l.Pop(0));
            Assert.Equal(4, l.Count);
            Assert.Equal(2, l.Pop(0));
            Assert.Equal(3, l.Count);
        }
        public void GivenAnEmptyList_WhenCallAppend_ThenCallPopReturnAppendedItem()
        {
            IntList l = new IntList();

            l.Add(5);
            Assert.Equal(5, l.Pop());
        }
        public void GivenAPopulatedList_WhenCallPopWithInvalidIndex_ThenThrowEmptyListException()
        {
            IntList l = new IntList();

            l.Add(1);
            l.Add(2);
            l.Add(3);
            Assert.Throws <InvalidListIndexException>(() => l.Pop(10));
        }
        public void GivenAnEmptyList_WhenCallAppendMultipleTimes_ThenCallPopReturnAppendedItemsInReverseOrder()
        {
            IntList l = new IntList();

            l.Add(1);
            l.Add(2);
            l.Add(3);
            l.Add(4);
            l.Add(5);
            Assert.Equal(5, l.Count);
            Assert.Equal(5, l.Pop());
            Assert.Equal(4, l.Count);
            Assert.Equal(4, l.Pop());
            Assert.Equal(3, l.Count);
            Assert.Equal(3, l.Pop());
            Assert.Equal(2, l.Count);
            Assert.Equal(2, l.Pop());
            Assert.Equal(1, l.Count);
            Assert.Equal(1, l.Pop());
            Assert.Equal(0, l.Count);
            Assert.Throws <EmptyListException>(() => l.Pop());
        }
        public void GivenAnEmptyList_WhenCallPopWithIndex_ThenThrowEmptyListException()
        {
            IntList l = new IntList();

            Assert.Throws <EmptyListException>(() => l.Pop(1));
        }