From 55a780d295ef2a852d7b7b89d43e388b3f16f79d Mon Sep 17 00:00:00 2001 From: danielsanchezq Date: Fri, 30 Jun 2023 09:20:26 +0200 Subject: [PATCH] Root parent is None --- carnot/test_tree_overlay.py | 4 ++++ carnot/tree_overlay.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/carnot/test_tree_overlay.py b/carnot/test_tree_overlay.py index 32caf1d..5a035af 100644 --- a/carnot/test_tree_overlay.py +++ b/carnot/test_tree_overlay.py @@ -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] diff --git a/carnot/tree_overlay.py b/carnot/tree_overlay.py index 19b8084..142015d 100644 --- a/carnot/tree_overlay.py +++ b/carnot/tree_overlay.py @@ -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]]: