2021-11-19 08:32:32 +01:00
|
|
|
package ch.zhaw.catan;
|
|
|
|
|
2021-12-08 14:39:19 +01:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
2021-11-19 08:32:32 +01:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
2021-12-05 13:53:36 +01:00
|
|
|
|
2021-12-08 14:39:19 +01:00
|
|
|
import ch.zhaw.catan.games.ThreePlayerStandard;
|
2021-12-09 16:14:47 +01:00
|
|
|
import org.junit.jupiter.api.*;
|
2021-11-19 08:32:32 +01:00
|
|
|
|
2021-12-05 13:53:36 +01:00
|
|
|
import java.awt.*;
|
2021-12-09 16:05:46 +01:00
|
|
|
import java.util.*;
|
|
|
|
import java.util.List;
|
2021-12-05 13:53:36 +01:00
|
|
|
|
2021-11-19 08:32:32 +01:00
|
|
|
|
|
|
|
/***
|
|
|
|
* TODO Write your own tests in this class.
|
|
|
|
*
|
|
|
|
* Note: Have a look at {@link ch.zhaw.catan.games.ThreePlayerStandard}. It can be used
|
|
|
|
* to get several different game states.
|
|
|
|
*
|
|
|
|
*/
|
2021-12-08 14:39:19 +01:00
|
|
|
|
|
|
|
|
2021-11-19 08:32:32 +01:00
|
|
|
public class SiedlerGameTest {
|
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
private final static int DEFAULT_WINPOINTS = 5;
|
2021-12-08 14:39:19 +01:00
|
|
|
private final static int DEFAULT_PLAYERAMOUNT = 4;
|
2021-11-19 08:32:32 +01:00
|
|
|
|
2021-12-08 15:01:33 +01:00
|
|
|
|
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
@Nested
|
|
|
|
@DisplayName("Positive test cases")
|
|
|
|
class PositiveTestcases {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To Test getLongestRoad in SiedlerBoard
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testLongestRoad() {
|
|
|
|
List<Config.Faction> factionList = Arrays.asList(Config.Faction.values());
|
|
|
|
|
|
|
|
SiedlerBoard board = new SiedlerBoard();
|
2021-12-09 17:19:40 +01:00
|
|
|
board.createFixGameField();
|
2021-12-09 16:14:47 +01:00
|
|
|
board.setEdge(new Point(6, 6), new Point(5, 7), new Road(Config.Faction.BLUE,new Point(6, 6),new Point(5, 7)));
|
|
|
|
board.setEdge(new Point(4, 6), new Point(5, 7), new Road(Config.Faction.BLUE,new Point(4, 6),new Point(5, 7)));
|
|
|
|
board.setEdge(new Point(4, 6), new Point(4, 4), new Road(Config.Faction.BLUE,new Point(4, 6),new Point(4, 4)));
|
|
|
|
board.setEdge(new Point(4, 6), new Point(3, 7), new Road(Config.Faction.BLUE,new Point(4, 6),new Point(3, 7)));
|
|
|
|
board.setEdge(new Point(3, 7), new Point(3, 9), new Road(Config.Faction.BLUE,new Point(3, 7),new Point(3, 9)));
|
|
|
|
board.setEdge(new Point(3, 9), new Point(4, 10), new Road(Config.Faction.BLUE,new Point(3, 9),new Point(4, 10)));
|
|
|
|
board.setEdge(new Point(4, 10), new Point(5, 9), new Road(Config.Faction.BLUE,new Point(4, 10),new Point(5, 9)));
|
|
|
|
board.setCorner(new Point(3,7),new Settlement(Config.Faction.BLUE,new Point(3,7)));
|
2021-12-09 17:42:43 +01:00
|
|
|
assertEquals(Config.Faction.BLUE, board.getLongestRoadFaction(factionList));
|
2021-12-10 10:36:48 +01:00
|
|
|
assertEquals(6,board.getLongestRoadLength());
|
2021-12-09 17:42:43 +01:00
|
|
|
//todo prüfen ob länge Stimmt.
|
2021-12-09 16:14:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
@DisplayName("Test")
|
|
|
|
public void TestHandle7() {
|
2021-12-09 16:05:46 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
SiedlerGame game = SystemTestcases.startGame();
|
|
|
|
|
|
|
|
}
|
2021-12-08 14:39:19 +01:00
|
|
|
}
|
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
@Nested
|
|
|
|
@DisplayName("Negative test cases")
|
|
|
|
class NegativeTestcases {
|
|
|
|
/**
|
|
|
|
* Tests if the method will fail when given false Data
|
|
|
|
* {@link ThreePlayerStandard#getAfterSetupPhaseAlmostEmptyBank(int)}
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void destructiveTestBuildCity() {
|
|
|
|
SiedlerGame model = ThreePlayerStandard.getAfterSetupPhaseAlmostEmptyBank(DEFAULT_WINPOINTS);
|
|
|
|
|
|
|
|
//Too
|
|
|
|
Assertions.assertFalse(model.buildCity(new Point(50, 60)));
|
|
|
|
|
|
|
|
//Factions wants to build a city on a city from another faction
|
|
|
|
Assertions.assertFalse(model.buildCity(new Point(3, 3)));
|
|
|
|
}
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
/**
|
|
|
|
* Tests if the method fails when given false Data
|
|
|
|
* {@link ThreePlayerStandard#getAfterSetupPhase(int)}
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void destructiveTestBuildRoad() {
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
SiedlerGame model = ThreePlayerStandard.getAfterSetupPhase(DEFAULT_WINPOINTS);
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
System.out.println(model.buildRoad(new Point(3, 7),new Point(3, 9)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests if the method fails when trading material with the same material
|
|
|
|
* {@link ThreePlayerStandard#getAfterSetupPhaseAlmostEmptyBank(int)}
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void destructiveTestTradeWithBank() {
|
|
|
|
SiedlerGame model = ThreePlayerStandard.getAfterSetupPhaseAlmostEmptyBank(DEFAULT_WINPOINTS);
|
|
|
|
model.switchToNextPlayer();
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
Map<Config.Resource, Integer> expectedResourceCards = ThreePlayerStandard.BANK_ALMOST_EMPTY_RESOURCE_CARD_STOCK.get(model.getCurrentPlayerFaction());
|
|
|
|
assertEquals(expectedResourceCards.get(Config.Resource.WOOL), model.getCurrentPlayerResourceStock(Config.Resource.WOOL));
|
|
|
|
assertEquals(expectedResourceCards.get(Config.Resource.LUMBER), model.getCurrentPlayerResourceStock(Config.Resource.LUMBER));
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
System.out.println(model.tradeWithBankFourToOne(Config.Resource.WOOL, Config.Resource.WOOL));
|
|
|
|
}
|
2021-12-08 14:39:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-12-09 16:14:47 +01:00
|
|
|
* @Class SystemTestCases
|
|
|
|
*
|
|
|
|
* This class simulates a running game and tests multiple sequences of this game.
|
|
|
|
* Those test cases will be
|
|
|
|
*
|
2021-12-08 14:39:19 +01:00
|
|
|
*/
|
2021-12-09 16:14:47 +01:00
|
|
|
@Nested
|
|
|
|
@DisplayName("System test cases")
|
|
|
|
class SystemTestcases {
|
|
|
|
|
|
|
|
private final static Map<Config.Faction, Point> START_SETTLEMENT_POSITIONS = new HashMap<>(
|
|
|
|
Map.of(
|
|
|
|
Config.Faction.BLUE, new Point(4, 4),
|
|
|
|
Config.Faction.RED, new Point(10, 4),
|
|
|
|
Config.Faction.GREEN, new Point(4, 18),
|
|
|
|
Config.Faction.YELLOW, new Point(10, 18)
|
|
|
|
));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Datafield START_ROADS_POSITION
|
|
|
|
*
|
|
|
|
* This are a set of Roads, that have been
|
|
|
|
*/
|
|
|
|
private final static Map<Config.Faction, Tuple<Point, Point>> START_ROADS_POSITIONS = new HashMap<>(
|
|
|
|
Map.of(
|
|
|
|
Config.Faction.BLUE, new Tuple<>(new Point(4, 4), new Point(4, 6)),
|
|
|
|
Config.Faction.RED, new Tuple<>(new Point(10, 4), new Point(10, 6)),
|
|
|
|
Config.Faction.GREEN, new Tuple<>(new Point(4, 18), new Point(4, 16)),
|
|
|
|
Config.Faction.YELLOW, new Tuple<>(new Point(10, 18), new Point(10, 16))
|
|
|
|
));
|
|
|
|
|
|
|
|
private static SiedlerGame startGame() {
|
|
|
|
return new SiedlerGame(DEFAULT_WINPOINTS, DEFAULT_PLAYERAMOUNT);
|
|
|
|
}
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-05 13:53:36 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
@Test
|
|
|
|
@DisplayName("Game initializing")
|
|
|
|
public void TestGameInitialization() {
|
|
|
|
SiedlerGame game = startGame();
|
2021-12-05 13:53:36 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
for (Config.Faction faction: game.getPlayerFactions()) {
|
|
|
|
HashMap<Config.Resource, Integer> resources = game.getCurrentPlayerResource();
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
Assertions.assertEquals(0, resources.get(Config.Resource.BRICK));
|
|
|
|
Assertions.assertEquals(0, resources.get(Config.Resource.GRAIN));
|
|
|
|
Assertions.assertEquals(0, resources.get(Config.Resource.LUMBER));
|
|
|
|
Assertions.assertEquals(0, resources.get(Config.Resource.ORE));
|
|
|
|
Assertions.assertEquals(0, resources.get(Config.Resource.WOOL));
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
game.switchToNextPlayer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This will test when
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void TestGameInSetupPhase() {
|
|
|
|
SiedlerGame game = gameInSetupPhase();
|
|
|
|
|
|
|
|
for (Config.Faction faction: game.getPlayerFactions()) {
|
|
|
|
HashMap<Config.Resource, Integer> resources = game.getCurrentPlayerResource();
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
Assertions.assertEquals(0, resources.get(Config.Resource.BRICK));
|
|
|
|
Assertions.assertEquals(0, resources.get(Config.Resource.GRAIN));
|
|
|
|
Assertions.assertEquals(0, resources.get(Config.Resource.LUMBER));
|
|
|
|
Assertions.assertEquals(0, resources.get(Config.Resource.ORE));
|
|
|
|
Assertions.assertEquals(0, resources.get(Config.Resource.WOOL));
|
|
|
|
|
|
|
|
game.switchToNextPlayer();
|
|
|
|
}
|
2021-12-08 14:39:19 +01:00
|
|
|
}
|
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
private static SiedlerGame gameInSetupPhase() {
|
|
|
|
SiedlerGame game = startGame();
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
for (Config.Faction faction: game.getPlayerFactions()) {
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
game.placeInitialSettlement(START_SETTLEMENT_POSITIONS.get(faction), false);
|
|
|
|
game.placeInitialRoad(START_ROADS_POSITIONS.get(faction).first, START_ROADS_POSITIONS.get(faction).second);
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
game.switchToNextPlayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
return game;
|
2021-12-08 14:39:19 +01:00
|
|
|
}
|
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
@Test
|
|
|
|
public void TestGameAfterSetupPhase() {
|
|
|
|
SiedlerGame game = gameAfterSetupPhase();
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
throwDiceSeveralTimes(game, 5, 5);
|
2021-12-08 14:39:19 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
System.out.println("\n\nVerteilung \n\n");
|
|
|
|
for (Config.Faction faction: game.getPlayerFactions()) {
|
|
|
|
HashMap<Config.Resource, Integer> resources = game.getCurrentPlayerResource();
|
|
|
|
System.out.println(faction.toString() + "\n");
|
|
|
|
System.out.println(" BRICK " + resources.get(Config.Resource.BRICK).toString());
|
|
|
|
System.out.println(" GRAIN " + resources.get(Config.Resource.GRAIN));
|
|
|
|
System.out.println(" LUMBER " + resources.get(Config.Resource.LUMBER));
|
|
|
|
System.out.println(" ORE " + resources.get(Config.Resource.ORE));
|
|
|
|
System.out.println(" WOOL " + resources.get(Config.Resource.WOOL));
|
2021-12-08 15:01:33 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
game.switchToNextPlayer();
|
|
|
|
}
|
2021-12-08 14:39:19 +01:00
|
|
|
}
|
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
private static SiedlerGame gameAfterSetupPhase() {
|
|
|
|
SiedlerGame game = gameInSetupPhase();
|
2021-12-08 14:39:19 +01:00
|
|
|
|
|
|
|
|
2021-12-08 15:01:33 +01:00
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
return game;
|
2021-12-08 14:39:19 +01:00
|
|
|
}
|
|
|
|
|
2021-12-09 16:14:47 +01:00
|
|
|
@Test
|
|
|
|
@DisplayName("End of Game test")
|
|
|
|
public void TestGameEnd() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private static SiedlerGame gameNearEnd() {
|
|
|
|
SiedlerGame game = gameAfterSetupPhase();
|
|
|
|
|
|
|
|
return game;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void throwDiceSeveralTimes(SiedlerGame game, int dice, int amountDiceThrows) {
|
|
|
|
for (int i = 0; i < amountDiceThrows; i++) {
|
|
|
|
System.out.println(game.getCurrentPlayerFaction().toString());
|
|
|
|
game.throwDice(dice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-08 14:39:19 +01:00
|
|
|
}
|
2021-11-19 08:32:32 +01:00
|
|
|
}
|