-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #670 from mikefranze/multiwinner_updates
Adding block STV and IRV
- Loading branch information
Showing
8 changed files
with
264 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { STV } from './IRV' | ||
|
||
describe("STV Tests", () => { | ||
test("Two winner test", () => { | ||
// Simple two winner STV test. | ||
// Shows fractional surplus and candidate elimination works | ||
|
||
const candidates = ['Alice', 'Bob', 'Carol', 'Dave'] | ||
|
||
const votes = [ | ||
[1, 2, 3, 4], | ||
[1, 2, 3, 4], | ||
[1, 2, 3, 4], | ||
[1, 2, 3, 4], | ||
[1, 2, 3, 4], | ||
[2, 1, 3, 4], | ||
[2, 1, 3, 4], | ||
[2, 3, 1, 4], | ||
[2, 3, 4, 1], | ||
] | ||
const results = STV(candidates, votes,2) | ||
expect(results.elected.length).toBe(2); | ||
expect(results.elected[0].name).toBe('Alice'); | ||
expect(results.elected[1].name).toBe('Bob'); | ||
expect(results.voteCounts.length).toBe(3); | ||
expect(results.voteCounts[0]).toStrictEqual([5,2,1,1]); | ||
expect(results.voteCounts[1]).toStrictEqual([0,3,1,1]); // first 5 voters weight reduced to 1/5 and transfered to Bob | ||
expect(results.voteCounts[2]).toStrictEqual([0,4,1,0]); // Dave eliminated and transfered to Bob | ||
|
||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.