-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: Add Method of Equal Shares #599
base: main
Are you sure you want to change the base?
Conversation
**Context:** This pull request adds new test cases for the `MethodOfEqualShares` class within the `packages/backend/src/Tabulators/MethodOfEqualShares.ts` file. This includes importing the `fraction.js` package and several testing scenarios such as Basic Example, Influence Budget Redistribution, Random Tiebreaker, Random Tiebreaker with Defined Order, and Valid/Invalid/Under/Bullet Vote Counts. **Key Changes:** 1. **New test file:** - Created a new test file at `packages/backend/src/Tabulators/MethodOfEqualShares.test.ts`. - Added comprehensive test cases to validate the functionality of the `MethodOfEqualShares`. 2. **Implementation of MethodOfEqualShares** - Added `packages/backend/src/Tabulators/MethodOfEqualShares.ts` to implement the MethodOfEqualShares function. - The function calculates election results based on various voting methods and scenarios. - It handles tiebreakers, influence budget redistribution, and validates different vote types. **Testing Instructions:** - Run the test suite in the `packages/backend/` directory to ensure all new and existing tests pass. **Motivation:** - To ensure the reliability and accuracy of the `MethodOfEqualShares` function. - To handle edge cases and validate the workflow of the election model.
6ce75b7
to
7f5a499
Compare
7f5a499
to
512e788
Compare
Not sure why this is failing...
|
@fsargent does this tool output any intermediate data that we can use to debug? |
Could also check the box to use fractions instead of floats and check if we're hitting any tiebreaker scenarios. |
Looks like a ties issue. In the tool you can click on the results at the bottom and get logs that includes a list of tied winner sets. Your winners were: 0, 1, 5, 6, 9, 12 Tied winner sets: |
6ecc82e
to
484ba7c
Compare
function shuffle<T>(array: T[]): T[] { | ||
const shuffled = array.slice(); | ||
for (let i = shuffled.length - 1; i > 0; i--) { | ||
const j = Math.floor(Math.random() * (i + 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need a random generator here. The "randomTiebreakOrder" input to the main function is intended to determine how "random" ties are broken. This allows tests to be determinate and the server can generate a random order based on candidate UUIDs. Sorry that this wasn't documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikefranze Yeah, makes sense. I'm having issues because the existing tool (https://pref.tools/abcvoting/) doesn't actually describe what order the candidates are elected, so it's hard for me to write tests without me just 'guessing' who should win, or trusting my possibly faulty code.
Context:
This pull request adds new test cases for the
MethodOfEqualShares
class within thepackages/backend/src/Tabulators/MethodOfEqualShares.ts
file. This includes importing thefraction.js
package and several testing scenarios such as Basic Example, Influence Budget Redistribution, Random Tiebreaker, Random Tiebreaker with Defined Order, and Valid/Invalid/Under/Bullet Vote Counts.Key Changes:
New test file:
packages/backend/src/Tabulators/MethodOfEqualShares.test.ts
.MethodOfEqualShares
.Implementation of MethodOfEqualShares
packages/backend/src/Tabulators/MethodOfEqualShares.ts
to implement the MethodOfEqualShares function.Testing Instructions:
packages/backend/
directory to ensure all new and existing tests pass.Motivation:
MethodOfEqualShares
function.