forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from nitasty009/master
pull
- Loading branch information
Showing
17 changed files
with
1,473 additions
and
0 deletions.
There are no files selected for viewing
Submodule coding2017-1
added at
b5be7e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>task_01</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
95 changes: 95 additions & 0 deletions
95
group05/371492887/task_01/src/com/nitasty/test/ArrayListTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.nitasty.test; | ||
|
||
import static org.junit.Assert.*; | ||
import junit.framework.Assert; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.nitasty.util.ArrayList; | ||
import com.nitasty.util.Iterator; | ||
|
||
public class ArrayListTest { | ||
|
||
private ArrayList list; | ||
|
||
@Before | ||
public void init(){ | ||
list=new ArrayList(); | ||
for (int i = 0; i < 100; i++) { | ||
list.add(i); | ||
} | ||
} | ||
|
||
@Test | ||
public void testAddObject() { | ||
list.add(100); | ||
Assert.assertEquals(101, list.size()); | ||
} | ||
|
||
@Test | ||
public void testAddIntObject() { | ||
list.add(3,"test"); | ||
Assert.assertEquals("test", list.get(3)); | ||
} | ||
|
||
@Test | ||
public void testRemoveInt() { | ||
list.add(3,"test"); | ||
list.remove(3); | ||
Assert.assertEquals(3, list.get(3)); | ||
} | ||
|
||
@Test | ||
public void testRemoveObject() { | ||
list.add(0,"test"); | ||
list.remove("test"); | ||
Assert.assertEquals(0, list.get(0)); | ||
} | ||
|
||
|
||
@Test | ||
public void testIsEmpty() { | ||
list.clear(); | ||
Assert.assertEquals(true, list.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testContains() { | ||
Assert.assertEquals(false, list.contains("test")); | ||
list.add("test"); | ||
Assert.assertEquals(true, list.contains("test")); | ||
} | ||
|
||
|
||
|
||
@Test | ||
public void testSet() { | ||
Assert.assertEquals(true, list.contains(3)); | ||
list.set(3, "test"); | ||
Assert.assertEquals(true, list.contains("test")); | ||
Assert.assertEquals(false, list.contains(3)); | ||
} | ||
|
||
@Test | ||
public void testIndexOf() { | ||
list.set(3, "test"); | ||
Assert.assertEquals(3, list.indexOf("test")); | ||
} | ||
|
||
@Test | ||
public void testLastIndexOf() { | ||
list.set(3, "test"); | ||
list.set(33, "test"); | ||
Assert.assertEquals(33, list.lastIndexOf("test")); | ||
} | ||
|
||
@Test | ||
public void testHasNext(){ | ||
int i=0; | ||
for(Iterator it=list.iterator();it.hasNext();i++){ | ||
Assert.assertEquals(i, it.next()); | ||
// System.out.println(it.next()); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
group05/371492887/task_01/src/com/nitasty/test/BinaryTreeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.nitasty.test; | ||
|
||
import static org.junit.Assert.*; | ||
import junit.framework.Assert; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.nitasty.util.BinaryTree; | ||
|
||
public class BinaryTreeTest { | ||
|
||
BinaryTree<Integer> tree; | ||
|
||
@Before | ||
public void init(){ | ||
tree=new BinaryTree<Integer>(); | ||
tree.insert(5); | ||
tree.insert(3); | ||
tree.insert(8); | ||
tree.insert(2); | ||
tree.insert(7); | ||
tree.insert(9); | ||
tree.insert(1); | ||
tree.insert(4); | ||
tree.insert(10); | ||
tree.insert(6); | ||
} | ||
|
||
@Test | ||
public void testMakeEmpty() { | ||
tree.makeEmpty(); | ||
Assert.assertEquals(true, tree.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testGetHeight() { | ||
Assert.assertEquals(3, tree.getHeight()); | ||
} | ||
|
||
@Test | ||
public void testContains() { | ||
for (int i = 1; i < 11; i++) { | ||
Assert.assertEquals(true, tree.contains(i)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testFindMin() { | ||
Assert.assertEquals(1, tree.findMin()); | ||
} | ||
|
||
@Test | ||
public void testFindMax() { | ||
Assert.assertEquals(10, tree.findMax()); | ||
} | ||
|
||
|
||
@Test | ||
public void testRemove() { | ||
tree.remove(3); | ||
Assert.assertEquals(false, tree.contains(3)); | ||
} | ||
|
||
|
||
} |
142 changes: 142 additions & 0 deletions
142
group05/371492887/task_01/src/com/nitasty/test/LinkedListTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package com.nitasty.test; | ||
|
||
import static org.junit.Assert.*; | ||
import junit.framework.Assert; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.nitasty.util.ArrayList; | ||
import com.nitasty.util.Iterator; | ||
import com.nitasty.util.LinkedList; | ||
|
||
public class LinkedListTest { | ||
|
||
private LinkedList list; | ||
|
||
@Before | ||
public void init(){ | ||
list=new LinkedList(); | ||
for (int i = 0; i < 100; i++) { | ||
list.add(i); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGet() { | ||
IndexOutOfBoundsException tx=null; | ||
for (int i = 0; i < 100; i++) { | ||
Assert.assertEquals(i, list.get(i)); | ||
} | ||
|
||
try { | ||
list.get(100); | ||
} catch (IndexOutOfBoundsException e) { | ||
tx=e; | ||
} | ||
Assert.assertEquals(IndexOutOfBoundsException.class,tx.getClass()); | ||
} | ||
|
||
@Test | ||
public void testRemoveInt() { | ||
for (int i = 99; i >= 0; i--) { | ||
Assert.assertEquals(i, list.remove(i)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSize() { | ||
Assert.assertEquals(100, list.size()); | ||
} | ||
|
||
@Test | ||
public void testAddFirst() { | ||
list.addFirst(-1); | ||
for (int i = 0; i < 101; i++) { | ||
Assert.assertEquals(i-1, list.get(i)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testAddLast() { | ||
|
||
for (int i = 100; i < 1000; i++) { | ||
list.addLast(i); | ||
} | ||
|
||
for (int i = 0; i < 1000; i++) { | ||
Assert.assertEquals(i, list.get(i)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testAddBefore() { | ||
list.addBefore(66,list.node(3)); | ||
Assert.assertEquals(66, list.get(3)); | ||
} | ||
|
||
@Test | ||
public void testAddAfter() { | ||
list.addAfter(66,list.node(3)); | ||
Assert.assertEquals(66, list.get(4)); | ||
} | ||
|
||
@Test | ||
public void testIsEmpty() { | ||
list.clear(); | ||
Assert.assertEquals(true, list.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testContains() { | ||
for (int i = 0; i < 100; i++) { | ||
Assert.assertEquals(true, list.contains(i)); | ||
Assert.assertEquals(false, list.contains(i+100)); | ||
} | ||
} | ||
|
||
|
||
@Test | ||
public void testAddIntObject() { | ||
list.add(20,"test"); | ||
Assert.assertEquals("test", list.get(20)); | ||
} | ||
|
||
@Test | ||
public void testRemoveObject() { | ||
list.remove(30); | ||
Assert.assertEquals(31, list.get(30)); | ||
} | ||
|
||
@Test | ||
public void testSet() { | ||
for (int i = 0; i < 100; i++) { | ||
list.set(i, i+100); | ||
Assert.assertEquals(i+100, list.get(i)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testIndexOf() { | ||
list.set(3, "test"); | ||
Assert.assertEquals(3, list.indexOf("test")); | ||
} | ||
|
||
@Test | ||
public void testLastIndexOf() { | ||
list.set(3, "test"); | ||
list.set(33, "test"); | ||
Assert.assertEquals(33, list.lastIndexOf("test")); | ||
} | ||
|
||
@Test | ||
public void testHasNext(){ | ||
int i=0; | ||
|
||
for(Iterator it=list.iterator();it.hasNext();i++){ | ||
Assert.assertEquals(i, it.next()); | ||
// System.out.println(it.next()); | ||
} | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
group05/371492887/task_01/src/com/nitasty/test/QueueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.nitasty.test; | ||
|
||
import static org.junit.Assert.*; | ||
import junit.framework.Assert; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.nitasty.util.LinkedList; | ||
import com.nitasty.util.Queue; | ||
|
||
public class QueueTest { | ||
|
||
Queue queue; | ||
|
||
@Before | ||
public void init(){ | ||
queue=new Queue(); | ||
for (int i = 0; i < 100; i++) { | ||
queue.enQueue(i); | ||
} | ||
} | ||
|
||
@Test | ||
public void testDeQueue() { | ||
for(int i=0; i<100;i++){ | ||
Assert.assertEquals(i, queue.deQueue()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testIsEmpty() { | ||
for(int i=0; i<100;i++){ | ||
queue.deQueue(); | ||
if(i<99) | ||
Assert.assertEquals(false, queue.isEmpty()); | ||
} | ||
Assert.assertEquals(true, queue.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testSize() { | ||
for(int i=99; i>0;i--){ | ||
queue.deQueue(); | ||
Assert.assertEquals(i, queue.size()); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.