Skip to content

Commit 401c3c5

Browse files
committed
add new multiplicity tests
1 parent 0029e88 commit 401c3c5

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

tests/test_analysis.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def test_profile_properties(self):
261261
assert median_total_score(instance, card_multi_profile) == 3
262262

263263
def test_project_loss(self):
264-
projects = [Project(chr(ord("a") + idx), 2) for idx in range(6)]
264+
projects = [Project(chr(ord("a") + idx), 4) for idx in range(6)]
265265
supporters = [[0, 1, 2, 4], [2, 3, 4], [0, 2], [0, 1], [4], [5]]
266266
was_picked = [True, True, False, False, False, False]
267267
voters_budget = [
@@ -280,28 +280,28 @@ def test_project_loss(self):
280280
)
281281
for idx in range(len(projects))
282282
]
283-
allocation_details = MESAllocationDetails(initial_budget_per_voter)
283+
allocation_details = MESAllocationDetails(
284+
initial_budget_per_voter,
285+
[2 for _ in range(len(voters_budget[0]))],
286+
)
284287
allocation_details.iterations = iterations
285288

286289
project_losses = calculate_project_loss(allocation_details)
287-
expected_budgets = [
288-
frac(4, 1),
289-
frac(2, 1),
290-
frac(1, 2),
291-
frac(1, 1),
292-
frac(0, 1),
293-
frac(1, 1),
294-
]
290+
expected_budgets = [8, 4, 1, 2, 0, 2]
295291
expected_losses = [
296292
{},
297-
{projects[0]: frac(1, 1)},
298-
{projects[0]: frac(1, 1), projects[1]: frac(1, 2)},
299-
{projects[0]: frac(1, 1)},
300-
{projects[0]: frac(1, 2), projects[1]: frac(1, 2)},
293+
{projects[0]: 2},
294+
{projects[0]: 2, projects[1]: 1},
295+
{projects[0]: 2},
296+
{projects[0]: 1, projects[1]: 1},
301297
{},
302298
]
303299

304300
for idx, project_loss in enumerate(project_losses):
305301
assert project_loss.name == projects[idx].name
306302
assert project_loss.supporters_budget == expected_budgets[idx]
307303
assert project_loss.budget_lost == expected_losses[idx]
304+
305+
# No iterations
306+
project_losses = calculate_project_loss(MESAllocationDetails(1, [1]))
307+
assert project_losses == []

tests/test_rule.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,16 @@ def mes_phragmen(instance, profile, resoluteness=True):
725725
[frac(1, 2), frac(1, 2), frac(1, 2), frac(1, 2), frac(1, 2)],
726726
[frac(1, 2), frac(1, 2), frac(1, 2), frac(1, 2), frac(1, 2)],
727727
),
728+
(
729+
[5, 1, 2, 1, 2],
730+
[0, 1, 2],
731+
[0, 1, 2],
732+
[1, 3],
733+
[frac(1, 2), frac(1, 4), frac(1, 4), frac(1, 4), frac(1, 4)],
734+
[frac(1, 2), frac(1, 4), frac(1, 4), frac(1, 4), frac(1, 4)],
735+
True,
736+
[2, 1, 2, 1, 2, 2],
737+
),
728738
]
729739
)
730740
def test_mes_analytics(
@@ -735,6 +745,8 @@ def test_mes_analytics(
735745
picked_projects_idxs,
736746
expected_third_voter_budget,
737747
expected_fourth_voter_budget,
748+
multiprofile=False,
749+
expected_multiplicity=[1 for _ in range(10)],
738750
):
739751
projects = [Project(chr(ord("a") + idx), costs[idx]) for idx in range(0, 5)]
740752
instance = Instance(projects, budget_limit=5)
@@ -752,21 +764,29 @@ def test_mes_analytics(
752764
ApprovalBallot({projects[4]}),
753765
]
754766
)
767+
if multiprofile:
768+
profile = profile.as_multiprofile()
755769
result = method_of_equal_shares(instance, profile, Cost_Sat, analytics=True)
756770

757771
assert sorted(list(result), key=lambda proj: proj.name) == [
758772
projects[idx] for idx in picked_projects_idxs
759773
]
760774
assert result.details.initial_budget_per_voter == frac(1, 2)
775+
assert result.details.voter_multiplicity == expected_multiplicity
761776

777+
check_voters = [2, 2, 5] if multiprofile else [3, 4, 8]
762778
for idx, anl in enumerate(
763779
sorted(result.details.iterations, key=lambda iter: iter.project.name)
764780
):
765781
assert anl.project.name == projects[idx].name
766782
assert anl.was_picked == (idx in picked_projects_idxs)
767-
assert anl.voters_budget[3] == expected_third_voter_budget[idx]
768-
assert anl.voters_budget[4] == expected_fourth_voter_budget[idx]
769-
assert anl.voters_budget[8] == frac(1, 2)
783+
assert (
784+
anl.voters_budget[check_voters[0]] == expected_third_voter_budget[idx]
785+
)
786+
assert (
787+
anl.voters_budget[check_voters[1]] == expected_fourth_voter_budget[idx]
788+
)
789+
assert anl.voters_budget[check_voters[2]] == frac(1, 2)
770790

771791
def test_mes_analytics_irresolute(self):
772792
projects = [Project(chr(ord("a") + idx), 3) for idx in range(0, 3)]

0 commit comments

Comments
 (0)