99 lines
2.7 KiB
Java
99 lines
2.7 KiB
Java
package server;
|
|
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class PlayerTest {
|
|
|
|
@Test
|
|
@DisplayName("Dovrebbe aggiungere la quantità di cibo indicata")
|
|
void shouldAddFood() {
|
|
//Arrange
|
|
Player player = new Player("Giovanni", TotemColor.YELLOW);
|
|
|
|
//Act
|
|
player.addFood(5);
|
|
player.addFood(2);
|
|
|
|
//Assert
|
|
assertEquals(7, player.getFoodTokens(), "5 + 2 deve fare 7");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Dovrebbe sottrarre il cibo quando i fondi sono sufficienti")
|
|
void shouldSubtractFoodWhenFundsAreSufficient() {
|
|
//Arrange
|
|
Player player = new Player("Mario", TotemColor.PURPLE);
|
|
|
|
//Act
|
|
player.addFood(5);
|
|
player.removeFood(2);
|
|
|
|
//Assert
|
|
assertEquals(3, player.getFoodTokens());
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Non dovrebbe far scendere il cibo sotto zero quando i fondi sono insufficienti")
|
|
void shouldNotGoNegativeWhenFoodIsInsufficient() {
|
|
//Arrange
|
|
Player player = new Player("Luigi", TotemColor.YELLOW);
|
|
|
|
//Act
|
|
player.addFood(2);
|
|
player.removeFood(5);
|
|
|
|
//Assert
|
|
assertEquals(2, player.getFoodTokens()); //Se il cibo è insufficiente, il cibo rimane lo stesso di prima, non diminuisce!
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Dovrebbe sommare correttamente i Punti Prestigio aggiunti")
|
|
void shouldAddPrestigePoints() {
|
|
// Arrange
|
|
Player player = new Player("Yoshi", TotemColor.YELLOW);
|
|
|
|
// Act
|
|
player.addPrestigePoints(3);
|
|
player.addPrestigePoints(4);
|
|
player.addPrestigePoints(10);
|
|
|
|
// Assert
|
|
assertEquals(17, player.getPrestigePoints());
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Dovrebbe sottrarre correttamente i Punti Prestigio persi")
|
|
void shouldRemovePrestigePoints() {
|
|
//Arrange
|
|
Player player = new Player("Gianbruno", TotemColor.BLUE);
|
|
player.addPrestigePoints(10);
|
|
|
|
// Act
|
|
player.removePrestigePoints(4);
|
|
|
|
// Assert
|
|
assertEquals(6, player.getPrestigePoints());
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Dovrebbe sottrarre correttamente i Punti Prestigio persi")
|
|
void shouldRemovePrestigePoints2() {
|
|
//Arrange
|
|
Player player1 = new Player("Gino", TotemColor.BLUE);
|
|
Player player2 = new Player("Olivia", TotemColor.RED);
|
|
|
|
player1.addPrestigePoints(10);
|
|
player2.addPrestigePoints(2);
|
|
|
|
// Act
|
|
player1.removePrestigePoints(4);
|
|
player2.removePrestigePoints(7);
|
|
|
|
// Assert
|
|
assertEquals(6, player1.getPrestigePoints());
|
|
assertEquals(-5, player2.getPrestigePoints());
|
|
}
|
|
} |