Exemple #1
0
        public void DeleteDuplicatesTest()
        {
            var testp    = new ArrayQ();
            var testcase = new ListNode(1);
            var result   = testp.DeleteDuplicates(null);

            Assert.AreEqual(null, result);

            testcase = new ListNode(1)
            {
                next = new ListNode(1)
            };
            testcase.next.next = new ListNode(2);
            result             = testp.DeleteDuplicates(testcase);
            Assert.AreEqual("1 2", ArrayQTest.GetLinkedListItems(result));

            testcase = new ListNode(1)
            {
                next = new ListNode(1)
            };
            testcase.next.next           = new ListNode(2);
            testcase.next.next.next      = new ListNode(3);
            testcase.next.next.next.next = new ListNode(3);
            result = testp.DeleteDuplicates(testcase);
            Assert.AreEqual("1 2 3", ArrayQTest.GetLinkedListItems(result));

            testcase = new ListNode(1)
            {
                next = new ListNode(2)
            };
            testcase.next.next                = new ListNode(3);
            testcase.next.next.next           = new ListNode(1);
            testcase.next.next.next.next      = new ListNode(2);
            testcase.next.next.next.next.next = new ListNode(3);
            result = testp.DeleteDuplicates(testcase);
            Assert.AreEqual("1 2 3 1 2 3", ArrayQTest.GetLinkedListItems(result));

            testcase = new ListNode(1)
            {
                next = new ListNode(2)
            };
            testcase.next.next = new ListNode(2);
            result             = testp.DeleteDuplicates(testcase);
            Assert.AreEqual("1 2", ArrayQTest.GetLinkedListItems(result));

            testcase = new ListNode(1)
            {
                next = new ListNode(1)
            };
            testcase.next.next                = new ListNode(2);
            testcase.next.next.next           = new ListNode(3);
            testcase.next.next.next.next      = new ListNode(3);
            testcase.next.next.next.next.next = new ListNode(4);
            result = testp.DeleteDuplicates(testcase);
            Assert.AreEqual("1 2 3 4", ArrayQTest.GetLinkedListItems(result));

            testcase = new ListNode(1)
            {
                next = new ListNode(1)
            };
            result = testp.DeleteDuplicates(testcase);
            Assert.AreEqual("1", ArrayQTest.GetLinkedListItems(result));

            testcase = new ListNode(1)
            {
                next = new ListNode(1)
            };
            testcase.next.next = new ListNode(1);
            result             = testp.DeleteDuplicates(testcase);
            Assert.AreEqual("1", ArrayQTest.GetLinkedListItems(result));
        }