Browse Source

test: cover the favoring adhesion feature

Coverage is now above 98% !
master
Dominique Merle 1 year ago
parent
commit
2947990a26
  1. 21
      src/main/java/fr/mieuxvoter/mj/MajorityJudgmentDeliberator.java
  2. 6
      src/main/java/fr/mieuxvoter/mj/ProposalTallyAnalysis.java
  3. 26
      src/test/java/fr/mieuxvoter/mj/MajorityJudgmentDeliberatorTest.java

21
src/main/java/fr/mieuxvoter/mj/MajorityJudgmentDeliberator.java

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

6
src/main/java/fr/mieuxvoter/mj/ProposalTallyAnalysis.java

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

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

@ -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
// public void runBenchmarks() throws Exception {
// Options options = new OptionsBuilder()

Loading…
Cancel
Save