Browse Source

test: add a test-case with 70 millions of participants

pull/4/head
Dominique Merle 1 year ago
parent
commit
845ed67a21
  1. 7
      src/test/java/fr/mieuxvoter/mj/MajorityJudgmentDeliberatorTest.java
  2. 16
      src/test/resources/README.md
  3. 18
      src/test/resources/assertions.json

7
src/test/java/fr/mieuxvoter/mj/MajorityJudgmentDeliberatorTest.java

@ -10,7 +10,6 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import net.joshka.junit.json.params.JsonFileSource;
//import net.joshka.junit.json.params.JsonObject;
class MajorityJudgmentDeliberatorTest {
@ -29,7 +28,7 @@ class MajorityJudgmentDeliberatorTest {
assertEquals(2, result.getProposalResults()[0].getRank());
assertEquals(1, result.getProposalResults()[1].getRank());
}
@Test
public void testUsageWithBigNumbers() {
DeliberatorInterface mj = new MajorityJudgmentDeliberator();
@ -49,7 +48,7 @@ class MajorityJudgmentDeliberatorTest {
assertEquals(2, result.getProposalResults()[0].getRank());
assertEquals(1, result.getProposalResults()[1].getRank());
}
@DisplayName("Test majority judgment deliberation")
@ParameterizedTest(name="#{index} {0}")
@JsonFileSource(resources = "/assertions.json")
@ -82,7 +81,7 @@ class MajorityJudgmentDeliberatorTest {
);
}
}
// @Test
// public void runBenchmarks() throws Exception {
// Options options = new OptionsBuilder()

16
src/test/resources/README.md

@ -0,0 +1,16 @@
Do add your test cases in the JSON file.
Some of the sample tallies were made using python.
```python
import numpy as np
def randofsum_unbalanced(s, n):
# Where s = sum (e.g. 40 in your case) and n is the output array length (e.g. 4 in your case)
r = np.random.rand(n)
a = np.array(np.round((r/np.sum(r))*s,0),dtype=int)
while np.sum(a) > s:
a[np.random.choice(n)] -= 1
while np.sum(a) < s:
a[np.random.choice(n)] += 1
return a
```

18
src/test/resources/assertions.json

@ -31,6 +31,24 @@
2,
3
]
},
{
"title": "Millions of participants",
"participants": 72327456,
"tallies": [
[5272679, 19797001, 10732688, 9612936, 1379840, 16886281, 8646031],
[16354546, 11690342, 9451800, 14245973, 817593, 12461162, 7306040],
[9849171, 17970690, 14276861, 4606692, 16404594, 6760147, 2459301],
[2645563, 12907474, 1278331, 22843261, 8025412, 8964952, 15662463],
[16293252, 12277630, 38348, 14929905, 11087753, 10634266, 7066302]
],
"ranks": [
3,
4,
5,
1,
2
]
}
]
Loading…
Cancel
Save