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/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/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..5cd1e3b 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,86 +1,26 @@
+
+
+
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -212,60 +153,19 @@
+
+
+
+
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -301,157 +201,79 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
@@ -494,12 +316,16 @@
-
-
-
-
-
-
+
+
+
+
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..87df74b 100644
--- a/src/main/java/com/zipcodewilmington/singlylinkedlist/MainApplication.java
+++ b/src/main/java/com/zipcodewilmington/singlylinkedlist/MainApplication.java
@@ -4,4 +4,7 @@
* Created by leon on 1/10/18.
*/
public class MainApplication {
+ public static void main(String[] args){
+ SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
+ }
}
diff --git a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java
index 2fb3165..081f1ff 100644
--- a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java
+++ b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java
@@ -1,7 +1,113 @@
package com.zipcodewilmington.singlylinkedlist;
+
+
/**
* Created by leon on 1/10/18.
*/
public class SinglyLinkedList {
+
+ class Node{
+ Object data;
+ Node next;
+
+ public Node(Object data){
+ this.data = data;
+ this.next = null;
+
+ }
+ }
+
+ public SinglyLinkedList(){
+
+ }
+
+ public Node head = null;
+ public Node tail = null;
+
+ public void addNode(Object data){
+ Node node = new Node(data);
+ if(head == null){
+ head = node;
+ }else {
+ tail.next = node;
+ }
+ tail = node;
+ }
+
+ public Integer size(){
+ Integer count = 0;
+ Node current = head;
+ while(current!= null){
+ count++;
+ current = current.next;
+ }
+ return count;
+ }
+
+ public Object find(Object data){
+ Integer index = 0;
+ Node current = head;
+ while(current!= null){
+ if(current.data == data){
+ return index;
+ }
+ index++;
+ current = current.next;
+ }
+ return -1;
+ }
+
+ public Boolean contains(Object data){
+ Node current = head;
+ while(current!= null){
+ if(current.data == data){
+ return true;
+ }
+ current = current.next;
+ }
+ return false;
+ }
+
+ public SinglyLinkedList remove(Integer index){
+ SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
+ Integer indexOfNode = 0;
+ Node current = head;
+ while(current!=null){
+ if(index != indexOfNode){
+ singlyLinkedList.addNode(current.data);
+ }
+ indexOfNode++;
+ current = current.next;
+
+ }
+ return singlyLinkedList;
+ }
+
+ public SinglyLinkedList copy(){
+ SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
+ Node current = head;
+ while(current!=null){
+ singlyLinkedList.addNode(current.data);
+ current = current.next;
+ }
+ return singlyLinkedList;
+ }
+
+ public void sort(){
+ Node current = head;
+ for(int i = 0; i < size();i++){
+ current = head;
+ while(current.next!= null){
+ Node next = current.next;
+ if((Integer)current.data>(Integer)next.data){
+ Object temp = current.data;
+ current.data = next.data;
+ next.data = temp;
+ }
+ current = current.next;
+ }
+ }
+ }
+
}
diff --git a/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java b/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java
index 5cc057e..756663f 100644
--- a/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java
+++ b/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java
@@ -1,7 +1,99 @@
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 TestSize(){
+ //given
+ SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
+ Integer expected = 0;
+ //when
+ Integer actual = singlyLinkedList.size();
+ //then
+ Assert.assertEquals(expected,actual);
+ }
+
+ @Test
+ public void testAdd(){
+ //given
+ SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
+ singlyLinkedList.addNode(1);
+ singlyLinkedList.addNode(2);
+ Integer expected = 2;
+ //when
+ Integer actual = singlyLinkedList.size();
+ //then
+ Assert.assertEquals(expected, actual);
+
+ }
+
+ @Test
+ public void testFind(){
+ SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
+ Integer expectedInd = 2;
+ singlyLinkedList.addNode("Hello");
+ singlyLinkedList.addNode("World");
+ singlyLinkedList.addNode("Zipcode");
+
+ //When
+ Object actual = singlyLinkedList.find("Zipcode");
+
+ //then
+ Assert.assertEquals(expectedInd,actual);
+
+ }
+
+ @Test
+ public void testContains(){
+ SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
+ Boolean expected = true;
+ singlyLinkedList.addNode("Hi");
+ singlyLinkedList.addNode("Hello");
+
+ //when
+ Boolean actual = singlyLinkedList.contains("Hello");
+
+ //Then
+ Assert.assertTrue(actual);
+ }
+
+ @Test
+ public void testCopy(){
+ SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
+ singlyLinkedList.addNode(2);
+ singlyLinkedList.addNode(3);
+ Integer expected = 2;
+
+ //When
+ Integer actual = singlyLinkedList.copy().size();
+
+ //Then
+ Assert.assertEquals(expected,actual);
+ }
+
+ @Test
+ public void sort(){
+ SinglyLinkedList singlyLinkedList = new SinglyLinkedList();
+ singlyLinkedList.addNode(5);
+ singlyLinkedList.addNode(4);
+ singlyLinkedList.addNode(3);
+ singlyLinkedList.addNode(2);
+ Integer expected = 4;
+
+ //When
+ Integer actual = singlyLinkedList.size();
+
+ //then
+ Assert.assertEquals(expected,actual);
+
+
+
+ }
+
}