mamweb/treenode/tests.py

41 lines
1.6 KiB
Python
Raw Normal View History

2020-04-30 00:41:12 +02:00
from django.test import TestCase
2021-11-07 10:25:34 +01:00
import treenode.treelib as tl
2024-11-01 13:50:48 +01:00
from .models import CastNode
2020-04-30 00:41:12 +02:00
class SimpleTreeLibTests(TestCase):
def setUp(self):
# Vyrobíme pár nějakých Nodů
2024-11-01 13:50:48 +01:00
self.root = CastNode(root=None, first_child=None, succ=None, nadpis="Root")
2020-04-30 00:41:12 +02:00
self.root.save()
2024-11-01 13:50:48 +01:00
self.some_node = CastNode(root=self.root, first_child=None, succ=None, nadpis="Přetržené")
self.other_node = CastNode(root=self.root, first_child=None, succ=None, nadpis="Dítě")
self.some_orphan = CastNode(root=None, first_child=None, succ=None, nadpis="Ošklivé")
self.other_orphan = CastNode(root=None, first_child=None, succ=None, nadpis="Káčátko")
2020-04-30 00:41:12 +02:00
# 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):
# safe_pred
2020-04-30 00:41:12 +02:00
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))
# safe_father_of_first
self.assertIsNone(tl.safe_father_of_first(self.root))
self.assertEqual(tl.safe_father_of_first(self.some_node), self.root)
self.assertEqual(tl.safe_father_of_first(self.other_node), self.root)
self.assertIsNone(tl.safe_father_of_first(self.some_orphan))
self.assertEqual(tl.safe_father_of_first(self.other_orphan), self.some_orphan)