Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartheyan committed Apr 14, 2024
1 parent 9348a44 commit 26f7a3c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 6 deletions.
88 changes: 86 additions & 2 deletions tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,18 @@ def mes_phragmen(instance, profile, resoluteness=True):
frac(1, 2),
frac(1, 2),
],
[
frac(3, 8),
frac(3, 8),
frac(3, 8),
frac(3, 8),
frac(3, 8),
frac(3, 8),
frac(3, 8),
frac(3, 8),
frac(1, 2),
frac(1, 2),
]
],
),
(
Expand Down Expand Up @@ -739,6 +751,18 @@ def mes_phragmen(instance, profile, resoluteness=True):
frac(1, 2),
frac(1, 2),
],
[
frac(1, 24),
frac(1, 24),
frac(3, 8),
frac(1, 24),
frac(3, 8),
frac(3, 8),
frac(3, 8),
frac(3, 8),
frac(1, 2),
frac(1, 2),
]
],
),
(
Expand Down Expand Up @@ -771,6 +795,18 @@ def mes_phragmen(instance, profile, resoluteness=True):
frac(1, 2),
frac(1, 2),
],
[
frac(1, 8),
frac(1, 8),
frac(3, 8),
frac(1, 8),
frac(1, 8),
frac(3, 8),
frac(3, 8),
frac(3, 8),
frac(1, 2),
frac(1, 2)
],
],
),
(
Expand Down Expand Up @@ -803,9 +839,32 @@ def mes_phragmen(instance, profile, resoluteness=True):
frac(1, 2),
frac(1, 2),
],
[
frac(1, 4),
frac(1, 4),
frac(1, 2),
frac(1, 4),
frac(1, 4),
frac(1, 2),
frac(0, 1),
frac(0, 1),
frac(1, 2),
frac(1, 2)
]
],
),
([5, 5, 5, 5, 5], [0, 1, 2], [0, 1, 2], [], []),
([5, 5, 5, 5, 5], [0, 1, 2], [0, 1, 2], [], [
[frac(1, 2),
frac(1, 2),
frac(1, 2),
frac(1, 2),
frac(1, 2),
frac(1, 2),
frac(1, 2),
frac(1, 2),
frac(1, 2),
frac(1, 2)]
]),
(
[5, 1, 2, 1, 2],
[0, 1, 2],
Expand All @@ -828,6 +887,14 @@ def mes_phragmen(instance, profile, resoluteness=True):
frac(1, 2),
frac(1, 2),
],
[
frac(1, 4),
frac(1, 2),
frac(1, 4),
frac(1, 2),
frac(0, 1),
frac(1, 2),
],
],
True,
[2, 1, 2, 1, 2, 2],
Expand All @@ -854,6 +921,14 @@ def mes_phragmen(instance, profile, resoluteness=True):
frac(1, 2),
frac(1, 2),
],
[
frac(1, 4),
frac(1, 2),
frac(1, 4),
frac(1, 2),
frac(0, 1),
frac(1, 2),
],
],
True,
[2, 1, 2, 1, 2, 2],
Expand All @@ -880,6 +955,14 @@ def mes_phragmen(instance, profile, resoluteness=True):
frac(1, 2),
frac(1, 2),
],
[
frac(1, 4),
frac(1, 2),
frac(1, 4),
frac(1, 2),
frac(0, 1),
frac(1, 2),
],
],
True,
[2, 1, 2, 1, 2, 2],
Expand Down Expand Up @@ -991,6 +1074,7 @@ def test_iterated_exhaustion_analytics(self):
[frac(1, 2)] * 6 + [frac(2, 3)] * 4,
[frac(1, 6)] * 2 + [frac(1, 2)] * 4 + [frac(1, 3)] + [frac(2, 3)] * 3,
[frac(1, 6)] * 4 + [frac(1, 2)] * 2 + [0] + [frac(2, 3)] * 3,
[frac(1, 6)] * 4 + [frac(1, 6)] * 3 + [frac(2, 3)] * 3 + [0] * 3 + [frac(2, 3)] * 3,
]

assert sorted(
Expand All @@ -1005,7 +1089,7 @@ def test_iterated_exhaustion_analytics(self):
] == frac(2, 3)
assert (
budget_allocation_mes_iterated.details.get_all_selected_projects()
== list(budget_allocation_mes_iterated)
== list(budget_allocation_mes_iterated) + [None]
)
for idx, iteration in enumerate(
budget_allocation_mes_iterated.details.iterations
Expand Down
8 changes: 4 additions & 4 deletions tests/test_visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def test_mes_visualisation(self):
outcome = method_of_equal_shares(instance, profile, sat_class=Cost_Sat, analytics=True)
vis = MESVisualiser(profile, instance, outcome)
with tempfile.TemporaryDirectory() as temp_dir:
vis.render(temp_dir)
summary_file_path = os.path.join(temp_dir, "summary.html")
round_analysis_file_path = os.path.join(temp_dir, "round_analysis.html")
vis.render(temp_dir, name="test")
summary_file_path = os.path.join(temp_dir, "test_summary.html")
round_analysis_file_path = os.path.join(temp_dir, "test_round_analysis.html")
assert os.path.isfile(summary_file_path)
assert os.path.isfile(round_analysis_file_path)
with open(summary_file_path, "r") as summary_file:
assert "<!DOCTYPE html>" in summary_file.read()
with open(round_analysis_file_path, "r") as round_analysis_file:
assert "<!DOCTYPE html>" in round_analysis_file.read()
assert len(vis.rounds) == 4 == len(outcome.details.iterations)
assert len(vis.rounds) == 4 == len(outcome.details.iterations) - 1

0 comments on commit 26f7a3c

Please sign in to comment.