summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorHaidong Ji2019-06-11 22:21:50 -0500
committerHaidong Ji2019-06-11 22:21:50 -0500
commit578980d5ff80f94c9748d806879b7b707eec441e (patch)
treefd08842ba01121d16aa4267390f5eb865f8d9ce7 /src/test
parentad183107055509e73c7a0740c1dd633f212d0f51 (diff)
"is it binary search tree" done!
This is not too bad. Since I got the tree traversal done in the last exercise, I just used the in-order traversal as a base and modified a bit.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/TreeBstCheckTest.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/TreeBstCheckTest.java b/src/test/TreeBstCheckTest.java
new file mode 100644
index 0000000..7002d3e
--- /dev/null
+++ b/src/test/TreeBstCheckTest.java
@@ -0,0 +1,60 @@
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class TreeBstCheckTest {
+ @Test
+ void test() {
+ TreeBstCheck.TreeOrders tt = new TreeBstCheck.TreeOrders();
+ tt.key = new int[]{2, 1, 3};
+ tt.left = new int[]{1, -1, -1};
+ tt.right = new int[]{2, -1, -1};
+
+ assertTrue(tt.isBst());
+ }
+ @Test
+ void test1() {
+ TreeBstCheck.TreeOrders tt = new TreeBstCheck.TreeOrders();
+ tt.key = new int[]{1, 2, 3};
+ tt.left = new int[]{1, -1, -1};
+ tt.right = new int[]{2, -1, -1};
+
+ assertFalse(tt.isBst());
+ }
+ @Test
+ void test2() {
+ TreeBstCheck.TreeOrders tt = new TreeBstCheck.TreeOrders();
+ tt.key = new int[0];
+ tt.left = new int[0];
+ tt.right = new int[0];
+
+ assertTrue(tt.isBst());
+ }
+ @Test
+ void test3() {
+ TreeBstCheck.TreeOrders tt = new TreeBstCheck.TreeOrders();
+ tt.key = new int[]{1, 2, 3, 4, 5};
+ tt.left = new int[]{-1, -1, -1, -1, -1};
+ tt.right = new int[]{1, 2, 3, 4, -1};
+
+ assertTrue(tt.isBst());
+ }
+ @Test
+ void test4() {
+ TreeBstCheck.TreeOrders tt = new TreeBstCheck.TreeOrders();
+ tt.key = new int[]{4, 2, 6, 1, 3, 5, 7};
+ tt.left = new int[]{1, 3, 5, -1, -1, -1, -1};
+ tt.right = new int[]{2, 4, 6, -1, -1, -1, -1};
+
+ assertTrue(tt.isBst());
+ }
+ @Test
+ void test5() {
+ TreeBstCheck.TreeOrders tt = new TreeBstCheck.TreeOrders();
+ tt.key = new int[]{4, 2, 1, 5};
+ tt.left = new int[]{1, 2, -1, -1};
+ tt.right = new int[]{-1, 3, -1, -1};
+
+ assertFalse(tt.isBst());
+ }
+}