summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorHaidong Ji2019-06-09 11:54:36 -0500
committerHaidong Ji2019-06-09 11:54:36 -0500
commitad183107055509e73c7a0740c1dd633f212d0f51 (patch)
tree41bf4a7e182bf8c0b9320b9e523b27ef5398862d /src/test
parentbf7d8fa962098eeafc4eed84e4ae0450806a43c3 (diff)
woohoo, tree order traversal done!
Once again a lot of fun. I had about 3 months hiatus due to house purchasing, where I didn't touch this exercise, more or less. Today I made an effort following TDD and got the last post order traversal done! I worried if edx/course staff stopped the auto grader. It turned out they didn't. Really happy :)
Diffstat (limited to 'src/test')
-rw-r--r--src/test/TreeTraversalTest.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/TreeTraversalTest.java b/src/test/TreeTraversalTest.java
index 1fd23ea..7e9773c 100644
--- a/src/test/TreeTraversalTest.java
+++ b/src/test/TreeTraversalTest.java
@@ -75,5 +75,33 @@ class TreeTraversalTest {
assertEquals(20, tt.postOrder().get(8));
assertEquals(0, tt.postOrder().get(9));
}
+ @Test
+ void test2() {
+ TreeTraversal.TreeOrders tt = new TreeTraversal.TreeOrders();
+ tt.key = new int[]{782521203, 839950857, 248660666, 696374696, 971981286};
+ tt.left = new int[]{4, -1, 3, -1, 1};
+ tt.right = new int[]{-1, -1, -1, -1, 2};
+
+ assertEquals(5, tt.inOrder().size());
+ assertEquals(839950857, tt.inOrder().get(0));
+ assertEquals(971981286, tt.inOrder().get(1));
+ assertEquals(696374696, tt.inOrder().get(2));
+ assertEquals(248660666, tt.inOrder().get(3));
+ assertEquals(782521203, tt.inOrder().get(4));
+
+ assertEquals(5, tt.preOrder().size());
+ assertEquals(782521203, tt.preOrder().get(0));
+ assertEquals(971981286, tt.preOrder().get(1));
+ assertEquals(839950857, tt.preOrder().get(2));
+ assertEquals(248660666, tt.preOrder().get(3));
+ assertEquals(696374696, tt.preOrder().get(4));
+
+ assertEquals(5, tt.postOrder().size());
+ assertEquals(839950857, tt.postOrder().get(0));
+ assertEquals(696374696, tt.postOrder().get(1));
+ assertEquals(248660666, tt.postOrder().get(2));
+ assertEquals(971981286, tt.postOrder().get(3));
+ assertEquals(782521203, tt.postOrder().get(4));
+ }
} \ No newline at end of file