Commit 5d9868b3 authored by Corentin Guillevic's avatar Corentin Guillevic
Browse files

Add tests for Pioche ; Small refactoring of Pioche

parent 3399bc9b
......@@ -1085,7 +1085,7 @@ public class PowerApplicator {
if(game.getTrackingCardPioche().getTrash().isEmpty()) {
return;
}
TrackingCard lastCardPlayed = game.getTrackingCardPioche().getLastTrashCards(1).get(0);
TrackingCard lastCardPlayed = game.getTrackingCardPioche().drawLastTrashCards(1).get(0);
creature.addTrackingCardToApplied(lastCardPlayed);
creature.addTrackingCard(lastCardPlayed);
creature.playTrackingCard(lastCardPlayed);
......@@ -1314,7 +1314,7 @@ public class PowerApplicator {
traque.addSurvivalCard(pioche.draw());
}
else {
traque.addSurvivalCard(pioche.getLastTrashCards(1));
traque.addSurvivalCard(pioche.drawLastTrashCards(1));
}
}
......
......@@ -88,7 +88,7 @@ public class Pioche<T extends PlayerCard>{
* @param number The number of cards
* @return A list of card
*/
public List<T> getLastTrashCards(int number) {
public List<T> drawLastTrashCards(int number) {
number = Math.min(trash.size(), number);
List<T> cards = new ArrayList<>();
for(int i = 1 ; i <= number ; ++i) {
......
package fr.univnantes.alma.server.game.item.pioche;
import fr.univnantes.alma.server.game.item.Phase;
import fr.univnantes.alma.server.game.item.card.CardName;
import fr.univnantes.alma.server.game.item.card.SurvivalCard;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class PiocheTest {
List<SurvivalCard> cards;
Random identityRandom;
@BeforeEach
void setup() {
cards = new ArrayList<>(Arrays.asList(
new SurvivalCard(CardName.ADRENALINE, "Adrénaline", "", Phase.PREPHASE_1),
new SurvivalCard(CardName.CAVALE, "Cavale", "", Phase.PREPHASE_1),
new SurvivalCard(CardName.RESISTANCE, "Résistance", "", Phase.PREPHASE_1)
));
identityRandom = mock(Random.class);
when(identityRandom.nextInt(any(Integer.class)))
.thenReturn(2)
.thenReturn(1)
.thenReturn(0);
}
@Test
void mix() {
fail();
void testMix_equals() {
Pioche<SurvivalCard> pioche = new Pioche<>(cards, identityRandom);
assertIterableEquals(cards, pioche.getCards());
}
@Test
void draw() {
fail();
void testDraw_equals() {
Pioche<SurvivalCard> pioche = new Pioche<>(cards, identityRandom);
assertEquals(cards.get(0), pioche.draw());
pioche = new Pioche<>(cards, identityRandom);
List<SurvivalCard> expect = new ArrayList<>(cards.subList(0,2));
assertIterableEquals(expect, pioche.draw(2));
}
@Test
void testDraw_noEnoughCardInPioche() {
Pioche<SurvivalCard> pioche = new Pioche<>(cards, identityRandom);
assertThrows(IllegalArgumentException.class, () -> pioche.draw(4));
}
@Test
void testThrowAway_equals() {
SurvivalCard survivalCard = new SurvivalCard(CardName.NAVETTE, "Navette", "", Phase.PREPHASE_1);
SurvivalCard survivalCard2 = new SurvivalCard(CardName.SECOND_SOUFFLE, "Second souffle", "", Phase.PREPHASE_1);
Pioche<SurvivalCard> pioche = new Pioche<>(cards, identityRandom);
pioche.throwAway(survivalCard);
assertEquals(Collections.singletonList(survivalCard), pioche.getTrash());
List<SurvivalCard> survivalCards = new ArrayList<>(Arrays.asList(survivalCard, survivalCard2));
pioche = new Pioche<>(cards, identityRandom);
pioche.throwAway(survivalCards);
assertIterableEquals(survivalCards, pioche.getTrash());
}
@Test
void testDrawLastTrashCards_equals() {
SurvivalCard survivalCard = new SurvivalCard(CardName.NAVETTE, "Navette", "", Phase.PREPHASE_1);
SurvivalCard survivalCard2 = new SurvivalCard(CardName.SECOND_SOUFFLE, "Second souffle", "", Phase.PREPHASE_1);
List<SurvivalCard> survivalCards = new ArrayList<>(Arrays.asList(survivalCard, survivalCard2));
Pioche<SurvivalCard> pioche = new Pioche<>(cards, identityRandom);
pioche.throwAway(survivalCards);
assertIterableEquals(Collections.singletonList(survivalCard2), pioche.drawLastTrashCards(1));
assertFalse(pioche.getTrash().contains(survivalCard2));
pioche = new Pioche<>(cards, identityRandom);
pioche.throwAway(survivalCards);
assertIterableEquals(Arrays.asList(survivalCard2, survivalCard), pioche.drawLastTrashCards(2));
assertFalse(pioche.getTrash().containsAll(survivalCards));
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment