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

Adding Typescript version of STAR-PR with tests #268

Merged
merged 4 commits into from
Jun 1, 2023

Conversation

mikefranze
Copy link
Collaborator

Updating STAR-PR (Allocated Score) to typescript with a few basic tests.

Currently the random tiebreaker works, but there are some cases where numerical errors can prevent ties from being found (Equal-Vote/starpy#23). This isn't a huge deal at the moment since the ties will be broken randomly and the numerical errors are probably random, but it'll be best to be able to at least identify ties.

I suspect it is related to or exacerbated by the scores normalization, so removing that will be the first step.

@mikefranze mikefranze requested a review from ArendPeter May 26, 2023 18:38
Copy link
Member

@ArendPeter ArendPeter left a comment

Choose a reason for hiding this comment

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

Looks good overall

I just did a quick scan over the implementation, but if the tests pass then I trust it

expect(results.summaryData.weightedScoresByRound[1]).toStrictEqual([0, 0, 16, 23]);
})
test("Fractional surplus", () => {
// Two winners, two main parties, Allison wins first round with highest score, Allison has 8 highest level supporters, more than the quota of 6 voters
Copy link
Member

Choose a reason for hiding this comment

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

What if Allison's highest level supporters has 4 5s and 4 4s? Does the fractional surplus work any differently? If so, can we add another test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question, it is handled slightly different. Added extra test case.

}
}
// converts list of strings to string with correct grammar ([a,b,c] => 'a, b, and c')
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
Copy link
Member

Choose a reason for hiding this comment

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

Is this variable used? The logic seems like a front end problem, so I was surprised to see it here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was accidently copied over from the STAR tabulator which uses it to write human readable logs. It could possibly be used in all the tabulators but removed it for now.

Copy link
Member

@ArendPeter ArendPeter left a comment

Choose a reason for hiding this comment

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

Thanks for adding the test, approved!

@mikefranze mikefranze merged commit 1cf7987 into Equal-Vote:main Jun 1, 2023
@mikefranze mikefranze deleted the STAR-PR-Refactor branch December 9, 2023 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants