From 8bdfa745e90eb619037c13a56d2455f7b321c67b Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Thu, 30 Apr 2020 00:41:12 +0200 Subject: [PATCH] =?UTF-8?q?Za=C4=8D=C3=A1tek=20test=C5=AF=20TreeLib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/tests_treelib.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 seminar/tests_treelib.py diff --git a/seminar/tests_treelib.py b/seminar/tests_treelib.py new file mode 100644 index 00000000..9c67ca22 --- /dev/null +++ b/seminar/tests_treelib.py @@ -0,0 +1,32 @@ +from django.test import TestCase +import seminar.treelib as tl +import seminar.models as m + +class SimpleTreeLibTests(TestCase): + def setUp(self): + # Vyrobíme pár nějakých Nodů + self.root = m.CastNode(root=None, first_child=None, succ=None, nadpis="Root") + self.root.save() + self.some_node = m.CastNode(root=self.root, first_child=None, succ=None, nadpis="Přetržené") + self.other_node = m.CastNode(root=self.root, first_child=None, succ=None, nadpis="Dítě") + self.some_orphan = m.CastNode(root=None, first_child=None, succ=None, nadpis="Ošklivé") + self.other_orphan = m.CastNode(root=None, first_child=None, succ=None, nadpis="Káčátko") + + # Trochu je pospojujeme + self.root.first_child = self.some_node + self.some_node.succ = self.other_node + self.some_orphan.first_child = self.other_orphan + + # Všechno uložíme + self.other_node.save() + self.some_node.save() + self.other_orphan.save() + self.some_orphan.save() + self.root.save() + + def test_safe_functions(self): + self.assertEqual(tl.safe_pred(self.other_node), self.some_node) + self.assertIsNone(tl.safe_pred(self.root)) + self.assertIsNone(tl.safe_pred(self.some_node)) + self.assertIsNone(tl.safe_pred(self.some_orphan)) + self.assertIsNone(tl.safe_pred(self.other_orphan))