Commit c30b5bf4 authored by Mamadou Saliou DIALLO's avatar Mamadou Saliou DIALLO

test: write unit test for Creature class

parent 26e9e143
package fr.univnantes.alma.model.player;
import fr.univnantes.alma.model.card.player.track.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
/**
* Creature Player test.
*/
class CreatureTest {
/**
* Player.
*/
private Creature creature;
/**
* Place cards.
*/
private List<TrackingCard> cards1;
/**
* Place cards.
*/
private List<TrackingCard> cards2;
/**
* Setup attributes.
*/
@BeforeEach
void setUp() {
creature = new Creature("player1", "saliou673");
cards1 = new ArrayList<>();
cards1.add(new AnguishCard());
cards1.add(new ForceFieldCard());
cards1.add(new DespairCard());
cards2 = new ArrayList<>();
cards2.add(new DreadCard());
cards2.add(new IntuitionCard());
cards2.add(new AnguishCard());
creature.initHand(cards1);
}
/**
* Test getHand method.
*/
@Test
void testGetHand() {
assertEquals(cards1.size(), creature.getHandSize());
assertTrue(creature.getHand().containsAll(cards1));
}
/**
* Test GetDiscard method.
*/
@Test
void testGetDiscard() {
assertEquals(creature.getDiscardSize(), creature.getDiscard().size());
creature.discard(cards1.get(0));
assertEquals(creature.getDiscardSize(), creature.getDiscard().size());
assertTrue(creature.getDiscard().contains(cards1.get(0)));
}
/**
* Test getPawn method.
*/
@Test
void testGetPawns() {
}
/**
* Test addCardToHand method.
* (1) When card is null.
* (2) When card is not null, but player hand is full.
* (3) When card is not null, but already in player hand.
* (4) When card is not null and player hand is not full.
*/
@Test
void testAddCardToHand() {
/**
* (1) When card is null.
*/
assertThrows(IllegalArgumentException.class, () -> {
creature.addCardToHand(null);
});
/**
* todo: (2) When card is not null, but player hand is full.
*/
/**
* (3) When card is not null, but already in player hand.
*/
assertThrows(IllegalArgumentException.class, () -> {
creature.addCardToHand(cards1.get(0));
});
/**
* (4) When card is not null and player hand is not full.
*/
assertTrue(creature.addCardToHand(cards2.get(0)));
}
/**
* Test removeCardFromHand method.
* (1) When card is null.
* (2) When card is not null, but not exist in player hand.
* (3) When card is not null and exist in player hand.
*/
@Test
void testRemoveCardFromHand() {
/**
* (1) When card is null.
*/
assertThrows(IllegalArgumentException.class, () -> {
creature.removeCardFromHand(null);
});
/**
* (2) When card is not null, but not exist in player hand.
*/
assertFalse(creature.removeCardFromHand(cards2.get(0)));
/**
* (3) When card is not null and exist in player hand.
*/
assertTrue(creature.removeCardFromHand(cards1.get(0)));
}
/**
* test discard method.
* (1) When card doesn't exist in player hand.
* (2) When card exist in player hand, but it's full.
* (3) When card exist in player hand, and it's not full.
*/
@Test
void testDiscard() {
/**
* (1) When card doesn't exist in player hand.
*/
assertThrows(IllegalArgumentException.class, () -> {
creature.discard(cards2.get(0));
});
/**
* todo: (2) When card exist in player hand, but it's full.
*/
/**
* (3) When card exist in player hand, and it's not full.
*/
assertEquals(0, creature.getDiscardSize());
assertEquals(cards1.size(), creature.getHandSize());
TrackingCard card = cards1.get(2);
creature.discard(card);
assertEquals(1, creature.getDiscardSize());
assertEquals(cards1.size() - 1, creature.getHandSize());
assertTrue(creature.getDiscard().contains(card));
assertFalse(creature.getHand().contains(card));
}
/**
* Test putCardBackInHand method.
* (1) When card doesn't exist in discard.
* (2) When card exist in discard, but player hand is full.
* (3) When card exist in discard and player hand is not full.
*/
@Test
void testPutCardBackInHand() {
/**
* (1) When card doesn't exist in discard.
*/
assertThrows(IllegalArgumentException.class, () -> {
creature.putCardBackInHand(cards2.get(0));
});
/**
* todo: (2) When card exist in discard, but player hand is full.
*/
/**
* (3) When card exist in discard and player hand is not full.
*/
TrackingCard card = cards1.get(2);
creature.discard(card);
assertTrue(creature.getDiscard().contains(card));
assertFalse(creature.getHand().contains(card));
creature.putCardBackInHand(card);
assertFalse(creature.getDiscard().contains(card));
assertTrue(creature.getHand().contains(card));
}
/**
* Test getHandSize mehtod.
*/
@Test
void testGetHandSize() {
assertEquals(cards1.size(), creature.getHandSize());
creature.discard(cards1.get(0));
assertEquals(cards1.size() - 1, creature.getHandSize());
}
/**
* Test getDiscardSize method.
*/
@Test
void testGetDiscardSize() {
assertEquals(0, creature.getDiscardSize());
creature.discard(cards1.get(0));
assertEquals(1, creature.getDiscardSize());
}
/**
* Test init hand method.
* (1) When card list is null.
* (2) When card list size is different to {@link Creature#INIT_HAND_SIZE}.
* (3) When card list has correct size, but player hand is full.
* (4) When card list has correct size and player hand is not full.
*/
@Test
void testInitHand() {
Creature creature1 = new Creature("player1", "produ224");
/**
* (1) When card list is null.
*/
assertThrows(IllegalArgumentException.class, () -> {
creature1.initHand(null);
});
/**
* (2) When card list size is different to {@link Player#INIT_HAND_SIZE}.
*/
int expectedSize = cards1.size() - 1;
cards1.remove(0);
assertEquals(expectedSize, cards1.size());
assertThrows(IllegalArgumentException.class, () -> {
creature1.initHand(cards1);
});
/**
* todo: (3) When card list has correct size, but player hand is full.
*/
/**
* (4) When card list has correct size and player hand is not full.
*/
creature1.initHand(cards2);
assertEquals(cards2.size(), creature1.getHandSize());
assertTrue(creature1.getHand().containsAll(cards2));
}
}
\ 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