From 926b055030fcd6f8564138819c747b97bf664954 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Mon, 7 Jan 2019 20:06:57 -0600 Subject: 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. --- src/test/TreeHeightTest.java | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/TreeHeightTest.java (limited to 'src/test') 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)); + } +} -- cgit v1.2.3