public void AddTwoNumbersProblemTest() { //342 var l1 = new ListNode(2) { next = new ListNode(4) { next = new ListNode(3) } }; //465 var l2 = new ListNode(5) { next = new ListNode(6) { next = new ListNode(4) } }; var solution = new AddTwoNumbersProblem(); var result = solution.AddTwoNumbers(l1, l2); Assert.Equal(7, result.val); Assert.Equal(0, result.next.val); Assert.Equal(8, result.next.next.val); Assert.Null(result.next.next.next); //342 l1 = new ListNode(2) { next = new ListNode(4) { next = new ListNode(3) } }; //465 l2 = new ListNode(5) { next = new ListNode(6) { next = new ListNode(4) { next = new ListNode(9) } } }; result = solution.AddTwoNumbers(l1, l2); Assert.Equal(7, result.val); Assert.Equal(0, result.next.val); Assert.Equal(8, result.next.next.val); Assert.Equal(9, result.next.next.next.val); Assert.Null(result.next.next.next.next); }
public void AddTwoNumbers_Basic() { AddTwoNumbersProblem.ListNode l1 = new(2, new(4, new(3))); AddTwoNumbersProblem.ListNode l2 = new(5, new(6, new(4))); AddTwoNumbersProblem addTwoNumbersProblem = new(); var result = addTwoNumbersProblem.AddTwoNumbers(l1, l2); result.Should().BeEquivalentTo(new AddTwoNumbersProblem.ListNode(7, new(0, new(8)))); }
public void AddTwoNumbers_Basic3() { AddTwoNumbersProblem.ListNode l1 = new(9, new(9, new(9, new(9, new(9, new(9, new(9))))))); AddTwoNumbersProblem.ListNode l2 = new(9, new(9, new(9, new(9)))); AddTwoNumbersProblem addTwoNumbersProblem = new(); var result = addTwoNumbersProblem.AddTwoNumbers(l1, l2); result.Should().BeEquivalentTo(new AddTwoNumbersProblem.ListNode(8, new(9, new(9, new(9, new(0, new(0, new(0, new(1))))))))); }
public void AddTwoNumbers_Case3() { // Arrange AddTwoNumbersProblem obj = new AddTwoNumbersProblem(); var l1 = ListNode.CreateListNode(9, 9, 9, 9, 9, 9, 9); var l2 = ListNode.CreateListNode(9, 9, 9, 9); var expected = ListNode.CreateListNode(8, 9, 9, 9, 0, 0, 0, 1); // Act var actual = obj.AddTwoNumbers(l1, l2); // Assert Assert.Equal(expected, actual); }
public void AddTwoNumbers_Case1() { // Arrange AddTwoNumbersProblem obj = new AddTwoNumbersProblem(); var l1 = ListNode.CreateListNode(2, 4, 3); var l2 = ListNode.CreateListNode(5, 6, 4); var expected = ListNode.CreateListNode(7, 0, 8); // Act var actual = obj.AddTwoNumbers(l1, l2); // Assert Assert.Equal(expected, actual); }