forked from edemo/PDEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing test cases to rank candidate edemo#257
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/test/java/org/rulez/demokracia/pdengine/votecalculator/VoteResultComposerIgnoreTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.rulez.demokracia.pdengine.votecalculator; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
import static org.rulez.demokracia.pdengine.testhelpers.BeatTableTestHelper.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.rulez.demokracia.pdengine.annotations.TestedBehaviour; | ||
import org.rulez.demokracia.pdengine.annotations.TestedFeature; | ||
import org.rulez.demokracia.pdengine.annotations.TestedOperation; | ||
import org.rulez.demokracia.pdengine.beattable.BeatTable; | ||
|
||
@TestedFeature("Schulze method") | ||
@TestedOperation("rank candidates") | ||
@TestedBehaviour("calculates winners until all choices are ignored") | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class VoteResultComposerIgnoreTest { | ||
|
||
@InjectMocks | ||
private VoteResultComposerImpl voteResultComposer; | ||
@Mock | ||
private WinnerCalculatorService winnerCalculatorService; | ||
|
||
@Test | ||
public void | ||
winner_calculation_ends_in_one_step_when_all_choices_ignored_at_once() { | ||
when(winnerCalculatorService.calculateWinners(any(), any())) | ||
.thenReturn(List.of(CHOICE1, CHOICE2, CHOICE3)); | ||
|
||
voteResultComposer | ||
.composeResult(createNewBeatTableWithComplexData()); | ||
|
||
verify(winnerCalculatorService, times(1)).calculateWinners(any(), any()); | ||
} | ||
|
||
@Test | ||
public void | ||
winner_calculation_ends_in_n_steps_when_choices_ignored_one_by_one() { | ||
when(winnerCalculatorService.calculateWinners(any(), any())) | ||
.thenReturn(List.of(CHOICE1)) | ||
.thenReturn(List.of(CHOICE2)) | ||
.thenReturn(List.of(CHOICE3)); | ||
|
||
voteResultComposer | ||
.composeResult(createNewBeatTableWithComplexData()); | ||
|
||
verify(winnerCalculatorService, times(3)).calculateWinners(any(), any()); | ||
} | ||
|
||
@Test | ||
public void winner_calculation_ends_in_zero_step_when_beat_table_is_empty() { | ||
voteResultComposer | ||
.composeResult(new BeatTable()); | ||
|
||
verify(winnerCalculatorService, never()).calculateWinners(any(), any()); | ||
} | ||
} |