Fix: GameTest Partial

This commit is contained in:
rubenpirreram
2026-04-11 17:23:41 +02:00
parent aeb3117d4a
commit 0462f0f39e
2 changed files with 79 additions and 3 deletions
@@ -33,6 +33,21 @@ public class Game {
board.upperListTribe.forEach(x->cards.add(x.clone())); board.upperListTribe.forEach(x->cards.add(x.clone()));
return cards; return cards;
} }
public List<TribeCard>getLowerListTribeCards() {
List<TribeCard> cards = new ArrayList<>();
board.lowerListTribe.forEach(x->cards.add(x.clone()));
return cards;
}
public List<BuildingCard>getUpperListBuilding() {
List<BuildingCard> cards = new ArrayList<>();
board.lowerListBuilding.forEach(x->cards.add(x.clone()));
return cards;
}
public List<BuildingCard>getLowerListBuilding() {
List<BuildingCard> cards = new ArrayList<>();
board.lowerListBuilding.forEach(x->cards.add(x.clone()));
return cards;
}
public CurrentState getCurrentState() { public CurrentState getCurrentState() {
return currentState; return currentState;
}; };
@@ -41,6 +56,11 @@ public class Game {
throw new IndexOutOfBoundsException("Player index out of bounds"); throw new IndexOutOfBoundsException("Player index out of bounds");
return playersList.get(playerIndex); return playersList.get(playerIndex);
} }
public Player getPlayerByUsername(int playerIndex) throws IndexOutOfBoundsException {
if(playerIndex >= playersList.size())
throw new IndexOutOfBoundsException("Player index out of bounds");
return playersList.get(playerIndex);
}
public int getNPlayers() { public int getNPlayers() {
@@ -157,7 +177,7 @@ public class Game {
if(currentState.getNLower() <1) if(currentState.getNLower() <1)
return false; return false;
TribeCard tribeCard = board.lowerListTribe.get(cardIndex); TribeCard tribeCard = board.lowerListTribe.get(cardIndex);
if(!tribeCard.IsEventCard()) if(tribeCard.IsEventCard())
return false; return false;
Character tempCard = (Character) tribeCard; Character tempCard = (Character) tribeCard;
@@ -305,9 +325,10 @@ public class Game {
if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) { if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) {
orderLogicCard.push(currentState.getCurrentPlayer()); orderLogicCard.push(currentState.getCurrentPlayer());
slotMap.put(currentState.getSlot(), null); slotMap.put(currentState.getSlot(), null);
for (Slot s : board.getSlotList()) { for (Slot s : slotMap.keySet()) {
if (slotMap.get(s) != null) { if (slotMap.get(s) != null) {
currentState.PlayerUpdate(slotMap.get(s), s); currentState.PlayerUpdate(slotMap.get(s), s);
break;
} }
} }
if(slotMap.values().stream().allMatch(v -> v == null)) if(slotMap.values().stream().allMatch(v -> v == null))
@@ -1,8 +1,14 @@
package it.polimi.ingsw.gc14.Model; package it.polimi.ingsw.gc14.Model;
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages; import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class GameTest { class GameTest {
@@ -28,6 +34,7 @@ class GameTest {
@Test @Test
void getNPlayers() { void getNPlayers() {
} }
@Test @Test
@@ -60,7 +67,55 @@ class GameTest {
} }
@Test @Test
void drawUpperTribeCardByIndex() { void drawingTribeCardByIndex() {
Game game=new Game(3);
Player p1=new Player("p1");
Player p2=new Player("p2");
Player p3=new Player("p3");
Player p4=new Player("p3");
assertTrue(game.addPlayer(p1));
assertTrue(game.addPlayer(p2));
assertFalse(game.addPlayer(p2));
assertTrue(game.addPlayer(p3));
Queue<Player>players=new LinkedList<>();
for(int i=0;i<3;i++) {
players.add( game.getCurrentState().getCurrentPlayer());
assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i));
}
Player temp_player;
temp_player=players.poll();
assertEquals(temp_player,game.getCurrentState().getCurrentPlayer());
int index;
List<TribeCard> cards=game.getLowerListTribeCards();
index=cards.indexOf(cards.stream().filter(x->!x.IsEventCard()).findFirst().get());
assertTrue(game.DrawLowerTribeCardByIndex(temp_player,index));
temp_player=players.poll();
assertEquals(temp_player,game.getCurrentState().getCurrentPlayer());
while(game.getCurrentState().getNUpper()>1) {
cards=game.getUpperListTribeCards();
index=cards.indexOf(cards.stream().filter(x->!x.IsEventCard()).findFirst().get());
assertTrue(game.DrawUpperTribeCardByIndex(temp_player,index));
}
cards=game.getUpperListTribeCards();
index=cards.indexOf(cards.stream().filter(TribeCard::IsEventCard).findFirst().get());
assertFalse(game.DrawUpperTribeCardByIndex(temp_player,index));
index=cards.indexOf(cards.stream().filter(x->!x.IsEventCard()).findFirst().get());
assertTrue(game.DrawUpperTribeCardByIndex(temp_player,index));
index=cards.indexOf(cards.stream().filter(x->!x.IsEventCard()).findFirst().get());
assertFalse(game.DrawUpperTribeCardByIndex(temp_player,index));
} }
@Test @Test