Skip to content

Commit b9b061c

Browse files
Simple BinaryTreeNode test pass
1 parent 9197183 commit b9b061c

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

group02/609990377/DataStructure/src/com/github/congcongcong250/coding2017/basic/BinaryTreeNode.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public void setRight(BinaryTreeNode right) {
3737
this.right = right;
3838
}
3939

40+
public void destroy(){
41+
this.data = null;
42+
this.left = null;
43+
this.right = null;
44+
}
45+
4046
public BinaryTreeNode insert(Object o){
4147
//If is empty root
4248
if(data == null){
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.github.congcongcong250.coding2017.basicTest;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.util.NoSuchElementException;
6+
7+
import org.junit.After;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
11+
import com.github.congcongcong250.coding2017.basic.BinaryTreeNode;
12+
13+
public class BinaryTreeNodeTest implements testCase {
14+
15+
BinaryTreeNode node = new BinaryTreeNode();
16+
17+
@Override
18+
@Before
19+
public void setUp() {
20+
node.insert(10);
21+
22+
}
23+
24+
@Override
25+
@After
26+
public void tearDown() {
27+
node.destroy();
28+
}
29+
30+
@Override
31+
@Test
32+
public void testAdd() {
33+
assertEquals(10,node.getData());
34+
node.insert(5);
35+
assertEquals(5,node.getLeft().getData());
36+
node.insert(1);
37+
node.insert(2);
38+
node.insert(6);
39+
node.insert(19);
40+
node.insert(18);
41+
/*
42+
* 10
43+
* 5 19
44+
* 1 6 18
45+
* 2
46+
*
47+
* */
48+
assertEquals(1,node.getLeft().getLeft().getData());
49+
assertEquals(2,node.getLeft().getLeft().getRight().getData());
50+
assertEquals(6,node.getLeft().getRight().getData());
51+
assertEquals(19,node.getRight().getData());
52+
assertEquals(18,node.getRight().getLeft().getData());
53+
}
54+
55+
@Override
56+
@Test
57+
public void testRemove() {
58+
// TODO Auto-generated method stub
59+
60+
}
61+
62+
@Override
63+
@Test
64+
public void testFunctional() {
65+
// TODO Auto-generated method stub
66+
67+
}
68+
69+
}

group02/609990377/DataStructure/src/com/github/congcongcong250/coding2017/basicTest/TestRunner.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ public static void main(String[] args){
1414
LinkedListTest LLT = new LinkedListTest();
1515
test(LLT);
1616

17+
StackTest STT = new StackTest();
18+
test(STT);
19+
20+
QueueTest QT = new QueueTest();
21+
test(QT);
22+
23+
BinaryTreeNodeTest BTNT = new BinaryTreeNodeTest();
24+
test(BTNT);
1725

1826
}
1927

@@ -23,7 +31,7 @@ private static Result test(testCase tc){
2331
for (Failure failure : result.getFailures()) {
2432
System.out.println(failure.toString());
2533
}
26-
System.out.println(result.wasSuccessful());
34+
System.out.println(tc.getClass().toString()+ "\n>>> Test status: "+result.wasSuccessful());
2735

2836
return result;
2937
}

0 commit comments

Comments
 (0)