Commit 05bffb97 authored by Mamadou Saliou DIALLO's avatar Mamadou Saliou DIALLO
Browse files

test: write unit test for Tracked class

parent 6540d223
package fr.univnantes.alma.model.player;
import fr.univnantes.alma.model.card.place.*;
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.*;
/**
* Tracked player test.
*/
class TrackedTest {
/**
* Player.
*/
private Tracked tracked;
/**
* Place cards.
*/
private List<PlaceCard> cards1;
/**
* Place cards.
*/
private List<PlaceCard> cards2;
/**
* Setup attributes.
*/
@BeforeEach
void setUp() {
tracked = new Tracked("player1", "saliou673");
cards1 = new ArrayList<>();
cards1.add(new RoverCard());
cards1.add(new RiverCard());
cards1.add(new BeachCard());
cards1.add(new SourceCard());
cards1.add(new WreckCard());
cards2 = new ArrayList<>();
cards2.add(new BlueArtefactCard());
cards2.add(new JungleCard());
cards2.add(new LairCard());
cards2.add(new ShelterCard());
cards2.add(new SwampCard());
tracked.initHand(cards1);
}
/**
* Test getHand method.
*/
@Test
void testGetHand() {
assertEquals(cards1.size(), tracked.getHandSize());
assertTrue(tracked.getHand().containsAll(cards1));
}
/**
* Test GetDiscard method.
*/
@Test
void testGetDiscard() {
assertEquals(tracked.getDiscardSize(), tracked.getDiscard().size());
tracked.discard(cards1.get(0));
assertEquals(tracked.getDiscardSize(), tracked.getDiscard().size());
assertTrue(tracked.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, () -> {
tracked.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, () -> {
tracked.addCardToHand(cards1.get(0));
});
/**
* (4) When card is not null and player hand is not full.
*/
assertTrue(tracked.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, () -> {
tracked.removeCardFromHand(null);
});
/**
* (2) When card is not null, but not exist in player hand.
*/
assertFalse(tracked.removeCardFromHand(cards2.get(0)));
/**
* (3) When card is not null and exist in player hand.
*/
assertTrue(tracked.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, () -> {
tracked.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, tracked.getDiscardSize());
assertEquals(cards1.size(), tracked.getHandSize());
PlaceCard card = cards1.get(2);
tracked.discard(card);
assertEquals(1, tracked.getDiscardSize());
assertEquals(cards1.size() - 1, tracked.getHandSize());
assertTrue(tracked.getDiscard().contains(card));
assertFalse(tracked.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, () -> {
tracked.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.
*/
PlaceCard card = cards1.get(2);
tracked.discard(card);
assertTrue(tracked.getDiscard().contains(card));
assertFalse(tracked.getHand().contains(card));
tracked.putCardBackInHand(card);
assertFalse(tracked.getDiscard().contains(card));
assertTrue(tracked.getHand().contains(card));
}
/**
* Test getHandSize mehtod.
*/
@Test
void testGetHandSize() {
assertEquals(cards1.size(), tracked.getHandSize());
tracked.discard(cards1.get(0));
assertEquals(cards1.size() - 1, tracked.getHandSize());
}
/**
* Test getDiscardSize method.
*/
@Test
void testGetDiscardSize() {
assertEquals(0, tracked.getDiscardSize());
tracked.discard(cards1.get(0));
assertEquals(1, tracked.getDiscardSize());
}
}
\ 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