summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHaidong Ji2019-06-09 16:51:07 -0500
committerHaidong Ji2019-06-09 16:51:07 -0500
commit560bb4c29cbbfd940e2773df0ff28d0315b16517 (patch)
tree6eb96446b793232217facd14e311ddd25e2e54c7 /tests
parent151a820c72161aacde623b444ab1f137689a36f5 (diff)
tree traversal done (in/pre/post) orders
Not too bad since I worked it out in Java first
Diffstat (limited to 'tests')
-rw-r--r--tests/tree_traversalTest.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/tree_traversalTest.py b/tests/tree_traversalTest.py
new file mode 100644
index 0000000..7fe79e3
--- /dev/null
+++ b/tests/tree_traversalTest.py
@@ -0,0 +1,37 @@
+import unittest
+
+from sources.tree_traversal import in_order, pre_order, post_order
+
+class MyTestCase(unittest.TestCase):
+ def test_something(self):
+ key = [4, 2, 5, 1, 3]
+ left = [1, 3, -1, -1, -1]
+ right = [2, 4, -1, -1, -1]
+
+ result = in_order(key, left, right)
+ self.assertEqual(len(result), 5)
+ self.assertEqual(result[0], 1)
+ self.assertEqual(result[1], 2)
+ self.assertEqual(result[2], 3)
+ self.assertEqual(result[3], 4)
+ self.assertEqual(result[4], 5)
+
+ result = pre_order(key, left, right)
+ self.assertEqual(len(result), 5)
+ self.assertEqual(result[0], 4)
+ self.assertEqual(result[1], 2)
+ self.assertEqual(result[2], 1)
+ self.assertEqual(result[3], 3)
+ self.assertEqual(result[4], 5)
+
+ result = post_order(key, left, right)
+ self.assertEqual(len(result), 5)
+ self.assertEqual(result[0], 1)
+ self.assertEqual(result[1], 3)
+ self.assertEqual(result[2], 2)
+ self.assertEqual(result[3], 5)
+ self.assertEqual(result[4], 4)
+
+
+if __name__ == '__main__':
+ unittest.main()