Equal-Vote / starpy

Python implementation of the STAR Voting system
https://www.starvoting.org/
BSD 3-Clause "New" or "Revised" License
8 stars 4 forks source link

Ties aren't working: too many values to unpack #16

Closed endolith closed 2 years ago

endolith commented 2 years ago

Trying to add the test cases from star-core but they're all failing:

        columns = ['Allison', 'Bill', 'Carmen', 'Doug']
        election = [[5, 4, 3, 3],
                    [4, 5, 1, 1],
                    [4, 5, 1, 2],
                    [3, 5, 1, 0],
                    [5, 4, 3, 0],
                    [5, 0, 4, 1],
                    [5, 0, 4, 0],
                    [4, 0, 5, 1],
                    [3, 4, 5, 0],
                    [3, 5, 5, 4]]
        ballots = pd.DataFrame(columns=columns, data=election)
        results = STAR(ballots)

        # expected = [["Allison"], ["Bill", "Carmen"], ["Doug"]];

        columns = ['Allison', 'Bill', 'Carmen', 'Doug']
        election = [[5, 4, 1, 4],
                    [5, 4, 1, 4],
                    [2, 4, 1, 2],
                    [4, 3, 2, 1],
                    [0, 5, 4, 4],
                    [3, 2, 4, 2],
                    [3, 1, 5, 3],
                    [3, 1, 5, 3],
                    [1, 3, 2, 2],
                    [4, 3, 5, 5]]
        ballots = pd.DataFrame(columns=columns, data=election)
        results = STAR(ballots)

        # expected = [["Allison", "Bill", "Carmen"], [], ["Doug"]];

        columns = ['Allison', 'Bill', 'Carmen', 'Doug']
        election = [[5, 4, 1, 4],
                    [5, 4, 1, 4],
                    [2, 4, 1, 2],
                    [4, 3, 2, 1],
                    [0, 5, 4, 4],
                    [3, 2, 4, 2],
                    [3, 1, 5, 3],
                    [3, 1, 5, 3],
                    [1, 3, 2, 2],
                    [4, 3, 5, 5]]
        ballots = pd.DataFrame(columns=columns, data=election)
        results = STAR(ballots)

        # expectedWinners = ["Allison", "Carmen", "Bill"];

These all fail with

\STAR.py", line 146, in Run_STAR_Round
    a,b = runoff_candidates

ValueError: too many values to unpack (expected 2)
endolith commented 2 years ago

Also is results['round_results'] meant to be a list with a single element? Or a dict? There will only ever be 2 rounds, right?

results['round_results'][0]['runner_up'] is the intended usage? Or results['round_results']['runner_up']?

mikefranze commented 2 years ago

It has 1 element per round. So if you have a 3 winner election you'll have 3 elements. Each round will tell you info about who won the round, who was runner up, and if there were ties.

mikefranze commented 2 years ago

Maybe runoff_candidates is getting more than 2 candidates?

mikefranze commented 2 years ago

Also, since we did change the tie breaker protocol from what star_core uses some of those tests might not pass. The star_core code and tests will need to be updated.