コード例 #1
0
ファイル: Test_2_1.cs プロジェクト: jkrez/Interview
        public void Question_2_1_BasicCases()
        {
            // No duplicates
            var l1       = ListHelpers.CreateLinkedList(1, 2, 3);
            var expected = ListHelpers.CloneList(l1);

            this.ValidateResult(expected, l1);

            // Several (3x) duplicates
            var l2 = ListHelpers.CreateLinkedList(1, 1, 1);

            expected = ListHelpers.CreateLinkedList(1);
            this.ValidateResult(expected, l2);

            // two sets of duplicates, one next to each other one separated
            var l3 = ListHelpers.CreateLinkedList(1, 2, 2, 1);

            expected = ListHelpers.CreateLinkedList(1, 2);
            this.ValidateResult(expected, l3);

            // 3x duplicate case split up
            var l4 = ListHelpers.CreateLinkedList(1, 2, 2, 3, 2);

            expected = ListHelpers.CreateLinkedList(1, 2, 3);
            this.ValidateResult(expected, l4);

            // Several duplicates in the list
            var l5 = ListHelpers.CreateLinkedList(1, 2, 2, 1, 3, 4, 7, 5, 6, 2, 3, 4, 5, 6);

            expected = ListHelpers.CreateLinkedList(1, 2, 3, 4, 7, 5, 6);
            this.ValidateResult(expected, l5);
        }
コード例 #2
0
            private void ValidateResult <T>(Node <T> expected, Node <T> input, int k)
                where T : IEquatable <T>
            {
                var inputCopy  = ListHelpers.CloneList(input);
                var inputCopy2 = ListHelpers.CloneList(input);

                Assert.AreEqual(expected, Question_2_2.ReturnKthToLast(inputCopy, k));
            }
コード例 #3
0
ファイル: Test_2_1.cs プロジェクト: jkrez/Interview
        private void ValidateResult <T>(Node <T> expected, Node <T> input)
            where T : IEquatable <T>
        {
            var inputCopy  = ListHelpers.CloneList(input);
            var inputCopy2 = ListHelpers.CloneList(input);

            Question_2_1.RemoveDuplicates(inputCopy);
            ListHelpers.ValidateLinkedListContent(expected, inputCopy);
            Question_2_1.RemoveDuplicatesNoSpace(input);
            ListHelpers.ValidateLinkedListContent(expected, input);
            Question_2_1.RemoveDuplicatesNoSpace2(inputCopy2);
            ListHelpers.ValidateLinkedListContent(expected, input);
        }
コード例 #4
0
            public void Question_2_2_BasicCases()
            {
                // Cover all case for K for a list of length 6.
                const int NumberElements = 6;

                var list = ListHelpers.CreateLinkedList(Enumerable.Range(0, NumberElements).Reverse().ToArray());

                for (var i = 0; i < NumberElements; i++)
                {
                    var listCopy = ListHelpers.CloneList(list);
                    var result   = Question_2_2.ReturnKthToLast(listCopy, i);
                    Assert.AreEqual(i, result);
                }
            }
コード例 #5
0
ファイル: Test_2_1.cs プロジェクト: jkrez/Interview
        public void Question_2_1_EdgeCases()
        {
            // 1 => 1 - Only one element.
            var l1       = ListHelpers.CreateLinkedList(1);
            var expected = ListHelpers.CloneList(l1);

            this.ValidateResult(expected, l1);

            // 1, 1 => 1 - Only duplicate elements
            var l2 = ListHelpers.CreateLinkedList(1, 1);

            expected = ListHelpers.CreateLinkedList(1);
            this.ValidateResult(expected, l2);

            // 1, 2, 2 => 1, 2 - Last element duplicated
            var l3 = ListHelpers.CreateLinkedList(1, 2, 2);

            expected = ListHelpers.CreateLinkedList(1, 2);
            this.ValidateResult(expected, l3);
        }