Skip to content

Commit 0f37944

Browse files
authored
Merge pull request onlyliuxin#8 from nitasty009/master
pull
2 parents f75d55d + e978f24 commit 0f37944

17 files changed

+1473
-0
lines changed

coding2017-1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit b5be7e853cd9d2f5bbcc43149dc4df83749759a2

group05/371492887/task_01/.classpath

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

group05/371492887/task_01/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

group05/371492887/task_01/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>task_01</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.nitasty.test;
2+
3+
import static org.junit.Assert.*;
4+
import junit.framework.Assert;
5+
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
9+
import com.nitasty.util.ArrayList;
10+
import com.nitasty.util.Iterator;
11+
12+
public class ArrayListTest {
13+
14+
private ArrayList list;
15+
16+
@Before
17+
public void init(){
18+
list=new ArrayList();
19+
for (int i = 0; i < 100; i++) {
20+
list.add(i);
21+
}
22+
}
23+
24+
@Test
25+
public void testAddObject() {
26+
list.add(100);
27+
Assert.assertEquals(101, list.size());
28+
}
29+
30+
@Test
31+
public void testAddIntObject() {
32+
list.add(3,"test");
33+
Assert.assertEquals("test", list.get(3));
34+
}
35+
36+
@Test
37+
public void testRemoveInt() {
38+
list.add(3,"test");
39+
list.remove(3);
40+
Assert.assertEquals(3, list.get(3));
41+
}
42+
43+
@Test
44+
public void testRemoveObject() {
45+
list.add(0,"test");
46+
list.remove("test");
47+
Assert.assertEquals(0, list.get(0));
48+
}
49+
50+
51+
@Test
52+
public void testIsEmpty() {
53+
list.clear();
54+
Assert.assertEquals(true, list.isEmpty());
55+
}
56+
57+
@Test
58+
public void testContains() {
59+
Assert.assertEquals(false, list.contains("test"));
60+
list.add("test");
61+
Assert.assertEquals(true, list.contains("test"));
62+
}
63+
64+
65+
66+
@Test
67+
public void testSet() {
68+
Assert.assertEquals(true, list.contains(3));
69+
list.set(3, "test");
70+
Assert.assertEquals(true, list.contains("test"));
71+
Assert.assertEquals(false, list.contains(3));
72+
}
73+
74+
@Test
75+
public void testIndexOf() {
76+
list.set(3, "test");
77+
Assert.assertEquals(3, list.indexOf("test"));
78+
}
79+
80+
@Test
81+
public void testLastIndexOf() {
82+
list.set(3, "test");
83+
list.set(33, "test");
84+
Assert.assertEquals(33, list.lastIndexOf("test"));
85+
}
86+
87+
@Test
88+
public void testHasNext(){
89+
int i=0;
90+
for(Iterator it=list.iterator();it.hasNext();i++){
91+
Assert.assertEquals(i, it.next());
92+
// System.out.println(it.next());
93+
}
94+
}
95+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.nitasty.test;
2+
3+
import static org.junit.Assert.*;
4+
import junit.framework.Assert;
5+
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
9+
import com.nitasty.util.BinaryTree;
10+
11+
public class BinaryTreeTest {
12+
13+
BinaryTree<Integer> tree;
14+
15+
@Before
16+
public void init(){
17+
tree=new BinaryTree<Integer>();
18+
tree.insert(5);
19+
tree.insert(3);
20+
tree.insert(8);
21+
tree.insert(2);
22+
tree.insert(7);
23+
tree.insert(9);
24+
tree.insert(1);
25+
tree.insert(4);
26+
tree.insert(10);
27+
tree.insert(6);
28+
}
29+
30+
@Test
31+
public void testMakeEmpty() {
32+
tree.makeEmpty();
33+
Assert.assertEquals(true, tree.isEmpty());
34+
}
35+
36+
@Test
37+
public void testGetHeight() {
38+
Assert.assertEquals(3, tree.getHeight());
39+
}
40+
41+
@Test
42+
public void testContains() {
43+
for (int i = 1; i < 11; i++) {
44+
Assert.assertEquals(true, tree.contains(i));
45+
}
46+
}
47+
48+
@Test
49+
public void testFindMin() {
50+
Assert.assertEquals(1, tree.findMin());
51+
}
52+
53+
@Test
54+
public void testFindMax() {
55+
Assert.assertEquals(10, tree.findMax());
56+
}
57+
58+
59+
@Test
60+
public void testRemove() {
61+
tree.remove(3);
62+
Assert.assertEquals(false, tree.contains(3));
63+
}
64+
65+
66+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package com.nitasty.test;
2+
3+
import static org.junit.Assert.*;
4+
import junit.framework.Assert;
5+
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
9+
import com.nitasty.util.ArrayList;
10+
import com.nitasty.util.Iterator;
11+
import com.nitasty.util.LinkedList;
12+
13+
public class LinkedListTest {
14+
15+
private LinkedList list;
16+
17+
@Before
18+
public void init(){
19+
list=new LinkedList();
20+
for (int i = 0; i < 100; i++) {
21+
list.add(i);
22+
}
23+
}
24+
25+
@Test
26+
public void testGet() {
27+
IndexOutOfBoundsException tx=null;
28+
for (int i = 0; i < 100; i++) {
29+
Assert.assertEquals(i, list.get(i));
30+
}
31+
32+
try {
33+
list.get(100);
34+
} catch (IndexOutOfBoundsException e) {
35+
tx=e;
36+
}
37+
Assert.assertEquals(IndexOutOfBoundsException.class,tx.getClass());
38+
}
39+
40+
@Test
41+
public void testRemoveInt() {
42+
for (int i = 99; i >= 0; i--) {
43+
Assert.assertEquals(i, list.remove(i));
44+
}
45+
}
46+
47+
@Test
48+
public void testSize() {
49+
Assert.assertEquals(100, list.size());
50+
}
51+
52+
@Test
53+
public void testAddFirst() {
54+
list.addFirst(-1);
55+
for (int i = 0; i < 101; i++) {
56+
Assert.assertEquals(i-1, list.get(i));
57+
}
58+
}
59+
60+
@Test
61+
public void testAddLast() {
62+
63+
for (int i = 100; i < 1000; i++) {
64+
list.addLast(i);
65+
}
66+
67+
for (int i = 0; i < 1000; i++) {
68+
Assert.assertEquals(i, list.get(i));
69+
}
70+
}
71+
72+
@Test
73+
public void testAddBefore() {
74+
list.addBefore(66,list.node(3));
75+
Assert.assertEquals(66, list.get(3));
76+
}
77+
78+
@Test
79+
public void testAddAfter() {
80+
list.addAfter(66,list.node(3));
81+
Assert.assertEquals(66, list.get(4));
82+
}
83+
84+
@Test
85+
public void testIsEmpty() {
86+
list.clear();
87+
Assert.assertEquals(true, list.isEmpty());
88+
}
89+
90+
@Test
91+
public void testContains() {
92+
for (int i = 0; i < 100; i++) {
93+
Assert.assertEquals(true, list.contains(i));
94+
Assert.assertEquals(false, list.contains(i+100));
95+
}
96+
}
97+
98+
99+
@Test
100+
public void testAddIntObject() {
101+
list.add(20,"test");
102+
Assert.assertEquals("test", list.get(20));
103+
}
104+
105+
@Test
106+
public void testRemoveObject() {
107+
list.remove(30);
108+
Assert.assertEquals(31, list.get(30));
109+
}
110+
111+
@Test
112+
public void testSet() {
113+
for (int i = 0; i < 100; i++) {
114+
list.set(i, i+100);
115+
Assert.assertEquals(i+100, list.get(i));
116+
}
117+
}
118+
119+
@Test
120+
public void testIndexOf() {
121+
list.set(3, "test");
122+
Assert.assertEquals(3, list.indexOf("test"));
123+
}
124+
125+
@Test
126+
public void testLastIndexOf() {
127+
list.set(3, "test");
128+
list.set(33, "test");
129+
Assert.assertEquals(33, list.lastIndexOf("test"));
130+
}
131+
132+
@Test
133+
public void testHasNext(){
134+
int i=0;
135+
136+
for(Iterator it=list.iterator();it.hasNext();i++){
137+
Assert.assertEquals(i, it.next());
138+
// System.out.println(it.next());
139+
}
140+
}
141+
142+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.nitasty.test;
2+
3+
import static org.junit.Assert.*;
4+
import junit.framework.Assert;
5+
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
9+
import com.nitasty.util.LinkedList;
10+
import com.nitasty.util.Queue;
11+
12+
public class QueueTest {
13+
14+
Queue queue;
15+
16+
@Before
17+
public void init(){
18+
queue=new Queue();
19+
for (int i = 0; i < 100; i++) {
20+
queue.enQueue(i);
21+
}
22+
}
23+
24+
@Test
25+
public void testDeQueue() {
26+
for(int i=0; i<100;i++){
27+
Assert.assertEquals(i, queue.deQueue());
28+
}
29+
}
30+
31+
@Test
32+
public void testIsEmpty() {
33+
for(int i=0; i<100;i++){
34+
queue.deQueue();
35+
if(i<99)
36+
Assert.assertEquals(false, queue.isEmpty());
37+
}
38+
Assert.assertEquals(true, queue.isEmpty());
39+
}
40+
41+
@Test
42+
public void testSize() {
43+
for(int i=99; i>0;i--){
44+
queue.deQueue();
45+
Assert.assertEquals(i, queue.size());
46+
}
47+
}
48+
49+
}

0 commit comments

Comments
 (0)