forked from haoel/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inorderSuccessorInBSTTest.java
53 lines (42 loc) · 1.42 KB
/
inorderSuccessorInBSTTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package inorderSuccessorInBST;
import org.junit.Test;
import java.util.ArrayList;
import static org.junit.Assert.*;
/**
* Created by leicao on 7/10/15.
*/
public class inorderSuccessorInBSTTest {
@Test
public void testInorderSuccessor() throws Exception {
ArrayList<TreeNode> inputes = new ArrayList<TreeNode>();
ArrayList<TreeNode> targets = new ArrayList<TreeNode>();
TreeNode n0 = new TreeNode(2);
TreeNode n1 = new TreeNode(1);
TreeNode n2 = new TreeNode(3);
n0.left = n1;
n0.right = n2;
inputes.add(n0);
targets.add(n2);
TreeNode nn0 = new TreeNode(2);
TreeNode nn1 = new TreeNode(1);
nn0.left = nn1;
inputes.add(nn0);
targets.add(nn1);
TreeNode t0 = new TreeNode(1);
TreeNode t1 = new TreeNode(2);
t0.right = t1;
inputes.add(t0);
targets.add(t0);
ArrayList<TreeNode> results = new ArrayList<TreeNode>();
results.add(null);
results.add(nn0);
results.add(t1);
for (int i = 0; i < results.size(); i++) {
inorderSuccessorInBST finder = new inorderSuccessorInBST();
TreeNode node = finder.inorderSuccessor(inputes.get(i), targets.get(i));
System.out.println(node);
boolean result = node == results.get(i) || node.val == results.get(i).val;
assertTrue(result);
}
}
}