Пример #1
0
        public void TestRemoveNthFromEnd(int[] list, int n, int[] expected)
        {
            var linkedListProblems = new LinkedListProblems();
            var expectedResults    = SingleLinkedListNode.GenerateList(expected);
            var input = SingleLinkedListNode.GenerateList(list);

            var actualResults = linkedListProblems.RemoveNthFromEnd(input, n);

            Assert.True(SingleLinkedListNode.AreListsEqual(expectedResults, actualResults));
        }
Пример #2
0
        public void TestReverseListRecursion(int[] list, int[] expectedOutput)
        {
            var linkedListProblems = new LinkedListProblems();

            var input           = SingleLinkedListNode.GenerateList(list);
            var expectedResults = SingleLinkedListNode.GenerateList(expectedOutput);

            var actualResults = linkedListProblems.ReverseListRecursion(input);

            Assert.True(SingleLinkedListNode.AreListsEqual(expectedResults, actualResults));
        }
Пример #3
0
        public void TestMergeTwoLists(int[] num1, int[] num2, int[] expectedNum)
        {
            var l1 = SingleLinkedListNode.GenerateList(num1);
            var l2 = SingleLinkedListNode.GenerateList(num2);
            var expectedResults    = SingleLinkedListNode.GenerateList(expectedNum);
            var linkedListProblems = new LinkedListProblems();

            var actualResults = linkedListProblems.MergeTwoLists(l1, l2);

            Assert.NotNull(expectedResults);
            Assert.True(SingleLinkedListNode.AreListsEqual(expectedResults, actualResults));
        }
Пример #4
0
        public void TestMergeKListsBruteForce()
        {
            var linkedListProblems = new LinkedListProblems();

            var inputs = new int[3][] { new int[3] {
                                            1, 4, 5
                                        }, new int[3] {
                                            1, 3, 4
                                        }, new int[2] {
                                            2, 6
                                        } };
            var expectedResults = SingleLinkedListNode.GenerateList(new int[] { 1, 1, 2, 3, 4, 4, 5, 6 });

            SingleLinkedListNode[] lists = new SingleLinkedListNode[]
            {
                SingleLinkedListNode.GenerateList(inputs[0]),
                SingleLinkedListNode.GenerateList(inputs[1]),
                SingleLinkedListNode.GenerateList(inputs[2]),
            };

            var actualResults = linkedListProblems.MergeKListsBruteForce(lists);

            Assert.True(SingleLinkedListNode.AreListsEqual(expectedResults, actualResults));
        }