diff --git a/carnot/__init__.py b/carnot/__init__.py index 7ccf359..9dc0b7c 100644 --- a/carnot/__init__.py +++ b/carnot/__init__.py @@ -1,2 +1,4 @@ -from .carnot import * +from .my_carnot import * from .beacon import RandomBeaconHandler + +from carnot import merging_committees diff --git a/carnot/carnot-vote-aggregation.py b/carnot/carnot_vote_aggregation.py similarity index 99% rename from carnot/carnot-vote-aggregation.py rename to carnot/carnot_vote_aggregation.py index 81b471f..ab50c21 100644 --- a/carnot/carnot-vote-aggregation.py +++ b/carnot/carnot_vote_aggregation.py @@ -21,6 +21,8 @@ # Step 6: Block Proposal # The proposal of a new block is done using the propose_block function in Carnot psuedocode. +# UnHappy Path: + from dataclasses import dataclass from typing import Union, List, Set, Optional, Type, TypeAlias, Dict diff --git a/carnot/carnot.py b/carnot/my_carnot.py similarity index 100% rename from carnot/carnot.py rename to carnot/my_carnot.py diff --git a/carnot/test_carnot_vote_aggregation.py b/carnot/test_carnot_vote_aggregation.py new file mode 100644 index 0000000..cdfe815 --- /dev/null +++ b/carnot/test_carnot_vote_aggregation.py @@ -0,0 +1,34 @@ +import unittest + +import carnot +from carnot import merging_committees +from carnot.merging_committees import merge_committees +import itertools +import unittest + +class TestMergeCommittees(unittest.TestCase): + + def assertMergedSetsEqual(self, merged, original): + merged_elements = set(itertools.chain.from_iterable(merged)) + self.assertEqual(merged_elements, original) + + def test_merge_committees_even(self): + # Test merging when the number of committees is even + original_sets = [set([1, 2, 3]), set([4, 5, 6]), set([7, 8, 9]), set([10, 11, 12])] + merged = merge_committees(original_sets) + self.assertMergedSetsEqual(merged, set.union(*original_sets)) + + def test_merge_committees_odd(self): + # Test merging when the number of committees is odd + original_sets = [set([1, 2, 3]), set([4, 5, 6]), set([7, 8, 9])] + merged = merge_committees(original_sets) + self.assertMergedSetsEqual(merged, set.union(*original_sets)) + + def test_merge_committees_empty(self): + # Test merging when there are empty committees + original_sets = [set([1, 2, 3]), set([]), set([4, 5, 6])] + merged = merge_committees(original_sets) + self.assertMergedSetsEqual(merged, set.union(*original_sets)) + +if __name__ == '__main__': + unittest.main()