diff --git a/group14/187114392/work_1_20170225/.classpath b/group14/187114392/work_1_20170225/.classpath new file mode 100644 index 0000000000..fceb4801b5 --- /dev/null +++ b/group14/187114392/work_1_20170225/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/group14/187114392/work_1_20170225/.gitignore b/group14/187114392/work_1_20170225/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group14/187114392/work_1_20170225/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group14/187114392/work_1_20170225/.idea/.name b/group14/187114392/work_1_20170225/.idea/.name new file mode 100644 index 0000000000..9769cfad31 --- /dev/null +++ b/group14/187114392/work_1_20170225/.idea/.name @@ -0,0 +1 @@ +2017Learning \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/.idea/compiler.xml b/group14/187114392/work_1_20170225/.idea/compiler.xml new file mode 100644 index 0000000000..96cc43efa6 --- /dev/null +++ b/group14/187114392/work_1_20170225/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/.idea/copyright/profiles_settings.xml b/group14/187114392/work_1_20170225/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000000..e7bedf3377 --- /dev/null +++ b/group14/187114392/work_1_20170225/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/.idea/encodings.xml b/group14/187114392/work_1_20170225/.idea/encodings.xml new file mode 100644 index 0000000000..97626ba454 --- /dev/null +++ b/group14/187114392/work_1_20170225/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/.idea/junitgenerator-prj-settings.xml b/group14/187114392/work_1_20170225/.idea/junitgenerator-prj-settings.xml new file mode 100644 index 0000000000..b6bb9db746 --- /dev/null +++ b/group14/187114392/work_1_20170225/.idea/junitgenerator-prj-settings.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/.idea/misc.xml b/group14/187114392/work_1_20170225/.idea/misc.xml new file mode 100644 index 0000000000..6a48f33378 --- /dev/null +++ b/group14/187114392/work_1_20170225/.idea/misc.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/.idea/modules.xml b/group14/187114392/work_1_20170225/.idea/modules.xml new file mode 100644 index 0000000000..f37bb20093 --- /dev/null +++ b/group14/187114392/work_1_20170225/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/.idea/uiDesigner.xml b/group14/187114392/work_1_20170225/.idea/uiDesigner.xml new file mode 100644 index 0000000000..e96534fb27 --- /dev/null +++ b/group14/187114392/work_1_20170225/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/.idea/work_1_20170225.iml b/group14/187114392/work_1_20170225/.idea/work_1_20170225.iml new file mode 100644 index 0000000000..d6ebd48059 --- /dev/null +++ b/group14/187114392/work_1_20170225/.idea/work_1_20170225.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/.idea/workspace.xml b/group14/187114392/work_1_20170225/.idea/workspace.xml new file mode 100644 index 0000000000..8c5615cc95 --- /dev/null +++ b/group14/187114392/work_1_20170225/.idea/workspace.xml @@ -0,0 +1,1295 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1488028819234 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/.project b/group14/187114392/work_1_20170225/.project new file mode 100644 index 0000000000..fab8d7f04c --- /dev/null +++ b/group14/187114392/work_1_20170225/.project @@ -0,0 +1,17 @@ + + + 2017Learning + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group14/187114392/work_1_20170225/.settings/org.eclipse.jdt.core.prefs b/group14/187114392/work_1_20170225/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..3a21537071 --- /dev/null +++ b/group14/187114392/work_1_20170225/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/group14/187114392/work_1_20170225/2017Learning.iml b/group14/187114392/work_1_20170225/2017Learning.iml new file mode 100644 index 0000000000..c4678227ee --- /dev/null +++ b/group14/187114392/work_1_20170225/2017Learning.iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/ReadMe.md b/group14/187114392/work_1_20170225/ReadMe.md new file mode 100644 index 0000000000..79077789f6 --- /dev/null +++ b/group14/187114392/work_1_20170225/ReadMe.md @@ -0,0 +1,3 @@ +这个项目用idea直接打开。 +运行里面的test 目录就可以直接单元测试。 +谢谢 diff --git a/group14/187114392/work_1_20170225/src/Main.java b/group14/187114392/work_1_20170225/src/Main.java new file mode 100644 index 0000000000..3e44cc8e16 --- /dev/null +++ b/group14/187114392/work_1_20170225/src/Main.java @@ -0,0 +1,31 @@ +/** + * Created by bshu on 2017/2/25. + */ +import com.coding.basic.ArrayList; +import com.coding.basic.Iterator; + +import java.util.*; + +/** + * Created by bshu on 2017/2/21. + */ +public class Main { + public static void main(String[] args) { + int size = 0; + System.out.println("1 size " + (size++)); + System.out.println("2 size " + (size)); + LinkedList lnk = new LinkedList(); + java.util.ArrayList list = new java.util.ArrayList(){{add("str0");}}; + lnk.add("kk1"); + lnk.add("kk2"); + lnk.add("kk3"); + lnk.remove(2); + lnk.iterator(); + int count = 0; + for (java.util.Iterator iter = lnk.iterator(); iter.hasNext();) { + System.out.printf("%s is :%s \n",count, iter.next()); + ++count; + } + } +} + diff --git a/group14/187114392/work_1_20170225/src/com/coding/basic/ArrayList.java b/group14/187114392/work_1_20170225/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..78f24c6dae --- /dev/null +++ b/group14/187114392/work_1_20170225/src/com/coding/basic/ArrayList.java @@ -0,0 +1,73 @@ +package com.coding.basic; +import java.util.Arrays; +import java.lang.IndexOutOfBoundsException; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[100]; + + public void ensure_length(int expect_length) { + if (expect_length > elementData.length) { + elementData = Arrays.copyOf(elementData,elementData.length * 2); + } + } + + public void add(Object o){ + ensure_length(size + 1); + elementData[size] = o; + size += 1; + } + + public void add(int index, Object o){ + ensure_length(size + 1); + System.arraycopy(elementData,index, + elementData,index + 1, + size - index + 1); + elementData[index] = o; + size += 1; + } + + public Object get(int index) { + if (index > size) { + throw new IndexOutOfBoundsException("index out of bounds"); + } else { + return elementData[index]; + } + } + + public Object remove(int index){ + Object oldvalue = elementData[index]; + System.arraycopy(elementData,index + 1,elementData,index,size - index - 1); + elementData[--size] = null; + return oldvalue; + } + + public int size(){ + return size; + } + + public Iterator iterator(){ + return new Iterator_ip(); + } + + private class Iterator_ip implements Iterator { + private int index = 0; + + @Override + public boolean hasNext() { + return (index + 1) <= size; + } + + @Override + public Object next() { + if (index > size) { +// throw new IndexOutOfBoundsException("iterator next out of bounds"); + return null; + } + return elementData[index++]; + } + } + +} diff --git a/group14/187114392/work_1_20170225/src/com/coding/basic/BinaryTreeNode.java b/group14/187114392/work_1_20170225/src/com/coding/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..d7ac820192 --- /dev/null +++ b/group14/187114392/work_1_20170225/src/com/coding/basic/BinaryTreeNode.java @@ -0,0 +1,32 @@ +package com.coding.basic; + +public class BinaryTreeNode { + + private Object data; + private BinaryTreeNode left; + private BinaryTreeNode right; + + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } + public BinaryTreeNode getLeft() { + return left; + } + public void setLeft(BinaryTreeNode left) { + this.left = left; + } + public BinaryTreeNode getRight() { + return right; + } + public void setRight(BinaryTreeNode right) { + this.right = right; + } + + public BinaryTreeNode insert(Object o){ + return null; + } + +} diff --git a/group14/187114392/work_1_20170225/src/com/coding/basic/Iterator.java b/group14/187114392/work_1_20170225/src/com/coding/basic/Iterator.java new file mode 100644 index 0000000000..06ef6311b2 --- /dev/null +++ b/group14/187114392/work_1_20170225/src/com/coding/basic/Iterator.java @@ -0,0 +1,7 @@ +package com.coding.basic; + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/group14/187114392/work_1_20170225/src/com/coding/basic/LinkedList.java b/group14/187114392/work_1_20170225/src/com/coding/basic/LinkedList.java new file mode 100644 index 0000000000..89b4523e0a --- /dev/null +++ b/group14/187114392/work_1_20170225/src/com/coding/basic/LinkedList.java @@ -0,0 +1,168 @@ +package com.coding.basic; + +public class LinkedList implements List { + + private Node head; + private Node tail; + private Node last_but_one; + private int size = 0; + + public LinkedList() { + tail = new Node(); + tail.data = null; + tail.next = null; + + head = new Node(); + head.next = null; + } + + private void add_elementbyindex(int index , Object o) { + Node new_node = new Node(); + if (index == 0) { + if (size > 0) { + new_node.data = head.data; + } else { +// System.out.println("first new node is null"); + new_node.data = null; + head.next = null; + } + head.data = o; + } else { + new_node.data = o; + } + + int count = 0; + Node k = head; + while (count < index - 1) { +// System.out.printf("add count:%s, k is:%s \n",count,k.data); + k = k.next; + ++count; + } + new_node.next = k.next; + k.next = new_node; + ++size; + } + + private Object remove_elementbyindex(int index) { + int count = 0; + Object remove_ob = null; + Node k = head; + while (count < index - 1) { +// System.out.printf("remove count:%s, k is:%s \n",count,k.data); + k = k.next; + ++count; + } + + if (index == 0) { + remove_ob = head.data; + head.data = head.next.data; + if (size == 1) { + head.data = null; + } + head.next = head.next.next; + } else if ((index - 1) == size) { +// System.out.printf("index:%s == size, count:%s, k is:%s \n",index,count,k.data); + remove_ob = k.data; + k.next = null; + } else { + if (size == 1) { + k.data = null; + } + remove_ob = k.next.data; + k.next = k.next.next; + } + --size; + return remove_ob; + } + + public void add(Object o){ + add_elementbyindex(size(),o); + } + + public void add(int index , Object o){ + // if index larger than size , then we set index equal to size; + if (index > size) { + throw new IndexOutOfBoundsException("index out of bounds"); + } + add_elementbyindex(index,o); + + } + public Object get(int index){ + if (index > size) { + throw new IndexOutOfBoundsException("get index out of bounds"); + } + Node k = head; + int count = 0; + while (count < index) { +// System.out.printf("get count:%s, k is:%s \n",count,k.data); + k = k.next; + ++count; + } +// System.out.printf("get count:%s, k is:%s \n",count,k.data); + return k.data; + } + public Object remove(int index){ + if (index < 0 || index > size || size == 0) { + return null; + } + return remove_elementbyindex(index); + } + + public int size(){ + return size; + } + + public void addFirst(Object o){ + add_elementbyindex(0,o); + } + public void addLast(Object o){ + add_elementbyindex(size,o); + } + public Object removeFirst(){ + if (size == 0) { + return null; + } + return remove_elementbyindex(0); + } + public Object removeLast(){ + if (size == 0) { + return null; + } + return remove_elementbyindex(size); + } + public Iterator iterator(){ + Iterator_ip iter = new Iterator_ip(head); + return iter; + } + + private static class Node{ + Object data; + Node next; + } + + private class Iterator_ip implements Iterator { + private int index = 0; + private Node node_iter; + + public Iterator_ip(Node node_iter) { + this.node_iter = node_iter; + } + + @Override + public boolean hasNext() { + return node_iter.next != null; + } + + @Override + public Object next() { + if (index > size) { +// throw new IndexOutOfBoundsException("iterator next out of bounds"); + return null; + } + Object now_data = node_iter.data; + node_iter = node_iter.next; + ++index; + return now_data; + } + } +} diff --git a/group14/187114392/work_1_20170225/src/com/coding/basic/List.java b/group14/187114392/work_1_20170225/src/com/coding/basic/List.java new file mode 100644 index 0000000000..10d13b5832 --- /dev/null +++ b/group14/187114392/work_1_20170225/src/com/coding/basic/List.java @@ -0,0 +1,9 @@ +package com.coding.basic; + +public interface List { + public void add(Object o); + public void add(int index, Object o); + public Object get(int index); + public Object remove(int index); + public int size(); +} diff --git a/group14/187114392/work_1_20170225/src/com/coding/basic/Queue.java b/group14/187114392/work_1_20170225/src/com/coding/basic/Queue.java new file mode 100644 index 0000000000..ada4130038 --- /dev/null +++ b/group14/187114392/work_1_20170225/src/com/coding/basic/Queue.java @@ -0,0 +1,22 @@ +package com.coding.basic; + +public class Queue { + + private LinkedList lnk = new LinkedList(); + + public void enQueue(Object o){ + lnk.addLast(o); + } + + public Object deQueue(){ + return lnk.removeFirst(); + } + + public boolean isEmpty(){ + return lnk.size() == 0; + } + + public int size(){ + return lnk.size(); + } +} diff --git a/group14/187114392/work_1_20170225/src/com/coding/basic/Stack.java b/group14/187114392/work_1_20170225/src/com/coding/basic/Stack.java new file mode 100644 index 0000000000..d553579b79 --- /dev/null +++ b/group14/187114392/work_1_20170225/src/com/coding/basic/Stack.java @@ -0,0 +1,37 @@ +package com.coding.basic; +import java.lang.ArrayIndexOutOfBoundsException; +import java.util.EmptyStackException; + +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o) { + elementData.add(o); +// System.out.println("size is " + elementData.size()); + } + + public Object pop() { + int elementData_size = elementData.size(); + if (elementData_size == 0) { + throw new EmptyStackException(); + } + Object top_data = elementData.get(elementData_size - 1); + elementData.remove(elementData_size - 1); + return top_data; + } + + public Object peek() { + if (elementData.size() == 0) { + throw new EmptyStackException(); + } + return elementData.get(elementData.size() - 1); + } + + public boolean isEmpty() { + return elementData.size() == 0; + } + + public int size() { + return elementData.size(); + } +} diff --git a/group14/187114392/work_1_20170225/test/ArrayList_Test.java b/group14/187114392/work_1_20170225/test/ArrayList_Test.java new file mode 100644 index 0000000000..fbfbdf1b3a --- /dev/null +++ b/group14/187114392/work_1_20170225/test/ArrayList_Test.java @@ -0,0 +1,52 @@ +import com.coding.basic.ArrayList; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by bshu on 2017/2/25. + */ +public class ArrayList_Test { + @Test + public void add_test() { + ArrayList arr = new ArrayList(); + arr.add("one"); + assertEquals(arr.get(0),"one"); + arr.add("two"); + assertEquals(arr.get(1),"two"); + } + + @Test + public void add_index_test() { + ArrayList arr = new ArrayList(); + arr.add(0,"one"); + assertEquals(arr.get(0),"one"); + arr.add(1,"two"); + arr.add(2,"three"); + arr.add(3,"four"); + arr.add(4,"five"); + assertEquals(arr.get(4),"five"); + arr.add(2,"duplicte two"); + assertEquals(arr.get(2),"duplicte two"); + } + + @Test + public void remove_test() { + ArrayList arr = new ArrayList(); + arr.add(0,"one"); + arr.add(1,"two"); + arr.add(2,"three"); + arr.remove(1); + assertEquals(arr.get(1),"three"); + } + + @Test + public void get_test() { + ArrayList arr = new ArrayList(); + arr.add(0,"one"); + arr.add(1,"two"); + arr.add(2,"three"); + assertEquals(arr.get(1),"two"); + assertEquals(arr.get(3),null); + } +} \ No newline at end of file diff --git a/group14/187114392/work_1_20170225/test/LinkedList_Test.java b/group14/187114392/work_1_20170225/test/LinkedList_Test.java new file mode 100644 index 0000000000..986366cb6a --- /dev/null +++ b/group14/187114392/work_1_20170225/test/LinkedList_Test.java @@ -0,0 +1,122 @@ +import org.junit.Test; +import com.coding.basic.*; +import java.lang.Object; + +import static org.junit.Assert.assertEquals; + +/** + * LinkedList_Test Tester. + * + * @author + * @since
bshu 26, 2017
+ * @version 1.0 + */ +public class LinkedList_Test { + @Test + public void get() { + LinkedList link = new LinkedList(); + link.add("kkk"); + assertEquals(link.get(0),"kkk"); + link.add("kkk1"); + assertEquals(link.get(1),"kkk1"); + } + + @Test + public void add() { + LinkedList link = new LinkedList(); + link.add("kkk"); + link.add("aaa"); + link.add("bbb"); + link.add("ccc"); + link.add("ddd"); + link.add("eee"); + Object[] ob = new Object[]{"kkk","aaa","bbb","ccc","ddd","eee"}; + int count = 0; + for (Iterator iter = link.iterator(); iter.hasNext();) { + Object data = iter.next(); +// System.out.printf("%s is :%s \n",count, data); + assertEquals(data,ob[count]); + ++count; + } + } + + @Test + public void add_index() { + LinkedList link = new LinkedList(); + link.add("kkk"); +// System.out.println("0 is " + link.get(0)); + link.add("kkk2"); + link.add(0,"0kkk"); + link.add(3,"3kkk"); + assertEquals(link.get(0),"0kkk"); + assertEquals(link.get(2),"kkk2"); + } + + @Test + public void add_first() { + LinkedList link = new LinkedList(); + link.add("kkk"); + link.addFirst("F_kkk"); + assertEquals(link.get(0),"F_kkk"); + assertEquals(link.get(1),"kkk"); + } + + @Test + public void add_last() { + LinkedList link = new LinkedList(); + link.add("kkk"); + link.addLast("L_kkk"); + assertEquals(link.get(0),"kkk"); + assertEquals(link.get(link.size() - 1),"L_kkk"); + } + + @Test + public void remove() { + LinkedList link = new LinkedList(); + link.add("kkk"); +// System.out.println("0 is " + link.get(0)); + link.add("kkk1"); + link.add("kkk2"); + link.remove(2); + link.add(link.size(),"2kkk"); + link.add("kkk3"); + link.add("kkk4"); + link.add("kkk5"); + link.remove(link.size()); + link.add("kkk6"); + int count = 0; + Object[] ob = new Object[]{"kkk","kkk1","2kkk","kkk3","kkk4","kkk6"}; + for (Iterator iter = link.iterator(); iter.hasNext();) { + Object data = iter.next(); + System.out.printf("%s is :%s \n",count, data); + assertEquals(data,ob[count]); + ++count; + } + } + + @Test + public void remove_first() { + LinkedList link = new LinkedList(); + link.add("kkk"); + link.add("kkk1"); + link.add("kkk2"); + link.removeFirst(); + assertEquals("kkk1",link.get(0)); + assertEquals("kkk2",link.get(1)); + assertEquals(2,link.size()); + } + + @Test + public void remove_last() { + LinkedList link = new LinkedList(); + link.add("kkk"); + link.add("kkk1"); + link.removeLast(); + assertEquals("kkk",link.get(0)); + link.removeLast(); + link.removeLast(); + link.remove(0); + link.remove(0); + assertEquals(null,link.get(0)); + } +} diff --git a/group14/187114392/work_1_20170225/test/Queue_Test.java b/group14/187114392/work_1_20170225/test/Queue_Test.java new file mode 100644 index 0000000000..319baf6706 --- /dev/null +++ b/group14/187114392/work_1_20170225/test/Queue_Test.java @@ -0,0 +1,44 @@ + +import com.coding.basic.LinkedList; +import com.coding.basic.Queue; +import org.junit.Test; +import org.junit.Before; +import org.junit.After; + +import static org.junit.Assert.assertEquals; + +/** + * Queue_Test Tester. + * + * @author + * @since
bshu 26, 2017
+ * @version 1.0 + */ +public class Queue_Test { + + @Test + public void enQueue() { + Queue que = new Queue(); + que.enQueue("kkk"); + que.enQueue("kkk1"); + assertEquals(2,que.size()); + } + + @Test + public void deQueue() { + Queue que = new Queue(); + que.enQueue("kkk"); + que.enQueue("kkk1"); + Object data = que.deQueue(); + assertEquals("kkk",data); + } + + @Test + public void isempty() { + Queue que = new Queue(); + assertEquals(true,que.isEmpty()); + que.enQueue("kk2"); + assertEquals(false,que.isEmpty()); + } + +} diff --git a/group14/187114392/work_1_20170225/test/Stack_Test.java b/group14/187114392/work_1_20170225/test/Stack_Test.java new file mode 100644 index 0000000000..8a11a20632 --- /dev/null +++ b/group14/187114392/work_1_20170225/test/Stack_Test.java @@ -0,0 +1,72 @@ + +import org.junit.Test; +import com.coding.basic.*; + +import java.util.EmptyStackException; + +import static org.junit.Assert.assertEquals; + +/** + * Stack_Test Tester. + * + * @author + * @since
bshu 26, 2017
+ * @version 1.0 + */ +public class Stack_Test { + @Test + public void pop() { + Stack stk = new Stack(); + stk.push("one"); + stk.push("two"); + assertEquals(stk.pop(),"two"); + } + + @Test + public void pop_empty() { + Stack stk = new Stack(); + try { + stk.pop(); + } + catch (EmptyStackException e) { + assertEquals(e.toString(),"java.util.EmptyStackException"); + } + } + + @Test + public void push() { + Stack stk = new Stack(); + stk.push("one"); + stk.push("two"); + assertEquals(stk.peek(),"two"); + } + + @Test + public void peek() { + Stack stk = new Stack(); + stk.push("one"); + stk.push("two"); + stk.push("three"); + assertEquals(stk.peek(),"three"); + } + + @Test + public void peek_empty() { + Stack stk = new Stack(); + try { + stk.peek(); + } + catch (EmptyStackException e) { + assertEquals(e.toString(),"java.util.EmptyStackException"); + } + } + + @Test + public void isempty() { + Stack stk = new Stack(); + stk.push("one"); + assertEquals(stk.isEmpty(),false); + stk.pop(); + assertEquals(stk.isEmpty(),true); + } +}