コード例 #1
0
        public void Example3_Can_handle_list_of_one()
        {
            var helper   = new LinkedListHelper();
            var list     = helper.CreateSinglyLinkedList(new int[] { 1 });
            var expected = helper.CreateSinglyLinkedList(new int[] { 1 });
            var sut      = new Solution();

            var actual = sut.ReverseList(list);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #2
0
        public void RemoveElements_NullList_ReturnsNewHead()
        {
            var      sut        = new Solution();
            ListNode input_head = null;
            var      input_val  = 0;
            ListNode expected   = null;

            var actual = sut.RemoveElements(input_head, input_val);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #3
0
        public void InserstionSortList_Example2()
        {
            var sut      = new Solution();
            var helper   = new LinkedListHelper();
            var input    = helper.CreateSinglyLinkedList(new int[] { -1, 5, 3, 4, 0 });
            var expected = helper.CreateSinglyLinkedList(new int[] { -1, 0, 3, 4, 5 });

            var actual = sut.InsertionSortList(input);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #4
0
        public void Example2_Can_reverse_short_list()
        {
            var helper   = new LinkedListHelper();
            var list     = helper.CreateSinglyLinkedList(new int[] { 1, 2 });
            var expected = helper.CreateSinglyLinkedList(new int[] { 2, 1 });
            var sut      = new Solution();

            var actual = sut.ReverseList(list);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #5
0
        public void OddEvenList_TwoItemList_ReturnsListOddEven()
        {
            var sut        = new Solution();
            var helper     = new LinkedListHelper();
            var input_list = helper.CreateSinglyLinkedList(new int[] { 1, 2 });
            var expected   = helper.CreateSinglyLinkedList(new int[] { 1, 2 });

            var actual = sut.OddEvenList(input_list);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #6
0
        public void MergeTwoLists_CanMergeIfAListIsEmpty()
        {
            var sut       = new Solution();
            var helper_ll = new LinkedListHelper();
            var input_l1  = helper_ll.CreateSinglyLinkedList(new int[] { });
            var input_l2  = helper_ll.CreateSinglyLinkedList(new int[] { 1 });
            var expected  = helper_ll.CreateSinglyLinkedList(new int[] { 1 });

            var actual = sut.MergeTwoLists(input_l1, input_l2);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #7
0
        public void RemoveElements_AllItemsNeedRemoving_Null()
        {
            var      sut        = new Solution();
            var      helper     = new LinkedListHelper();
            var      input_head = helper.CreateSinglyLinkedList(new int[] { 1, 1, 1, 1, 1, 1 });
            var      input_val  = 1;
            ListNode expected   = null;

            var actual = sut.RemoveElements(input_head, input_val);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #8
0
        public void RemoveElements_ItemAtEnd_RemoveEnd()
        {
            var sut        = new Solution();
            var helper     = new LinkedListHelper();
            var input_head = helper.CreateSinglyLinkedList(new int[] { 1, 2, 3, 4, 5, 6 });
            var input_val  = 6;
            var expected   = helper.CreateSinglyLinkedList(new int[] { 1, 2, 3, 4, 5 });

            var actual = sut.RemoveElements(input_head, input_val);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #9
0
        public void RemoveElements_RemoveMultipleInMiddle_ReturnsNewList()
        {
            var sut        = new Solution();
            var helper     = new LinkedListHelper();
            var input_head = helper.CreateSinglyLinkedList(new int[] { 1, 4, 2, 3, 4, 5, 6 });
            var input_val  = 4;
            var expected   = helper.CreateSinglyLinkedList(new int[] { 1, 2, 3, 5, 6 });

            var actual = sut.RemoveElements(input_head, input_val);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #10
0
        public void Test_Can_add_one_to_999999_to_make_a_million()
        {
            var helper   = new LinkedListHelper();
            var input1   = helper.CreateSinglyLinkedList(new int[] { 1 });
            var input2   = helper.CreateSinglyLinkedList(new int[] { 9, 9, 9, 9, 9, 9 });
            var expected = helper.CreateSinglyLinkedList(new int[] { 1, 0, 0, 0, 0, 0, 0 });
            var sut      = new Solution();

            var actual = sut.AddTwoNumbers(input1, input2);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #11
0
        public void Example3_Can_add_two_zeroes()
        {
            var helper   = new LinkedListHelper();
            var input1   = helper.CreateSinglyLinkedList(new int[] { 0 });
            var input2   = helper.CreateSinglyLinkedList(new int[] { 0 });
            var expected = helper.CreateSinglyLinkedList(new int[] { 0 });
            var sut      = new Solution();

            var actual = sut.AddTwoNumbers(input1, input2);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #12
0
        public void Example2_Can_add_two_numbers_of_same_length()
        {
            var helper   = new LinkedListHelper();
            var input1   = helper.CreateSinglyLinkedList(new int[] { 2, 4, 3 });
            var input2   = helper.CreateSinglyLinkedList(new int[] { 5, 6, 4 });
            var expected = helper.CreateSinglyLinkedList(new int[] { 8, 0, 7 });
            var sut      = new Solution();

            var actual = sut.AddTwoNumbers(input1, input2);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #13
0
        public void RemoveElement_ListWhereEveryItemNeedsRemoval_ReturnsNull()
        {
            var helper     = new LinkedListHelper();
            var sut        = new Solution();
            var input_head = helper.CreateSinglyLinkedList(new int[] { 7, 7, 7, 7 });
            var input_val  = 7;
            var expected   = helper.CreateSinglyLinkedList(new int[] { });

            var actual = sut.RemoveElements(input_head, input_val);

            AssertLinkedList.AreEqualValue(expected, actual);
        }
コード例 #14
0
        public void MergeKLists_CanMergeLists()
        {
            var helper = new LinkedListHelper();
            var sut    = new Solution();
            var input  = new ListNode[]
            {
                helper.CreateSinglyLinkedList(new int[] { 1, 4, 5 }),
                helper.CreateSinglyLinkedList(new int[] { 1, 3, 4 }),
                helper.CreateSinglyLinkedList(new int[] { 2, 6 }),
            };
            var expected = helper.CreateSinglyLinkedList(new int[] { 1, 1, 2, 3, 4, 4, 5, 6, });

            var actual = sut.MergeKLists(input);

            AssertLinkedList.AreEqualValue(expected, actual);
        }