test: cover the favoring adhesion feature

Coverage is now above 98% !
pull/14/head^2
Dominique Merle 3 years ago
parent d193ed0eca
commit 2947990a26

@ -18,9 +18,25 @@ import java.util.Comparator;
* *
* https://en.wikipedia.org/wiki/Majority_judgment * https://en.wikipedia.org/wiki/Majority_judgment
* https://fr.wikipedia.org/wiki/Jugement_majoritaire * https://fr.wikipedia.org/wiki/Jugement_majoritaire
*
* Should this class be `final`?
*/ */
final public class MajorityJudgmentDeliberator implements DeliberatorInterface { final public class MajorityJudgmentDeliberator implements DeliberatorInterface {
protected boolean favorContestation = true;
protected boolean numerizeScore = false;
public MajorityJudgmentDeliberator() {}
public MajorityJudgmentDeliberator(boolean favorContestation) {
this.favorContestation = favorContestation;
}
public MajorityJudgmentDeliberator(boolean favorContestation, boolean numerizeScore) {
this.favorContestation = favorContestation;
this.numerizeScore = numerizeScore;
}
@Override @Override
public ResultInterface deliberate(TallyInterface tally) { public ResultInterface deliberate(TallyInterface tally) {
ProposalTallyInterface[] tallies = tally.getProposalsTallies(); ProposalTallyInterface[] tallies = tally.getProposalsTallies();
@ -34,8 +50,7 @@ final public class MajorityJudgmentDeliberator implements DeliberatorInterface {
for (int proposalIndex = 0; proposalIndex < amountOfProposals; proposalIndex++) { for (int proposalIndex = 0; proposalIndex < amountOfProposals; proposalIndex++) {
ProposalTallyInterface proposalTally = tallies[proposalIndex]; ProposalTallyInterface proposalTally = tallies[proposalIndex];
String score = computeScore(proposalTally, amountOfJudges); String score = computeScore(proposalTally, amountOfJudges);
ProposalTallyAnalysis analysis = new ProposalTallyAnalysis(); ProposalTallyAnalysis analysis = new ProposalTallyAnalysis(proposalTally, this.favorContestation);
analysis.reanalyze(proposalTally);
ProposalResult proposalResult = new ProposalResult(); ProposalResult proposalResult = new ProposalResult();
proposalResult.setScore(score); proposalResult.setScore(score);
proposalResult.setAnalysis(analysis); proposalResult.setAnalysis(analysis);
@ -73,7 +88,7 @@ final public class MajorityJudgmentDeliberator implements DeliberatorInterface {
} }
protected String computeScore(ProposalTallyInterface tally, BigInteger amountOfJudges) { protected String computeScore(ProposalTallyInterface tally, BigInteger amountOfJudges) {
return computeScore(tally, amountOfJudges, true, false); return computeScore(tally, amountOfJudges, this.favorContestation, this.numerizeScore);
} }
/** /**

@ -43,10 +43,14 @@ public class ProposalTallyAnalysis {
reanalyze(tally); reanalyze(tally);
} }
public ProposalTallyAnalysis(ProposalTallyInterface tally, Boolean favorContestation) {
reanalyze(tally, favorContestation);
}
public void reanalyze(ProposalTallyInterface tally) { public void reanalyze(ProposalTallyInterface tally) {
reanalyze(tally, true); reanalyze(tally, true);
} }
public void reanalyze(ProposalTallyInterface tally, Boolean favorContestation) { public void reanalyze(ProposalTallyInterface tally, Boolean favorContestation) {
this.tally = tally; this.tally = tally;
this.totalSize = BigInteger.ZERO; this.totalSize = BigInteger.ZERO;

@ -341,8 +341,34 @@ class MajorityJudgmentDeliberatorTest {
} }
} }
@Test
@DisplayName("Test favoring adhesion")
public void testFavoringAdhesion() {
boolean favorContestation = false;
Integer amountOfJudges = 4;
DeliberatorInterface mj = new MajorityJudgmentDeliberator(favorContestation);
TallyInterface tally = new Tally(new ProposalTallyInterface[] {
new ProposalTally(new Integer[]{ 2, 0, 2 }),
new ProposalTally(new Integer[]{ 0, 2, 2 }),
new ProposalTally(new Integer[]{ 2, 1, 1 }),
}, amountOfJudges);
ResultInterface result = mj.deliberate(tally);
assertNotNull(result);
assertEquals(3, result.getProposalResults().length);
assertEquals(2, result.getProposalResults()[0].getRank());
assertEquals(1, result.getProposalResults()[1].getRank());
assertEquals(3, result.getProposalResults()[2].getRank());
assertEquals(2, result.getProposalResults()[0].getAnalysis().getMedianGrade());
assertEquals(2, result.getProposalResults()[1].getAnalysis().getMedianGrade());
assertEquals(1, result.getProposalResults()[2].getAnalysis().getMedianGrade());
}
// … // …
// @Test // @Test
// public void runBenchmarks() throws Exception { // public void runBenchmarks() throws Exception {
// Options options = new OptionsBuilder() // Options options = new OptionsBuilder()

Loading…
Cancel
Save