Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gardncl committed Apr 16, 2017
2 parents 219fc6a + 5463d49 commit 9e8cf78
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
6 changes: 6 additions & 0 deletions src/linkedlists/AddIntegers.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

public class AddIntegers {

/*
Write a program which takes two singly linked lists of digits,
and returns the list corresponding to the sum of the integers
they represent. The least significant digit comes first.
*/

public static ListNode<Integer> addIntegers(ListNode<Integer> a, ListNode<Integer> b) {

return new ListNode<>(null);
Expand Down
12 changes: 6 additions & 6 deletions test/linkedlists/AddIntegersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ void addIntegers1() {

@Test
void addIntegers2() {
sum = createLinkedList(1, 0, 0);
a = createLinkedList(1, 0, 0);
b = createLinkedList(0);
sum = createLinkedList(4, 2, 0, 1);
a = createLinkedList(2, 1, 5);
b = createLinkedList(2, 1, 5);

test(sum, a, b);
}

@Test
void addIntegers3() {
sum = createLinkedList(1, 0, 2, 4);
a = createLinkedList(5, 1, 2);
b = createLinkedList(5 ,1, 2);
sum = createLinkedList(1, 0, 0, 1);
a = createLinkedList(1, 0, 0, 0);
b = createLinkedList(0, 0, 0, 1);

test(sum, a, b);
}
Expand Down
22 changes: 11 additions & 11 deletions test/linkedlists/FindOverlappingWithCyclesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ void testOverlappingWithCycles1() {
void testOverlappingWithCycles2() {
list1 = createLinkedList(1, 2);
list2 = createLinkedList(1, 2, 3, 4, 5);
list1.get(2).next = list2.get(3);
overlap = createLinkedList(2, 3);

overlap = list1.get(2).next = list2.get(3);

test(overlap, list1, list2);
}
Expand All @@ -39,7 +37,6 @@ void testOverlappingWithCycles3() {
list2 = createLinkedList(2, 3, 4, 5);
overlap = list1.get(2).next = list2.get(2);


test(overlap, list1, list2);
}

Expand All @@ -51,27 +48,30 @@ void testOverlappingWithCycles4() {
list2.get(5).next = list2.get(1);
overlap = createLinkedList(2, 3);


test(overlap, list1, list2);
}

@Test
void testOverlappingWithCycles5() {
list1 = createLinkedList(3, 4);
list1 = createLinkedList(1, 2, 3, 4, 5);
list1.get(5).next = list1.get(1);
list2 = createLinkedList(1, 2, 3, 4, 5);
list1.get(2).next = list2.get(5);
list2.get(5).next = list2.get(1);
overlap = createLinkedList(4, 5);

overlap = null;

test(overlap, list1, list2);
}

private void test(ListNode<Integer> overlap, ListNode<Integer> list1, ListNode<Integer> list2) {
ListNode<Integer> result = testOverlappingWithCycles(list1, list2);
assertEquals(overlap.data, result.data);
if (overlap.next != null)
if (overlap == null)
assertNull(result);
else if (overlap.next != null) {
assertNotNull(result);
assertEquals(overlap.data, result.data);
assertEquals(overlap.next.data, result.next.data);
}

}

}
12 changes: 6 additions & 6 deletions test/linkedlists/ListPivotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ void pivot1() {

@Test
void pivot2() {
expected = createLinkedList(3, 3, 3, 2, 2, 2, 1, 1, 1);
input = createLinkedList(2, 2, 3, 3, 3, 2, 1, 1, 1);
k = 4;
expected = createLinkedList(1, 1, 1, 3, 3, 3, 2, 2, 2);
input = createLinkedList(3, 3, 3, 2, 2, 2, 1, 1, 1);
k = 1;

test(expected, input, k);
}

@Test
void pivot3() {
expected = createLinkedList(3, 3, 3, 2, 2, 2, 1, 1, 1);
input = createLinkedList(1, 1, 1, 2, 2, 2, 3, 3, 3);
k = 8;
expected = createLinkedList(1, 1, 1, 2, 2, 2, 3, 3, 3);
input = createLinkedList(3, 3, 3, 2, 2, 2, 1, 1, 1);
k = 2;

test(expected, input, k);
}
Expand Down

0 comments on commit 9e8cf78

Please sign in to comment.