From 24c9318c9bedfecd72280414c610ad200ae01f8b Mon Sep 17 00:00:00 2001 From: Dee Date: Thu, 22 Jul 2021 23:45:26 -0400 Subject: [PATCH 1/5] up to sort and reverse --- .idea/compiler.xml | 2 + .idea/jarRepositories.xml | 20 ++ .idea/modules.xml | 1 + .idea/workspace.xml | 325 ++++-------------- .../singlylinkedlist/SinglyLinkedList.java | 107 ++++++ 5 files changed, 193 insertions(+), 262 deletions(-) create mode 100644 .idea/jarRepositories.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 4be381c..a07d5fa 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -6,11 +6,13 @@ + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index ad4fefc..8b9083f 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,6 +3,7 @@ + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b6d36bd..fa0d859 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,86 +1,21 @@ + + - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -212,60 +148,19 @@ + + - + + - - - + - - - - - - - - - - - + @@ -494,12 +290,17 @@ - - - - - + + + diff --git a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java index 2fb3165..9543fb8 100644 --- a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java +++ b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java @@ -1,7 +1,114 @@ package com.zipcodewilmington.singlylinkedlist; +import javax.xml.soap.Node; +import java.util.List; + /** * Created by leon on 1/10/18. */ public class SinglyLinkedList { + + class Node { + String data; + Node next; + + public Node(String data) { + this.data = data; + this.next = null; + } + } + + public Node head = null; + public Node tail = null; + + public void addNode(String data){ + Node newNode = new Node (data); + if (head == null){ + head = newNode; + } else { + tail.next =newNode; + } + tail = newNode; + } + + public int size() { + int length = 0; + Node current = head; + + if (current.next != null){ + length++; + } + return length; + } + + public void remove(String data) { + Node current = head; + if (current == null){ + throw new UnsupportedOperationException("No list here, smart guy"); + } + while (current != null){ + if (current.data == data){ + current.data = null; + } + current = current.next; + } + } + + public Boolean contains(String data){ + Node current = head; + if (head == null){ + throw new UnsupportedOperationException("No list again fool!"); + } + while(current != null){ + if (current.data == data){ + return true; + } + } + return false; + } + public int find (String data) { + Node current = head; + int index = 0; + if (head == null) { + throw new UnsupportedOperationException("Got ya again!"); + } + while (current != null){ + if (current.data == data){ + return index; + } + index++; + current = current.next; + } + return -1; + } + + public String get (int index) { + Node current = head; + int trackIndex = 0; + if (head == null || index > size() || index <0) { + throw new UnsupportedOperationException("THERE'S NO LIST"); + } + while (current != null){ + if (trackIndex ==index){ + return current.data; + } + trackIndex++; + current = current.next; + } + return null; + } + + public SinglyLinkedList copy() { + SinglyLinkedList copied = new SinglyLinkedList(); + + Node current = head; + if (head ==null) { + throw new UnsupportedOperationException("Nick proved this would happen"); + } + while (current != null){ + copied.addNode(current.data); + current = current.next; + } + return copied; + } } From b67b9f79fb6b9867e9571725796d9b9cd769ab08 Mon Sep 17 00:00:00 2001 From: Dee Date: Thu, 22 Jul 2021 23:58:17 -0400 Subject: [PATCH 2/5] reversed success --- .../singlylinkedlist/SinglyLinkedList.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java index 9543fb8..98eb3e6 100644 --- a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java +++ b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java @@ -111,4 +111,17 @@ public SinglyLinkedList copy() { } return copied; } + + public SinglyLinkedList reverse () { + SinglyLinkedList reverseList = new SinglyLinkedList(); + int i = size() -1; + if (head == null) { + throw new UnsupportedOperationException("Try it again"); + } + while (i >=0) { + reverseList.addNode(get(i)); + i--; + } + return reverseList; + } } From 1b181de6089e5a9a5ab382fa31533877e91c473e Mon Sep 17 00:00:00 2001 From: Dee Date: Fri, 23 Jul 2021 18:05:23 -0400 Subject: [PATCH 3/5] node tests --- .idea/libraries/Maven__junit_junit_4_13_1.xml | 13 ++ .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 ++ .idea/workspace.xml | 104 ++++++++++++- pom.xml | 8 + .../singlylinkedlist/MainApplication.java | 5 + .../singlylinkedlist/SinglyLinkedList.java | 35 ++++- .../SinglyLinkedListTest.java | 140 ++++++++++++++++++ 7 files changed, 308 insertions(+), 10 deletions(-) create mode 100644 .idea/libraries/Maven__junit_junit_4_13_1.xml create mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml diff --git a/.idea/libraries/Maven__junit_junit_4_13_1.xml b/.idea/libraries/Maven__junit_junit_4_13_1.xml new file mode 100644 index 0000000..9fa24fc --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_13_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fa0d859..3ccd4bf 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,11 +5,13 @@ - - - + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index ffa3f40..87a2afa 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,14 @@ com.zipcodewilmington singlylinkedlist 1.0-SNAPSHOT + + + junit + junit + 4.13.1 + test + + \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/singlylinkedlist/MainApplication.java b/src/main/java/com/zipcodewilmington/singlylinkedlist/MainApplication.java index b8cd84f..095dd2e 100644 --- a/src/main/java/com/zipcodewilmington/singlylinkedlist/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/singlylinkedlist/MainApplication.java @@ -4,4 +4,9 @@ * Created by leon on 1/10/18. */ public class MainApplication { + + public static void main(String[] args) { + SinglyLinkedList string = new SinglyLinkedList(); + string.slice(3,5); + } } diff --git a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java index 98eb3e6..d1d2c5b 100644 --- a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java +++ b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java @@ -35,25 +35,29 @@ public int size() { int length = 0; Node current = head; - if (current.next != null){ + while (current != null){ length++; + current = current.next; } return length; } public void remove(String data) { Node current = head; - if (current == null){ + if (current == null) { throw new UnsupportedOperationException("No list here, smart guy"); } - while (current != null){ - if (current.data == data){ - current.data = null; - } + + if (current.data == data) { current = current.next; + while (current.next != null) { + current = current.next; + } + } } + public Boolean contains(String data){ Node current = head; if (head == null){ @@ -63,9 +67,12 @@ public Boolean contains(String data){ if (current.data == data){ return true; } + current = current.next; } return false; } + + public int find (String data) { Node current = head; int index = 0; @@ -124,4 +131,20 @@ public SinglyLinkedList reverse () { } return reverseList; } + + public String slice(int start, int end){ + String substring = ""; + Node current = head; + if (head == null){ + throw new UnsupportedOperationException("You wildin again, no list buddy"); + } + int i = start; + while (i < end) { + substring += current.data; + current = current.next; + i++; + } + + return substring; + } } diff --git a/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java b/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java index 5cc057e..a1038e7 100644 --- a/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java +++ b/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java @@ -1,7 +1,147 @@ package com.zipcodewilmington.singlylinkedlist; +import org.junit.Assert; +import org.junit.Test; + /** * Created by leon on 1/10/18. */ public class SinglyLinkedListTest { + + @Test + public void addNodeTest(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + + //when + testString.addNode("Hey"); + String expected = "Hey"; + + //then + String actual = testString.get(0); + Assert.assertEquals(expected, actual); + + + } + + @Test + public void addNodeTest2(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + + //when + testString.addNode("Hey"); + int expected = 1; + + //then + int actual = testString.size(); + Assert.assertEquals(expected, actual); + } + + @Test + public void addNodeTest3(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + + //when + testString.addNode("Hey"); + testString.addNode("there"); + int expected = 2; + + //then + int actual = testString.size(); + Assert.assertEquals(expected, actual); + } + + + + @Test (expected = UnsupportedOperationException.class) + public void sliceTest(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + + //when + testString.slice(3,5); + + //then + //Assert.assertEquals(expected, actual); + } + + @Test (expected = UnsupportedOperationException.class) + public void removeExceptionTest(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + + //when + testString.remove("Hey"); + + } + + @Test + public void removeFirstTest(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + testString.addNode("Hey"); + testString.addNode("there"); + + //when + testString.remove("Hey"); + String actual = testString.get(0); + + //then + String expected = "there"; + Assert.assertEquals(expected, actual); + + } + + @Test + public void removeSecondTest(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + testString.addNode("Hey"); + testString.addNode("there"); + testString.addNode("Delilah"); + + //when + testString.remove("there"); + String actual = testString.get(0); + + //then + String expected = "Hey"; + Assert.assertEquals(expected, actual); + + } + + @Test + public void removeCheckThirdTest(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + testString.addNode("Hey"); + testString.addNode("there"); + testString.addNode("Delilah"); + + //when + testString.remove("there"); + String actual = testString.get(1); + + //then + String expected = "Delilah"; + Assert.assertEquals(expected, actual); + + } + + @Test + public void containsTest(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + testString.addNode("Hey"); + testString.addNode("there"); + + //when + boolean contains = testString.contains("there"); + + //then + Assert.assertTrue(contains); + + } } From 9586479992894f5444c666de005d54c31729e514 Mon Sep 17 00:00:00 2001 From: Dee Date: Sun, 25 Jul 2021 00:54:48 -0400 Subject: [PATCH 4/5] sort broken --- .idea/workspace.xml | 36 ++--- .../singlylinkedlist/SinglyLinkedList.java | 65 ++++++-- .../SinglyLinkedListTest.java | 151 +++++++++++++++++- 3 files changed, 218 insertions(+), 34 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3ccd4bf..dc7b0eb 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,11 +5,7 @@ - - - - @@ -162,7 +158,7 @@ - + - + @@ -227,14 +223,14 @@ - + @@ -244,14 +240,14 @@ - + @@ -261,14 +257,14 @@ - + @@ -278,14 +274,14 @@ - + @@ -295,7 +291,7 @@ - - - - - + + + + + diff --git a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java index d1d2c5b..f3645d5 100644 --- a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java +++ b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java @@ -42,19 +42,39 @@ public int size() { return length; } - public void remove(String data) { + public void remove(int index){ Node current = head; if (current == null) { - throw new UnsupportedOperationException("No list here, smart guy"); + throw new UnsupportedOperationException("List is uhhh duhh empty"); } - - if (current.data == data) { + int trackIndex = 0; + while (current != null){ + if (trackIndex == index){ + current.data = null; + } current = current.next; - while (current.next != null) { - current = current.next; } + } + + public SinglyLinkedList remove(String data) { + SinglyLinkedList list = new SinglyLinkedList(); + Node current = head; + if (current == null) { + throw new UnsupportedOperationException("No list here, smart guy"); } + + while (current != null) { + // current = current.next; + if (current.data != data) { + list.addNode(current.data); + //current.data = null; + } + + current = current.next; + } + return list; + } @@ -138,13 +158,40 @@ public String slice(int start, int end){ if (head == null){ throw new UnsupportedOperationException("You wildin again, no list buddy"); } - int i = start; - while (i < end) { - substring += current.data; + int i = 0; + while (current.next != null){ + if (i >= start && i < end) { + substring += current.data; + } current = current.next; i++; } return substring; } + + public SinglyLinkedList sort(){ + Node current = head; + int length = size() -1; + int i = 0; + SinglyLinkedList copyOfSort = new SinglyLinkedList(); + + while (current.next != null && i < length) { + String currentValue = get(i); + String nextValue = get(i + 1); + if (currentValue.charAt(0) > nextValue.charAt(0)) { + String temp = currentValue; + current.data = nextValue; + current.next.data = temp; + copyOfSort.addNode(nextValue); + i++; + } + copyOfSort.addNode(current.data); + i++; + current = current.next; + } + + return copyOfSort; + } + } diff --git a/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java b/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java index a1038e7..02252e2 100644 --- a/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java +++ b/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java @@ -56,7 +56,7 @@ public void addNodeTest3(){ @Test (expected = UnsupportedOperationException.class) - public void sliceTest(){ + public void sliceErrorTest(){ //given SinglyLinkedList testString = new SinglyLinkedList(); @@ -67,6 +67,28 @@ public void sliceTest(){ //Assert.assertEquals(expected, actual); } + @Test + public void sliceTest(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + testString.addNode("Wonder"); + testString.addNode("if "); + testString.addNode("this "); + testString.addNode("will "); + testString.addNode("be "); + testString.addNode("cut"); + testString.addNode("right"); + String expected = "this will be cut"; + + //when + String actual = testString.slice(2,6); + + + //then + Assert.assertEquals(expected, actual); + } + + @Test (expected = UnsupportedOperationException.class) public void removeExceptionTest(){ //given @@ -85,12 +107,11 @@ public void removeFirstTest(){ testString.addNode("there"); //when - testString.remove("Hey"); + testString.remove(0); String actual = testString.get(0); //then - String expected = "there"; - Assert.assertEquals(expected, actual); + Assert.assertNull(actual); } @@ -122,7 +143,7 @@ public void removeCheckThirdTest(){ //when testString.remove("there"); - String actual = testString.get(1); + String actual = testString.get(2); //then String expected = "Delilah"; @@ -130,6 +151,25 @@ public void removeCheckThirdTest(){ } + @Test + public void checkNewListWithRemove(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + testString.addNode("Hey"); + testString.addNode("there"); + testString.addNode("Delilah"); + + //when + testString.remove("there"); + SinglyLinkedList actual = testString.remove("there"); + String actualString = actual.get(1); + + //then + String expected = "Delilah"; + Assert.assertEquals(expected, actualString); + + } + @Test public void containsTest(){ //given @@ -144,4 +184,105 @@ public void containsTest(){ Assert.assertTrue(contains); } + + @Test + public void findHelloAbsentTest(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + testString.addNode("Hey"); + testString.addNode("there"); + testString.addNode("Delilah"); + int expected = -1; + + //when + int actual = testString.find("Hello"); + + //then + Assert.assertEquals(expected, actual); + + } + + @Test + public void findHelloPresentTest(){ + //given + SinglyLinkedList testString = new SinglyLinkedList(); + testString.addNode("Hey"); + testString.addNode("there"); + testString.addNode("Delilah"); + testString.addNode("Hello"); + int expected = 3; + + //when + int actual = testString.find("Hello"); + + //then + Assert.assertEquals(expected, actual); + + } + + @Test (expected = UnsupportedOperationException.class) + public void copyNothingTest(){ + //given + SinglyLinkedList perfect = new SinglyLinkedList(); + + //when + perfect.copy(); + } + + @Test + public void copyNotNullTest(){ + //given + SinglyLinkedList perfect = new SinglyLinkedList(); + perfect.addNode("I"); + perfect.addNode("went"); + perfect.addNode("the"); + perfect.addNode("extra"); + perfect.addNode("mile"); + + //when + SinglyLinkedList copy = perfect.copy(); + String actual = copy.get(1); + String expected = perfect.get(1); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void sortTest(){ + //given + SinglyLinkedList testSort = new SinglyLinkedList(); + testSort.addNode("i"); + testSort.addNode("went"); + testSort.addNode("the"); + testSort.addNode("extra"); + testSort.addNode("mile"); + String expected = "extra"; + + //when + SinglyLinkedList sorted = testSort.sort(); + String actual = sorted.get(0); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void reverseTest(){ + //given + SinglyLinkedList testSort = new SinglyLinkedList(); + testSort.addNode("i"); + testSort.addNode("went"); + testSort.addNode("the"); + testSort.addNode("extra"); + testSort.addNode("mile"); + String expected = "mile"; + + //when + SinglyLinkedList sorted = testSort.reverse(); + String actual = sorted.get(0); + + //then + Assert.assertEquals(expected, actual); + } } From e5b3f11ba03dcda30ad8d71972c86205661bbe19 Mon Sep 17 00:00:00 2001 From: Dee Date: Sun, 25 Jul 2021 15:43:29 -0400 Subject: [PATCH 5/5] sort fixed --- .idea/workspace.xml | 16 ++-- .../singlylinkedlist/SinglyLinkedList.java | 73 ++++++++++++++----- .../SinglyLinkedListTest.java | 45 +++++++++++- 3 files changed, 107 insertions(+), 27 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index dc7b0eb..f43fccc 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -158,7 +158,7 @@ - + - + @@ -223,7 +223,7 @@ - + @@ -257,7 +257,7 @@ - + + + - - diff --git a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java index f3645d5..454ada3 100644 --- a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java +++ b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java @@ -170,28 +170,67 @@ public String slice(int start, int end){ return substring; } - public SinglyLinkedList sort(){ - Node current = head; - int length = size() -1; - int i = 0; - SinglyLinkedList copyOfSort = new SinglyLinkedList(); - - while (current.next != null && i < length) { - String currentValue = get(i); - String nextValue = get(i + 1); - if (currentValue.charAt(0) > nextValue.charAt(0)) { - String temp = currentValue; + public void sort(){ + //Node current = head; + int length = size(); + + for (int i = 0; i < length; i++) { + Node current = head; + while (current.next != null){ + String currentValue = current.data; + String nextValue = current.next.data; + if (compareNodeValue(currentValue, nextValue)){ + String temp = current.data; current.data = nextValue; current.next.data = temp; - copyOfSort.addNode(nextValue); - i++; } - copyOfSort.addNode(current.data); - i++; - current = current.next; + current = current.next; + } + + } + +// while (i < length) { +// String currentValue = copyOfSort.get(i); +// String nextValue = copyOfSort.get(i + 1); +// while (compareNodeValue(currentValue, nextValue)) { +// String temp = currentValue; +// copyOfSort.setNode(i, nextValue); +// copyOfSort.setNode(i+1, temp); //null?? +// //copyOfSort.addNode(nextValue); +// i++; +// } +//// copyOfSort.addNode(current.data); +// i++; +// current = current.next; +// } + + //return copyOfSort; + } + + public void setNode (int index, String reset) { + Node current = head; + int trackIndex = 0; + if (head == null || index > size() || index <0) { + throw new UnsupportedOperationException("THERE'S NO LIST"); + } + while (current != null) { + if (trackIndex == index) { + current.data = reset; } + trackIndex++; + current = current.next; + } + } + + public Boolean compareNodeValue(String first, String next){ + if (first == null || next == null){ + throw new UnsupportedOperationException("empty node"); + } - return copyOfSort; + if (first.charAt(0) > next.charAt(0)){ + return true; } + return false; + } } diff --git a/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java b/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java index 02252e2..3d63eb9 100644 --- a/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java +++ b/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java @@ -260,8 +260,8 @@ public void sortTest(){ String expected = "extra"; //when - SinglyLinkedList sorted = testSort.sort(); - String actual = sorted.get(0); + testSort.sort(); + String actual = testSort.get(0); //then Assert.assertEquals(expected, actual); @@ -285,4 +285,45 @@ public void reverseTest(){ //then Assert.assertEquals(expected, actual); } + + @Test + public void setTest(){ + //given + SinglyLinkedList setThis = new SinglyLinkedList(); + setThis.addNode("hope"); + setThis.addNode("this"); + setThis.addNode("doesnt"); + setThis.addNode("works"); + String reset = "does"; + + //when + setThis.setNode(2, reset); + String actual = setThis.get(2); + + //then + Assert.assertEquals(reset, actual); + + } + + @Test + public void compareTest(){ + //given + SinglyLinkedList setThis = new SinglyLinkedList(); + setThis.addNode("hope"); + setThis.addNode("this"); + setThis.addNode("doesnt"); + setThis.addNode("works"); + + //when + String first = setThis.get(1); + String second = setThis.get(2); + + boolean actual = setThis.compareNodeValue(first, second); + + + //then + Assert.assertTrue(actual); + + } + }