Fix: Player and PlayerTest Changed
This commit is contained in:
@@ -91,18 +91,13 @@ public class Player {
|
|||||||
|
|
||||||
this.PrestigeValue -= Value;
|
this.PrestigeValue -= Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserName(String UserName) throws IllegalArgumentException{
|
|
||||||
final int MAXLEN = 32;
|
|
||||||
if(UserName.isEmpty() || UserName.length() > MAXLEN){
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
this.UserName = UserName;
|
|
||||||
}
|
|
||||||
// End setters
|
// End setters
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
public Player(String UserName){
|
public Player(String UserName) throws IllegalArgumentException {
|
||||||
|
if(UserName.isEmpty() || UserName.length() > 32) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
this.UserName = UserName;
|
this.UserName = UserName;
|
||||||
|
|
||||||
this.inventors = new ArrayList <>();
|
this.inventors = new ArrayList <>();
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Model;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
class PlayerAddFoodTest {
|
|
||||||
|
|
||||||
@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); // chiedere prof (dovrebbe essere +3 expected)
|
|
||||||
p.addFood(1);
|
|
||||||
|
|
||||||
p.addFood(3);
|
|
||||||
p.removeFood(3);
|
|
||||||
assertEquals(0, p.getFoodValue());
|
|
||||||
|
|
||||||
p.addFood(4);
|
|
||||||
p.removeFood(p.getFoodValue());
|
|
||||||
assertEquals(0, p.getFoodValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Model;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class PlayerAddPrestigeTest {
|
|
||||||
|
|
||||||
@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()); // chiedere prof; dovrebbe essere +4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Model;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class PlayerRemFoodTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void removeFood() {
|
|
||||||
Player p = new Player("test");
|
|
||||||
assertEquals(true, p.removeFood(0));
|
|
||||||
assertEquals(false, p.removeFood(1));
|
|
||||||
assertEquals(true, p.removeFood(-1)); // chiedere prof
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Model;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class PlayerRemPrestigeTest {
|
|
||||||
|
|
||||||
@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()); // chiedere prof; dovrebbe essere -4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Model;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import it.polimi.ingsw.gc14.Model.Player;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
class PlayerSetUserTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void setUserName() {
|
|
||||||
String UserName = "abcdabcdabcdabcdabcdabcdabcdabcd";
|
|
||||||
Player p = new Player(UserName);
|
|
||||||
assertEquals(32, p.getUserName().length());
|
|
||||||
p.setUserName("abcdabcdabcda");
|
|
||||||
assertEquals(true, p.getUserName().length() <= 32);
|
|
||||||
assertEquals(true, p.getUserName().length() > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Exception Test Max Length")
|
|
||||||
void test_max() {
|
|
||||||
Player p = new Player("abcdabcdabcdabcdabcdabcdabcdabcd");
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> {
|
|
||||||
p.setUserName("abcdabcdabcdabcdabcdabcdabcdabcdZ");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Exception Test Min Length")
|
|
||||||
void test_min() {
|
|
||||||
Player p = new Player("abcdabcdabcdabcdabcdabcdabcdabcd");
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> {
|
|
||||||
p.setUserName("");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package it.polimi.ingsw.gc14.Model;
|
package it.polimi.ingsw.gc14.Model;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@@ -8,18 +9,82 @@ class PlayerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addFood() {
|
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
|
@Test
|
||||||
void removeFood() {
|
void removeFood() {
|
||||||
|
Player p = new Player("test");
|
||||||
|
assertEquals(true, p.removeFood(0));
|
||||||
|
assertEquals(false, p.removeFood(1));
|
||||||
|
assertEquals(true, p.removeFood(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addPrestige() {
|
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
|
@Test
|
||||||
void removePrestige() {
|
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