Merge pull request #41 from rubenpirreram/tests-fix

tests-fix
This commit is contained in:
rubenpirreram
2026-04-23 17:06:13 +02:00
committed by GitHub
19 changed files with 292 additions and 20 deletions
@@ -62,7 +62,7 @@ public abstract class EventCard extends TribeCard {
*/
@Override
public String toString() {
return super.toString()+" "+type.toString();
return super.toString()+", "+type.toString();
}
/**
@@ -70,4 +70,5 @@ public class Hunt extends EventCard {
public EventCard clone() {
return new Hunt(getEra(), prestigeMultiplier);
}
}
@@ -63,6 +63,11 @@ public class Board implements Serializable {
return this.tribeDeck.size();
}
/**
* @return the game era
*/
public int getEra() {return this.era;}
/**
* Creates and initializes a new board:
@@ -234,7 +239,7 @@ public class Board implements Serializable {
upperListBuilding.addAll( buildingCards.subList(0,3));
}
}
else if(era==3)
else // Era 3
{
if(nTotem==2)
{
@@ -13,7 +13,7 @@ public class Order2 extends OrderLogicCard {
* @param players the list of players associated with this order card.
* @throws NoSuchElementException if the number of players is not equal to 2.
*/
public Order2(ArrayList<Player> players)throws NoSuchElementException {
public Order2(ArrayList<Player> players) throws NoSuchElementException {
if(players.size()!=2)
throw new NoSuchElementException();
super(players);
@@ -1,6 +1,8 @@
package it.polimi.ingsw.gc14.Model.Cards.Building.Effects;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@@ -16,4 +18,52 @@ class Building1Test {
assertEquals(ct, b0.getIcon());
}
@Test
@DisplayName("Apply Effect")
void applyEffect(){
String user = "test";
Player p = new Player(user);
assertTrue(p.buildingCards.isEmpty());
assertTrue(p.inventors.isEmpty());
assertTrue(p.builders.isEmpty());
assertTrue(p.gatherers.isEmpty());
assertTrue(p.shamans.isEmpty());
assertTrue(p.hunters.isEmpty());
assertTrue(p.artists.isEmpty());
assertEquals(0, p.getFoodValue());
assertEquals(0, p.getPrestigeValue());
assertEquals(user, p.getUserName());
Building1 b0 = new Building1(1,2,3, CharacterType.INVENTOR);
b0.applyEffect(p);
assertTrue(p.buildingCards.isEmpty());
assertTrue(p.inventors.isEmpty());
assertTrue(p.builders.isEmpty());
assertTrue(p.gatherers.isEmpty());
assertTrue(p.shamans.isEmpty());
assertTrue(p.hunters.isEmpty());
assertTrue(p.artists.isEmpty());
assertEquals(0, p.getFoodValue());
assertEquals(0, p.getPrestigeValue());
assertEquals(user, p.getUserName());
}
@Test
@DisplayName("Clone")
void Clone(){
int Era = 1;
int Price = 2;
int Prestige = 3;
CharacterType ct = CharacterType.INVENTOR;
Building1 b0 = new Building1(Era,Price,Prestige, ct);
BuildingCard bClone = b0.clone();
assertEquals(Era,b0.getEra());
assertEquals(Price,b0.getPrice());
assertEquals(Prestige, bClone.getPrestigeValue());
assertEquals(ct, b0.getIcon());
}
}
@@ -65,4 +65,15 @@ class Building8Test {
assertEquals(2 + 4, p.getPrestigeValue());
}
@Test
@DisplayName("Exception Test")
void ExceptionTest() {
Player p = new Player("test");
Building8 b8 = new Building8(1, 1, 1);
Building0 b0 = new Building0(1, 1, 1);
p.buildingCards.add(b0);
assertThrows(IllegalArgumentException.class, () -> b8.applyEffect(p));
}
}
@@ -1,7 +1,6 @@
package it.polimi.ingsw.gc14.Model.Cards;
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building0;
import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building13;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
@@ -145,9 +144,9 @@ class BuildingCardTest {
BuildingCard bc0 = new BuildingCard(2, 1,1,1);
assertEquals(true, bc0.buy(p1));
assertEquals(false, bc0.buy(p1));
assertEquals(false, bc0.buy(p2));
assertTrue(bc0.buy(p1));
assertFalse(bc0.buy(p1));
assertFalse(bc0.buy(p2));
}
@Test
@@ -155,6 +154,37 @@ class BuildingCardTest {
void testToString() {
Building13 b0 = new Building13(1, 2,3);
assertEquals("Era:1\nPrice:2\nPrestige:3\n", b0.toString());
assertEquals("Era:1 Price:2 Prestige:3", b0.toString());
}
@Test
@DisplayName("Apply Effect")
void applyEffect(){
String user = "test";
Player p = new Player(user);
assertTrue(p.buildingCards.isEmpty());
assertTrue(p.inventors.isEmpty());
assertTrue(p.builders.isEmpty());
assertTrue(p.gatherers.isEmpty());
assertTrue(p.shamans.isEmpty());
assertTrue(p.hunters.isEmpty());
assertTrue(p.artists.isEmpty());
assertEquals(0, p.getFoodValue());
assertEquals(0, p.getPrestigeValue());
assertEquals(user, p.getUserName());
BuildingCard b = new BuildingCard(1,2,3);
b.applyEffect(p);
assertTrue(p.buildingCards.isEmpty());
assertTrue(p.inventors.isEmpty());
assertTrue(p.builders.isEmpty());
assertTrue(p.gatherers.isEmpty());
assertTrue(p.shamans.isEmpty());
assertTrue(p.hunters.isEmpty());
assertTrue(p.artists.isEmpty());
assertEquals(0, p.getFoodValue());
assertEquals(0, p.getPrestigeValue());
assertEquals(user, p.getUserName());
}
}
@@ -79,6 +79,7 @@ class BuilderTest {
@Test
void constructorWithNMinTest() {
// Correct case
Builder b = new Builder(1, 2, 3, 4);
assertEquals(1, b.getEra());
@@ -87,6 +88,12 @@ class BuilderTest {
assertEquals(3, b.getPrestigeValue());
assertEquals(4, b.getNMin());
assertFalse(b.IsEventCard());
// Wrong reductionValue
assertThrows(IllegalArgumentException.class, () -> {new Builder(1, -1, 3, 4);});
// Wrong prestigeValue
assertThrows(IllegalArgumentException.class, () -> {new Builder(1, 2, -1, 4);});
}
@Test
@@ -105,4 +105,12 @@ class CavePaintingsTest {
assertEquals(1, cv2.getEra());
assertEquals(EventType.CAVE_PAINTINGS, cv2.getType());
}
@Test
@DisplayName("ToString testing")
void toStringTest() {
CavePaintings cv1 = new CavePaintings(1, 1,1,1);
assertEquals("Era:1, CAVE_PAINTINGS", cv1.toString());
}
}
@@ -107,4 +107,12 @@ class HuntTest {
assertEquals(1, h2.getEra());
assertEquals(EventType.HUNT, h2.getType());
}
@Test
@DisplayName("ToString testing")
void toStringTest() {
Hunt h1 = new Hunt(1, 3);
assertEquals("Era:1, HUNT", h1.toString());
}
}
@@ -206,4 +206,12 @@ class ShamanicRitualTest {
assertEquals(prestigeToRemove, sr2.prestigeToRemove);
}
@Test
@DisplayName("ToString testing")
void toStringTest() {
ShamanicRitual sr1 = new ShamanicRitual(1, 5,2);
assertEquals("Era:1, SHAMANIC_RITUAL", sr1.toString());
}
}
@@ -116,6 +116,14 @@ class SustenanceTest {
assertEquals(EventType.SUSTENANCE, s2.getType());
assertEquals(prestigeDebt, s2.getPrestigeDebt());
}
@Test
@DisplayName("ToString testing")
void toStringTest() {
Sustenance s1 = new Sustenance(1, 5);
assertEquals("Era:1, SUSTENANCE", s1.toString());
}
}
@@ -82,6 +82,13 @@ class BoardTest {
assertEquals(94 + 2 - (5+4) - (5+1), bd5.getTribeDeckSize());
}
@Test
@DisplayName("Testing era getter")
void getEra() {
Board bd = new Board(3);
assertEquals(1, bd.getEra());
}
@Test
@DisplayName("Testing constructor")
void testConstructor() {
@@ -159,15 +166,16 @@ class BoardTest {
@DisplayName("Removing a card from lower row of building cards")
void removeLowerBuildingCard() {
Board bd = new Board(3);
bd.lowerListBuilding.add(new BuildingCard(2, 1, 5, 10));
bd.lowerListBuilding.add(new BuildingCard(3, 2, 2, 1));
for (int i=0;i<3;i++) {
bd.nextRound(); // Skip to era 2
}
List<BuildingCard> before = bd.lowerListBuilding;
BuildingCard cardToRemove = before.get(0);
before.remove(0);
bd.removeUpperBuildingCard(cardToRemove);
bd.removeLowerBuildingCard(cardToRemove);
assertEquals(before, bd.lowerListBuilding);
}
@@ -186,4 +194,89 @@ class BoardTest {
assertEquals(numPlayer+4, bd.upperListTribe.size()); // Verifica che la nuova dimensione della lista superiore sia corretta
}
@Test
@DisplayName("Testing nextEra")
void nextEra() {
// Since nextEra is private, it must be tested through nextRound.
// In this test we simulate multiple rounds to trigger the next era activation.
// NOTE: after 3 rounds we are in era 2. After 6 we are in era 3.
int numPlayer;
List<BuildingCard> upperListBefore;
// Era 2, nTotem <= 3
numPlayer = 3;
Board bd1 = new Board(numPlayer);
upperListBefore = new ArrayList<>(bd1.upperListBuilding);
for (int i=0;i<3;i++) {
bd1.nextRound(); // Skip to era 2
}
assertEquals(2, bd1.getEra());
assertEquals(upperListBefore, bd1.lowerListBuilding);
assertNotEquals(upperListBefore, bd1.upperListBuilding);
assertEquals(2, bd1.upperListBuilding.size());
// Era 2, nTotem > 3
numPlayer = 4;
Board bd2 = new Board(numPlayer);
upperListBefore = new ArrayList<>(bd2.upperListBuilding);
for (int i=0;i<3;i++) {
bd2.nextRound(); // Skip to era 2
}
assertEquals(2, bd2.getEra());
assertEquals(upperListBefore, bd2.lowerListBuilding);
assertNotEquals(upperListBefore, bd2.upperListBuilding);
assertEquals(3, bd2.upperListBuilding.size());
// Era 3, nTotem == 2
numPlayer = 2;
Board bd3 = new Board(numPlayer);
for (int i=0;i<3;i++) {
bd3.nextRound(); // Skip to era 2
}
upperListBefore = new ArrayList<>(bd3.upperListBuilding); // We need to take the list of the era 2
for (int i=0;i<3;i++) {
bd3.nextRound(); // Skip to era 3
}
assertEquals(3, bd3.getEra());
assertEquals(upperListBefore, bd3.lowerListBuilding);
assertNotEquals(upperListBefore, bd3.upperListBuilding);
assertEquals(3, bd3.upperListBuilding.size());
// Era 3, nTotem == 5
numPlayer = 5;
Board bd4 = new Board(numPlayer);
for (int i=0;i<3;i++) {
bd4.nextRound(); // Skip to era 2
}
upperListBefore = new ArrayList<>(bd4.upperListBuilding); // We need to take the list of the era 2
for (int i=0;i<3;i++) {
bd4.nextRound(); // Skip to era 3
}
assertEquals(3, bd4.getEra());
assertEquals(upperListBefore, bd4.lowerListBuilding);
assertNotEquals(upperListBefore, bd4.upperListBuilding);
assertEquals(5, bd4.upperListBuilding.size());
// Era 3, nTotem != 2, 5
numPlayer = 3;
Board bd5 = new Board(numPlayer);
for (int i=0;i<3;i++) {
bd5.nextRound(); // Skip to era 2
}
upperListBefore = new ArrayList<>(bd5.upperListBuilding); // We need to take the list of the era 2
for (int i=0;i<3;i++) {
bd5.nextRound(); // Skip to era 3
}
assertEquals(3, bd5.getEra());
assertEquals(upperListBefore, bd5.lowerListBuilding);
assertNotEquals(upperListBefore, bd5.upperListBuilding);
assertEquals(4, bd5.upperListBuilding.size());
}
}
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
@@ -10,6 +11,16 @@ import static org.junit.jupiter.api.Assertions.*;
class Order2Test {
@Test
@DisplayName("Testing Order2 constructor with wrong number of player")
void constructorTest() {
Player p1 = new Player("p1");
ArrayList<Player> players = new ArrayList<>();
players.add(p1);
assertThrows(NoSuchElementException.class, () -> {new Order2(players);});
}
@Test
void firstReturnGetsFood() {
Player p1 = new Player("p1");
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
@@ -10,6 +11,15 @@ import static org.junit.jupiter.api.Assertions.*;
class Order3Test {
@Test
@DisplayName("Testing Order3 constructor with wrong number of player")
void constructorTest() {
Player p1 = new Player("p1");
ArrayList<Player> players = new ArrayList<>();
players.add(p1);
assertThrows(NoSuchElementException.class, () -> {new Order3(players);});
}
@Test
void firstReturnGetsFood() {
Player p1 = new Player("p1");
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
@@ -10,6 +11,15 @@ import static org.junit.jupiter.api.Assertions.*;
class Order4Test {
@Test
@DisplayName("Testing Order4 constructor with wrong number of player")
void constructorTest() {
Player p1 = new Player("p1");
ArrayList<Player> players = new ArrayList<>();
players.add(p1);
assertThrows(NoSuchElementException.class, () -> {new Order4(players);});
}
@Test
void firstReturnGetsFood() {
Player p1 = new Player("p1");
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.*;
@@ -15,6 +16,15 @@ import static org.junit.jupiter.api.Assertions.*;
class Order5Test {
@Test
@DisplayName("Testing Order5 constructor with wrong number of player")
void constructorTest() {
Player p1 = new Player("p1");
ArrayList<Player> players = new ArrayList<>();
players.add(p1);
assertThrows(NoSuchElementException.class, () -> {new Order5(players);});
}
@Test
void firstReturnGetsFood() {
Player p1 = new Player("p1");
@@ -11,24 +11,26 @@ class PlayableCardTest {
@Test
void PlayableCardWrongEraException() {
assertDoesNotThrow(() -> {
new BuildingCard(1, 5, 1);
new BuildingCard(2,1, 5, 1);
});
assertDoesNotThrow(() -> {
new BuildingCard(2, 5, 1);
new BuildingCard(2, 2, 5, 1);
});
assertDoesNotThrow(() -> {
new BuildingCard(3, 5, 1);
new BuildingCard(2, 3, 5, 1);
});
assertThrows(IllegalArgumentException.class, () -> {
new BuildingCard(0, 5, 1);
new BuildingCard(2, 0, 5, 1);
});
assertThrows(IllegalArgumentException.class, () -> {
new BuildingCard(4, 5, 1);
new BuildingCard(2, 4, 5, 1);
});
assertThrows(IllegalArgumentException.class, () -> {
new BuildingCard(-1, 5, 1);
new BuildingCard(2, -1, 5, 1);
});
}
}
}
@@ -201,8 +201,8 @@ class PlayerTest {
p.addFood(7);
p.artists.add(new Artist(1));
p.artists.add(new Artist(2));
p.buildingCards.add(new BuildingCard(1,2, 5));
p.buildingCards.add(new BuildingCard(2,3, 6));
p.buildingCards.add(new BuildingCard(2, 1,2, 5));
p.buildingCards.add(new BuildingCard(2, 2,3, 6));
assertEquals("test_usr:"+ "\n\t" +
"Food: 7" + "\n\t" +
"Prestige: 15" + "\n\t" +