Exemple #1
0
        public static void Main()
        {
            //Please use the Unit test from 07-TestLinkedList project /provided by ttitto/

            var list = new SinglyLinkedLinkedList<int>();

            //list.Add(4);
            //list.Add(58);
            //list.Add(659816519);
            //list.Add(165965);
            //list.Add(659816519);
            //list.Add(165965);

            list.Add(4);
            list.Add(58);
            list.Add(659816519);
            list.Add(165965);

            list.Remove(0);

            foreach (var number in list)
            {
                Console.Write(number + " ");
            }

            Console.WriteLine();
            Console.WriteLine(list.FirstIndexOf(4));
            //Console.WriteLine(list.Count);
            //Console.WriteLine(list.FirstIndexOf(659816519));
            //Console.WriteLine(list.LastIndexOf(659816519));
            //Console.WriteLine(list.LastIndexOf(165965));
        }
        public void RemoveElementAtIndexZero()
        {
            var list = new SinglyLinkedLinkedList<int>();

            list.Add(4);
            list.Add(58);
            list.Add(659816519);
            list.Add(165965);

            list.Remove(0);

            Assert.AreEqual(3, list.Count, MESSAGE_COUNTNOTMATCHING);
            Assert.AreEqual(-1, list.FirstIndexOf(4), MESSAGE_FIRSTINDEXOF);
            Assert.AreEqual(2, list.FirstIndexOf(165965), MESSAGE_FIRSTINDEXOF);
            Assert.AreEqual(-1, list.LastIndexOf(4), MESSAGE_LASTINDEXOF);

            var expectedList = this.FillIntoList(list);
            CollectionAssert.AreEqual(expectedList, new List<int>() { 58, 659816519, 165965 }, "Elements' order is not correct.");
        }
        public void RemoveElementFromEmptyList()
        {
            var list = new SinglyLinkedLinkedList<int>();

            list.Remove(2);
        }
        public void RemovingTailShouldAllowCorrectAddingAfterwards()
        {
            var list = new SinglyLinkedLinkedList<int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);
            list.Add(6);
            list.Add(7);

            list.Remove(2);
            list.Remove(3);
            list.Remove(4);
            list.Add(8);
            list.Add(9);

            Assert.AreEqual(6, list.Count, MESSAGE_COUNTNOTMATCHING);

            var items = FillIntoList(list);
            CollectionAssert.AreEqual(new List<int>() { 1, 2, 4, 6, 8, 9 }, items, "Adding items after tail has been removed should work correctly.");
        }
        public void RemoveRepetitiveElementFromListWithRepetitions()
        {
            var list = new SinglyLinkedLinkedList<int>();

            list.Add(4);
            list.Add(58);
            list.Add(659816519);
            list.Add(165965);
            list.Add(659816519);
            list.Add(165965);

            list.Remove(2);

            Assert.AreEqual(5, list.Count, MESSAGE_COUNTNOTMATCHING);
            Assert.AreEqual(1, list.FirstIndexOf(58), MESSAGE_FIRSTINDEXOF);
            Assert.AreEqual(1, list.LastIndexOf(58), MESSAGE_LASTINDEXOF);
            Assert.AreEqual(3, list.FirstIndexOf(659816519), MESSAGE_FIRSTINDEXOF);
            Assert.AreEqual(3, list.LastIndexOf(659816519), MESSAGE_LASTINDEXOF);

            var expectedList = this.FillIntoList(list);
            CollectionAssert.AreEqual(expectedList, new List<int>() { 4, 58, 165965, 659816519, 165965 }, "Elements' order is not correct.");
        }