Root parent is None

This commit is contained in:
danielsanchezq 2023-06-30 09:20:26 +02:00
parent 12ae3532b3
commit 55a780d295
2 changed files with 7 additions and 0 deletions

View File

@ -15,6 +15,10 @@ class TestCarnotTree(TestCase):
self.assertIs(self.tree.parent_committee(one), root)
self.assertIs(self.tree.parent_committee(two), root)
def test_root_parenting(self):
root = self.tree.inner_committees[0]
self.assertIsNone(self.tree.parent_committee(root))
def test_childs(self):
root = self.tree.inner_committees[0]
one = self.tree.inner_committees[1]

View File

@ -46,6 +46,9 @@ class CarnotTree:
return hashes, dict(enumerate(committees))
def parent_committee(self, committee_id: Id) -> Optional[Id]:
# root committee doesnt have a parent
if committee_id == self.inner_committees[0]:
return None
return self.inner_committees[max(self.committees[committee_id] // 2 - 1, 0)]
def child_committees(self, committee_id: Id) -> Tuple[Optional[Id], Optional[Id]]: