summaryrefslogtreecommitdiff
path: root/tests/tree_traversalTest.py
blob: 7fe79e3c9410cd2d8eacc739cb3113d6a95db546 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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()