Fix: Player and PlayerTest Changed
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package it.polimi.ingsw.gc14.Model;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@@ -8,18 +9,82 @@ class PlayerTest {
|
||||
|
||||
@Test
|
||||
void addFood() {
|
||||
Player p = new Player("test");
|
||||
int old_val = p.getFoodValue();
|
||||
p.addFood(0);
|
||||
int new_val = p.getFoodValue();
|
||||
assertEquals(old_val, new_val);
|
||||
p.addFood(1);
|
||||
new_val = p.getFoodValue();
|
||||
assertNotEquals(old_val, new_val);
|
||||
p.addFood(-2);
|
||||
new_val = p.getFoodValue();
|
||||
assertEquals(-1, new_val);
|
||||
p.addFood(1);
|
||||
|
||||
p.addFood(3);
|
||||
p.removeFood(3);
|
||||
assertEquals(0, p.getFoodValue());
|
||||
|
||||
p.addFood(4);
|
||||
p.removeFood(p.getFoodValue());
|
||||
assertEquals(0, p.getFoodValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeFood() {
|
||||
Player p = new Player("test");
|
||||
assertEquals(true, p.removeFood(0));
|
||||
assertEquals(false, p.removeFood(1));
|
||||
assertEquals(true, p.removeFood(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void addPrestige() {
|
||||
Player p = new Player("test");
|
||||
p.addPrestige(0);
|
||||
assertEquals(0, p.getPrestigeValue());
|
||||
p.addPrestige(1);
|
||||
assertEquals(1, p.getPrestigeValue());
|
||||
p.addPrestige(-3);
|
||||
assertEquals(-2, p.getPrestigeValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void removePrestige() {
|
||||
Player p = new Player("test");
|
||||
p.removePrestige(0);
|
||||
assertEquals(0, p.getPrestigeValue());
|
||||
p.removePrestige(1);
|
||||
assertEquals(-1, p.getPrestigeValue());
|
||||
p.removePrestige(-3);
|
||||
assertEquals(2, p.getPrestigeValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void setUserName() {
|
||||
String UserName = "abcdabcdabcdabcdabcdabcdabcdabcd";
|
||||
Player p = new Player(UserName);
|
||||
assertEquals(32, p.getUserName().length());
|
||||
p = new Player("abcdabcdabcda");
|
||||
assertEquals(true, p.getUserName().length() <= 32);
|
||||
assertEquals(true, p.getUserName().length() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception Test Max Length")
|
||||
void test_max() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
Player p = new Player("abcdabcdabcdabcdabcdabcdabcdabcdZ");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Exception Test Min Length")
|
||||
void test_min() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
Player p = new Player("");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user