From 845ed67a21cb69d12bb168bc9630818f1f5bcb96 Mon Sep 17 00:00:00 2001 From: domi41 Date: Wed, 5 May 2021 13:36:48 +0200 Subject: [PATCH] test: add a test-case with 70 millions of participants --- .../mj/MajorityJudgmentDeliberatorTest.java | 7 +++---- src/test/resources/README.md | 16 ++++++++++++++++ src/test/resources/assertions.json | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/README.md diff --git a/src/test/java/fr/mieuxvoter/mj/MajorityJudgmentDeliberatorTest.java b/src/test/java/fr/mieuxvoter/mj/MajorityJudgmentDeliberatorTest.java index 6a10478..cac001f 100644 --- a/src/test/java/fr/mieuxvoter/mj/MajorityJudgmentDeliberatorTest.java +++ b/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() diff --git a/src/test/resources/README.md b/src/test/resources/README.md new file mode 100644 index 0000000..ab956aa --- /dev/null +++ b/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 +``` diff --git a/src/test/resources/assertions.json b/src/test/resources/assertions.json index 4284d00..0b1ff15 100644 --- a/src/test/resources/assertions.json +++ b/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 + ] } ]