Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with Empty Ballots (And Test Correct Behaviour) #548

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

BenBals
Copy link
Contributor

@BenBals BenBals commented Apr 1, 2024

As described by @lukasrad02, the current algorithm for ranked choice elections throws an exception if there is an empty ballot (i.e., a voter who ranked no choice but still submitted their ballot). I've fixed this error and implemented a test to check the behaviour.

The Error

For reference: Here is where it previously broke

======================================================================
ERROR: test_empty_ballots (myhpi.tests.polls.test_ranked_choice_algorithm.RankedChoiceAlgorithmTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/beb/code/fsr/myHPI/myhpi/tests/polls/test_ranked_choice_algorithm.py", line 117, in test_empty_ballots
    self.poll.calculate_ranking(),
  File "/Users/beb/code/fsr/myHPI/myhpi/polls/models.py", line 237, in calculate_ranking
    current_votes[heapq.heappop(ballot)[1].option.pk].append(ballot)
IndexError: index out of range

Copy link
Contributor

@lukasrad02 lukasrad02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm this is working on the data set that caused the error previously.

@jeriox jeriox merged commit 54036d5 into fsr-de:main Apr 2, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants