Add: PlayerTest.java Added "getUserName", "getTotCharacters", "getNType", "getFoodValue", "getPrestigeValue" Classes
Fix: "setUserName" In PlayerTest.java Now Correctly Handles Constructor Default Values Testing
This commit is contained in:
@@ -1,12 +1,101 @@
|
||||
package it.polimi.ingsw.gc14.Model;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class PlayerTest {
|
||||
|
||||
@Test
|
||||
void getUserName(){
|
||||
String usr = "test";
|
||||
Player p = new Player(usr);
|
||||
assertEquals(usr, p.getUserName());
|
||||
assertTrue(p.getUserName().length() <= 32);
|
||||
assertTrue(p.getUserName().length() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTotCharacters(){
|
||||
String usr = "test";
|
||||
Player p = new Player(usr);
|
||||
assertEquals(0, p.getTotCharacters());
|
||||
int N = 10;
|
||||
ArrayList<Artist> a = Stream.generate(() -> new Artist(1, 1)).limit(N).collect(Collectors.toCollection(ArrayList::new));
|
||||
p.artists.addAll(a);
|
||||
assertEquals(N, p.getTotCharacters());
|
||||
ArrayList<Builder> b = Stream.generate(() -> new Builder(1, 1, 1)).limit(N).collect(Collectors.toCollection(ArrayList::new));
|
||||
p.builders.addAll(b);
|
||||
assertEquals(2 * N, p.getTotCharacters());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getNType(){
|
||||
String usr = "test";
|
||||
Player p = new Player(usr);
|
||||
for(CharacterType type : CharacterType.values()){
|
||||
assertEquals(0, p.getNType(type));
|
||||
}
|
||||
int N = 10;
|
||||
ArrayList<Artist> a = Stream.generate(() -> new Artist(1, 1)).limit(N).collect(Collectors.toCollection(ArrayList::new));
|
||||
p.artists.addAll(a);
|
||||
|
||||
ArrayList<Builder> b = Stream.generate(() -> new Builder(1, 1, 1)).limit(N).collect(Collectors.toCollection(ArrayList::new));
|
||||
p.builders.addAll(b);
|
||||
|
||||
ArrayList<Inventor> i = Stream.generate(() -> new Inventor(1, 1, 1)).limit(N).collect(Collectors.toCollection(ArrayList::new));
|
||||
p.inventors.addAll(i);
|
||||
|
||||
ArrayList<Gatherer> g = Stream.generate(() -> new Gatherer(1, 1)).limit(N).collect(Collectors.toCollection(ArrayList::new));
|
||||
p.gatherers.addAll(g);
|
||||
|
||||
ArrayList<Shaman> s = Stream.generate(() -> new Shaman(1, 1)).limit(N).collect(Collectors.toCollection(ArrayList::new));
|
||||
p.shamans.addAll(s);
|
||||
|
||||
ArrayList<Hunter> h = Stream.generate(() -> new Hunter(1, true, 1)).limit(N).collect(Collectors.toCollection(ArrayList::new));
|
||||
p.hunters.addAll(h);
|
||||
|
||||
assertEquals(N, p.getNType(CharacterType.ARTIST));
|
||||
assertEquals(N, p.getNType(CharacterType.BUILDER));
|
||||
assertEquals(N, p.getNType(CharacterType.INVENTOR));
|
||||
assertEquals(N, p.getNType(CharacterType.GATHERER));
|
||||
assertEquals(N, p.getNType(CharacterType.SHAMAN));
|
||||
assertEquals(N, p.getNType(CharacterType.HUNTER));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFoodValue(){
|
||||
int food = 5;
|
||||
Player p = new Player("test");
|
||||
assertEquals(0, p.getFoodValue());
|
||||
p.addFood(food);
|
||||
assertEquals(food, p.getFoodValue());
|
||||
p.removeFood(10 * food);
|
||||
assertEquals(food, p.getFoodValue());
|
||||
p.removeFood(food);
|
||||
assertEquals(0, p.getFoodValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPrestigeValue(){
|
||||
int prestige = 5;
|
||||
Player p = new Player("test");
|
||||
assertEquals(0, p.getPrestigeValue());
|
||||
p.addPrestige(prestige);
|
||||
assertEquals(prestige, p.getPrestigeValue());
|
||||
p.removePrestige(prestige);
|
||||
assertEquals(0, p.getPrestigeValue());
|
||||
p.removePrestige(prestige);
|
||||
assertEquals(-prestige, p.getPrestigeValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addFood() {
|
||||
Player p = new Player("test");
|
||||
@@ -66,10 +155,26 @@ class PlayerTest {
|
||||
void setUserName() {
|
||||
String UserName = "abcdabcdabcdabcdabcdabcdabcdabcd";
|
||||
Player p = new Player(UserName);
|
||||
assertEquals(0, p.getFoodValue());
|
||||
assertEquals(0, p.getPrestigeValue());
|
||||
assertEquals(32, p.getUserName().length());
|
||||
p = new Player("abcdabcdabcda");
|
||||
assertEquals(true, p.getUserName().length() <= 32);
|
||||
assertEquals(true, p.getUserName().length() > 0);
|
||||
String username = "abcdabcdabcda";
|
||||
p = new Player(username);
|
||||
|
||||
//Constructor default values testing
|
||||
assertEquals(username, p.getUserName());
|
||||
assertEquals(0, p.getFoodValue());
|
||||
assertEquals(0, p.getPrestigeValue());
|
||||
assertTrue(p.inventors.isEmpty());
|
||||
assertTrue(p.builders.isEmpty());
|
||||
assertTrue(p.gatherers.isEmpty());
|
||||
assertTrue(p.shamans.isEmpty());
|
||||
assertTrue(p.hunters.isEmpty());
|
||||
assertTrue(p.artists.isEmpty());
|
||||
assertTrue(p.buildingCards.isEmpty());
|
||||
|
||||
assertTrue(p.getUserName().length() <= 32);
|
||||
assertTrue(p.getUserName().length() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user