diff --git a/carnot/Carnot-Simulation-Psuedocode.py b/carnot/carnot_simulation_psuedocode.py similarity index 91% rename from carnot/Carnot-Simulation-Psuedocode.py rename to carnot/carnot_simulation_psuedocode.py index e664864..890f7f7 100644 --- a/carnot/Carnot-Simulation-Psuedocode.py +++ b/carnot/carnot_simulation_psuedocode.py @@ -2,11 +2,10 @@ import time class Committee: - def __init__(self, committee_id, processing_time=0, parent_committee=None): + def __init__(self, committee_id, parent_committee=None): self.committee_id = committee_id self.child_committee = None self.parent_committee = parent_committee - # self.processing_time = processing_time def create_binary_tree_committees(num_levels, committee_id=0, parent_committee=None): """ @@ -24,7 +23,7 @@ def create_binary_tree_committees(num_levels, committee_id=0, parent_committee=N return None processing_time = 1 # Set the processing time for each committee (you can adjust this as needed) - committee = Committee(committee_id, processing_time, parent_committee) + committee = Committee(committee_id, parent_committee) committee.child_committee = create_binary_tree_committees(num_levels - 1, committee_id + 1, committee) return committee diff --git a/carnot/test_carnot_simulation.py b/carnot/test_carnot_simulation.py new file mode 100644 index 0000000..4821375 --- /dev/null +++ b/carnot/test_carnot_simulation.py @@ -0,0 +1,61 @@ +from carnot_simulation_psuedocode import * + +import time + +def test_message_passing(): + # Test Case 1: Binary tree with 3 levels (L0, L1, L2) + num_levels = 3 + root_committee = create_binary_tree_committees(num_levels) + + # Find the leaf committee at the lowest level + leaf_committee = find_leaf_committee(root_committee) + + # Start message passing from the leaf committee at the lowest level and move towards the root at the highest level + latency = 1 # Set the latency for message passing (you can adjust this as needed) + start_time = time.time() + result = simulate_message_passing(leaf_committee, latency) + end_time = time.time() + + expected_result = num_levels - 1 + assert result == expected_result, f"Test Case 1 failed. Expected: {expected_result}, Got: {result}" + + print(f"Test Case 1: Number of Levels Message Passed: {result}, Elapsed Time: {end_time - start_time:.4f} seconds") + + # Test Case 2: Binary tree with 5 levels (L0, L1, L2, L3, L4) + num_levels = 5 + root_committee = create_binary_tree_committees(num_levels) + + # Find the leaf committee at the lowest level + leaf_committee = find_leaf_committee(root_committee) + + # Start message passing from the leaf committee at the lowest level and move towards the root at the highest level + latency = 0.5 # Set the latency for message passing (you can adjust this as needed) + start_time = time.time() + result = simulate_message_passing(leaf_committee, latency) + end_time = time.time() + + expected_result = num_levels - 1 + assert result == expected_result, f"Test Case 2 failed. Expected: {expected_result}, Got: {result}" + + print(f"Test Case 2: Number of Levels Message Passed: {result}, Elapsed Time: {end_time - start_time:.4f} seconds") + + # Test Case 3: Binary tree with 1 level (Only the root committee) + num_levels = 1 + root_committee = create_binary_tree_committees(num_levels) + + # Find the leaf committee at the lowest level (which is also the root) + leaf_committee = find_leaf_committee(root_committee) + + # Start message passing from the leaf committee (which is also the root) + latency = 0.1 # Set the latency for message passing (you can adjust this as needed) + start_time = time.time() + result = simulate_message_passing(leaf_committee, latency) + end_time = time.time() + + expected_result = num_levels - 1 + assert result == expected_result, f"Test Case 3 failed. Expected: {expected_result}, Got: {result}" + + print(f"Test Case 3: Number of Levels Message Passed: {result}, Elapsed Time: {end_time - start_time:.4f} seconds") + +if __name__ == "__main__": + test_message_passing()