summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorHaidong Ji2019-01-07 20:06:57 -0600
committerHaidong Ji2019-01-07 20:06:57 -0600
commit926b055030fcd6f8564138819c747b97bf664954 (patch)
tree0b33ae2de3b977b08f5a46d1147cf2190af4e495 /src/test
parenta318045cf5c15cadad5c067ab6af5aa498bd155e (diff)
Tree height recursive version done!
Following example starter code, I had to specify stackSize when creating the thread. Without it, it won't pass tests due to stack overflow error. I'll still try to work out an iterative version using Queue. We'll see.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/TreeHeightTest.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/TreeHeightTest.java b/src/test/TreeHeightTest.java
new file mode 100644
index 0000000..0fe3e57
--- /dev/null
+++ b/src/test/TreeHeightTest.java
@@ -0,0 +1,47 @@
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class TreeHeightTest {
+ @Test
+ void test1() {
+ int[] a = {4, -1, 4, 1, 1};
+ assertEquals(3, TreeHeight.getHeight(a));
+ }
+
+ @Test
+ void test2() {
+ int[] a = {-1, 0, 4, 0, 3};
+ assertEquals(4, TreeHeight.getHeight(a));
+ }
+
+ @Test
+ void test3() {
+ int[] a = {4, -1, 4, 1, 1};
+ assertEquals(3, TreeHeight.getHeightNaive(a));
+ }
+
+ @Test
+ void test4() {
+ int[] a = {-1, 0, 4, 0, 3};
+ assertEquals(4, TreeHeight.getHeightNaive(a));
+ }
+
+ @Test
+ void test5() {
+ int[] a = {9, 7, 5, 5, 2, 9, 9, 9, 2, -1};
+ assertEquals(4, TreeHeight.getHeightNaive(a));
+ }
+
+ @Test
+ void test6() {
+ int[] a = {9, 7, 5, 5, 2, 9, 9, 9, 2, -1};
+ assertEquals(4, TreeHeight.getHeight(a));
+ }
+
+ @Test
+ void test7() {
+ int[] a = {8, 8, 5, 6, 7, 3, 1, 6, -1, 5};
+ assertEquals(6, TreeHeight.getHeight(a));
+ }
+}