diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..cc95d0d5 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,21 @@ +name: Unit Tests + +on: + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Run tests + run: python -m unittest discover \ No newline at end of file diff --git a/laboratories/cicd-documentation/gigel.md b/laboratories/cicd-documentation/gigel.md new file mode 100644 index 00000000..41dc3560 --- /dev/null +++ b/laboratories/cicd-documentation/gigel.md @@ -0,0 +1 @@ +# HI \ No newline at end of file diff --git a/laboratories/cicd-documentation/tree.py b/laboratories/cicd-documentation/tree.py index 2639fcd1..e399b7bc 100644 --- a/laboratories/cicd-documentation/tree.py +++ b/laboratories/cicd-documentation/tree.py @@ -1,5 +1,5 @@ from node import Node - +import unittest class Tree: """ Tree class for binary tree """ @@ -76,10 +76,33 @@ def _printInorderTree(self, node): def _printPreorderTree(self, node): # TODO - pass + if node is not None: + print(str(node.data) + ' ') + self._printPreorderTree(node.left) + self._printPostorderTree(node.right) def _printPostorderTree(self, node): # TODO - pass + if node is not None: + self._printPreorderTree(node.left) + self._printPostorderTree(node.right) + print(str(node.data) + ' ') + + +class TestTreeFind(unittest.TestCase): + def setUp(self): + self.tree = Tree() + values = [50, 30, 70, 20, 40] + for v in values: + self.tree.add(v) + + def test_find_non_existing_element(self): + result = self.tree.find(100) + self.assertIsNone(result, "Should be none") + def test_find_root(self): + result = self.tree.find(50) + self.assertEqual(result, self.tree.getRoot(), "Root was not found.") +if __name__ == '__main__': + unittest.main()