public void MyLinkedList_5_Insert_01_ThrowsExceptionOnIndexTooLowOnEmptyList()
        {
            // Arrange
            IMyLinkedList <string> lst = DSBuilder.CreateMyLinkedList();

            // Act & Assert
            Assert.Throws(typeof(MyLinkedListIndexOutOfRangeException), () => lst.Insert(-1, "1"));
        }
Example #2
0
        public void MyLinkedList_5_Insert_04_ThrowsExceptionOnIndexTooHighOnList3()
        {
            // Arrange
            IMyLinkedList <string> lst = DSBuilder.CreateMyLinkedList();

            lst.AddFirst("1");
            lst.AddFirst("2");
            lst.AddFirst("3");

            // Act & Assert
            Assert.Throws(typeof(MyLinkedListIndexOutOfRangeException), () => lst.Insert(4, "4"));
        }
Example #3
0
        public void MyLinkedList_5_Insert_06_GetFirstOkAfterInsertAtBeginningOnEmptyList()
        {
            // Arrange
            IMyLinkedList <string> lst = DSBuilder.CreateMyLinkedList();
            string expected            = "1";

            // Act
            lst.Insert(0, "1");
            string actual = lst.GetFirst();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #4
0
        public void MyLinkedList_5_Insert_05_SizeEquals1AfterInsertAtBeginningOnEmptyList()
        {
            // Arrange
            IMyLinkedList <string> lst = DSBuilder.CreateMyLinkedList();
            int expected = 1;

            // Act
            lst.Insert(0, "1");
            int actual = lst.Size();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #5
0
        public void MyLinkedList_5_Insert_13_GetFirstOkAfterInsertInMiddleOnList3()
        {
            // Arrange
            IMyLinkedList <string> lst = DSBuilder.CreateMyLinkedList();

            lst.AddFirst("1");
            lst.AddFirst("2");
            lst.AddFirst("3");
            string expected = "3";

            // Act
            lst.Insert(1, "4");
            string actual = lst.GetFirst();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #6
0
        public void MyLinkedList_5_Insert_12_SizeEquals4AfterInsertInMiddleOnList3()
        {
            // Arrange
            IMyLinkedList <string> lst = DSBuilder.CreateMyLinkedList();

            lst.AddFirst("1");
            lst.AddFirst("2");
            lst.AddFirst("3");
            int expected = 4;

            // Act
            lst.Insert(1, "4");
            int actual = lst.Size();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #7
0
        public void MyLinkedList_6_ToString_4_VariousOperations2()
        {
            // Arrange
            IMyLinkedList <string> lst = DSBuilder.CreateMyLinkedList();

            lst.AddFirst("1");
            lst.AddFirst("2");
            lst.Insert(1, "4");
            lst.RemoveFirst();

            string expected = "[4,1]";

            // Act
            string actual = lst.ToString();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #8
0
        public void MyLinkedList_5_Insert_11_GetLastOkAfterInsertAtEndOnList3()
        {
            // Arrange
            IMyLinkedList <string> lst = DSBuilder.CreateMyLinkedList();

            lst.AddFirst("1");
            lst.AddFirst("2");
            lst.AddFirst("3");
            string expected = "4";

            // Act
            lst.Insert(3, "4");
            lst.RemoveFirst();
            lst.RemoveFirst();
            lst.RemoveFirst();
            string actual = lst.GetFirst();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #9
0
        static void LinkedList()
        {
            System.Console.WriteLine("\n=====   MyLinkedList   =====\n");

            IMyLinkedList <string> lst = DSBuilder.CreateMyLinkedList();

            lst.AddFirst("1");
            lst.AddFirst("2");
            lst.AddFirst("3");
            lst.Insert(0, "0");

            Console.WriteLine(lst.ToString());

            MyLinkedList <string> ll = new MyLinkedList <string>();

            System.Console.WriteLine(ll);
            ll.AddFirst("a");
            ll.AddFirst("b");
            ll.AddFirst("c");
            ll.Insert(2, "x");
            System.Console.WriteLine(ll);
            try
            {
                ll.Insert(4, "kan niet");
            }
            catch (MyLinkedListIndexOutOfRangeException e)
            {
                System.Console.WriteLine(e.Message);
            }

            ll.Clear();
            ll.AddFirst("a");
            ll.AddFirst("b");
            System.Console.WriteLine(ll.GetFirst());
            ll.RemoveFirst();
            System.Console.WriteLine(ll);
            ll.RemoveFirst();
            System.Console.WriteLine(ll);
        }