-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquadratic-voting.spec.ts
40 lines (34 loc) · 1.17 KB
/
quadratic-voting.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import assert from 'assert';
import { quadraticVoting } from './quadratic-voting';
import { describe, test } from 'node:test';
describe('quadraticVoting', () => {
test('calculates quadratic votes for each agent and sum of quadratic votes', () => {
const votes: Record<string, number> = {
user1: 4,
user2: 9,
user3: 16,
};
// Expected result
const expectedQuadraticVotesDict: Record<string, number> = {
user1: 2, // sqrt(4) = 2
user2: 3, // sqrt(9) = 3
user3: 4, // sqrt(16) = 4
};
const expectedSumQuadraticVotes = 2 + 3 + 4;
const [resultQuadraticVotesDict, resultSumQuadraticVotes] = quadraticVoting(votes);
// Verify that the result is as expected
assert.deepStrictEqual(resultQuadraticVotesDict, expectedQuadraticVotesDict);
assert.strictEqual(resultSumQuadraticVotes, expectedSumQuadraticVotes);
});
test('', () => {
// Example usage:
const votes: Record<string, number> = {
user1: 4,
user2: 9,
user3: 16,
};
const [result, sum] = quadraticVoting(votes);
assert.deepStrictEqual(result, { user1: 2, user2: 3, user3: 4 });
assert.strictEqual(sum, 9);
});
});