fix: whitespace hell (we need a linter!)

Also, add another test-case with thousands of participants.
pull/4/head
Dominique Merle 3 years ago
parent 2cbb7c45d8
commit 5ab34db580

@ -2,8 +2,6 @@ package fr.mieuxvoter.mj;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.stream.Stream;
import javax.json.JsonArray; import javax.json.JsonArray;
import javax.json.JsonObject; import javax.json.JsonObject;
import javax.json.JsonValue; import javax.json.JsonValue;
@ -11,9 +9,6 @@ import javax.json.JsonValue;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import net.joshka.junit.json.params.JsonFileSource; import net.joshka.junit.json.params.JsonFileSource;
//import net.joshka.junit.json.params.JsonObject; //import net.joshka.junit.json.params.JsonObject;
@ -55,25 +50,26 @@ class MajorityJudgmentDeliberatorTest {
assertEquals(1, result.getProposalResults()[1].getRank()); assertEquals(1, result.getProposalResults()[1].getRank());
} }
@DisplayName("Test majority judgment deliberation") @DisplayName("Test majority judgment deliberation")
@ParameterizedTest(name="#{index} {0}") @ParameterizedTest(name="#{index} {0}")
@JsonFileSource(resources = "/assertions.json") @JsonFileSource(resources = "/assertions.json")
public void testFromJson(JsonObject datum) { public void testFromJson(JsonObject datum) {
JsonArray jsonTallies = datum.getJsonArray("tallies"); JsonArray jsonTallies = datum.getJsonArray("tallies");
int amountOfProposals = jsonTallies.size(); int amountOfProposals = jsonTallies.size();
ProposalTallyInterface[] tallies = new ProposalTallyInterface[amountOfProposals]; Long amountOfParticipants = Long.valueOf(datum.get("participants").toString());
for (int i = 0; i < amountOfProposals; i++) { ProposalTallyInterface[] tallies = new ProposalTallyInterface[amountOfProposals];
JsonArray jsonTally = jsonTallies.getJsonArray(i); for (int i = 0; i < amountOfProposals; i++) {
int amountOfGrades = jsonTally.size(); JsonArray jsonTally = jsonTallies.getJsonArray(i);
Long[] tally = new Long[amountOfGrades]; int amountOfGrades = jsonTally.size();
for (int g = 0; g < amountOfGrades; g++) { Long[] tally = new Long[amountOfGrades];
JsonValue amountForGrade = jsonTally.get(g); for (int g = 0; g < amountOfGrades; g++) {
tally[g] = Long.valueOf(amountForGrade.toString()); JsonValue amountForGrade = jsonTally.get(g);
} tally[g] = Long.valueOf(amountForGrade.toString());
tallies[i] = new ProposalTally(tally); }
} tallies[i] = new ProposalTally(tally);
}
DeliberatorInterface mj = new MajorityJudgmentDeliberator(); DeliberatorInterface mj = new MajorityJudgmentDeliberator();
TallyInterface tally = new Tally(tallies, 3L); TallyInterface tally = new Tally(tallies, amountOfParticipants);
ResultInterface result = mj.deliberate(tally); ResultInterface result = mj.deliberate(tally);
assertNotNull(result); assertNotNull(result);
@ -85,23 +81,23 @@ class MajorityJudgmentDeliberatorTest {
"Rank of tally #"+i "Rank of tally #"+i
); );
} }
} }
// @Test // @Test
// public void runBenchmarks() throws Exception { // public void runBenchmarks() throws Exception {
// Options options = new OptionsBuilder() // Options options = new OptionsBuilder()
// .include(this.getClass().getName() + ".*") // .include(this.getClass().getName() + ".*")
// .mode(Mode.AverageTime) // .mode(Mode.AverageTime)
// .warmupTime(TimeValue.seconds(1)) // .warmupTime(TimeValue.seconds(1))
// .warmupIterations(6) // .warmupIterations(6)
// .threads(1) // .threads(1)
// .measurementIterations(6) // .measurementIterations(6)
// .forks(1) // .forks(1)
// .shouldFailOnError(true) // .shouldFailOnError(true)
// .shouldDoGC(true) // .shouldDoGC(true)
// .build(); // .build();
// //
// new Runner(options).run(); // new Runner(options).run();
// } // }
} }

@ -1,20 +1,35 @@
[ [
{ {
"title": "Few judgments", "title": "Few participants",
"participants": 3,
"tallies": [ "tallies": [
[1, 1, 1], [1, 1, 1],
[1, 0, 2], [1, 0, 2],
[3, 0, 0], [3, 0, 0],
[2, 0, 1], [2, 0, 1],
[0, 3, 0] [0, 3, 0]
], ],
"ranks": [ "ranks": [
3, 3,
1, 1,
5, 5,
4, 4,
2 2
]
},
{
"title": "Thousands of participants",
"participants": 37000,
"tallies": [
[11142, 6970, 4040, 1968, 9888, 2992],
[10141, 8971, 4043, 1965, 8884, 2996],
[14141, 8971, 1043, 1965, 7884, 2996]
],
"ranks": [
1,
2,
3
] ]
} }

Loading…
Cancel
Save