package ch.zhaw.catan; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import ch.zhaw.catan.games.ThreePlayerStandard; import org.beryx.textio.TextIO; import org.beryx.textio.TextIoFactory; import org.beryx.textio.TextTerminal; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import java.awt.*; import java.util.*; import java.util.List; /*** * 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. * */ public class SiedlerGameTest { private final static int DEFAULT_WINPOINTS = 10; private final static int DEFAULT_PLAYERAMOUNT = 4; private final static Map START_SETTLEMENT_POSITIONS = new HashMap<>( Map.of( Config.Faction.BLUE, new Point(5, 7), Config.Faction.RED, new Point(1, 3), Config.Faction.GREEN, new Point(11, 13), Config.Faction.YELLOW, new Point(13, 5) )); private final static Map> START_ROADS_POSITIONS = new HashMap<>( Map.of( Config.Faction.BLUE, new Tuple<>(new Point(5, 6), new Point(5, 6)), Config.Faction.RED, new Tuple<>(new Point(1, 2), new Point(1, 1)), Config.Faction.GREEN, new Tuple<>(new Point(12, 12), new Point(13, 11)), Config.Faction.YELLOW, new Tuple<>(new Point(13, 6), new Point(13, 7)) )); /** * To Test getLongestRoad in SiedlerBoard * */ @Test public void testLongestRoad() { HashMap currentLongestRoad = new HashMap<>(); //currentLongestRoad.put(Config.Faction.RED,5); List factionList = Arrays.asList(Config.Faction.values()); SiedlerBoard board = new SiedlerBoard(); board.createFixGamefield(); 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))); board.getLongestRoadFaction(currentLongestRoad,factionList); assertEquals(6,currentLongestRoad.get(Config.Faction.BLUE)); } /** * 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))); } /** * Tests if the method fails when given false Data * {@link ThreePlayerStandard#getAfterSetupPhase(int)} */ @Test public void destructiveTestBuildRoad() { SiedlerGame model = ThreePlayerStandard.getAfterSetupPhase(DEFAULT_WINPOINTS); 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(); Map 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)); System.out.println(model.tradeWithBankFourToOne(Config.Resource.WOOL, Config.Resource.WOOL)); } @Test public void TestGameInSetupPhase() { SiedlerGame game = startGame(); for (Config.Faction faction: game.getPlayerFactions()) { HashMap resources = game.getCurrentPlayerResource(); 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(); } } @Test public void TestGameAfterSetupPhase() { SiedlerGame game = gameAfterSetupPhase(); throwDiceSeveralTimes(game, 5, 5); System.out.println("\n\nVerteilung \n\n"); for (Config.Faction faction: game.getPlayerFactions()) { HashMap 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)); game.switchToNextPlayer(); } } @Test public void TestGameInMiddle() { } private SiedlerGame startGame() { return new SiedlerGame(DEFAULT_WINPOINTS, DEFAULT_PLAYERAMOUNT); } private void throwDiceSeveralTimes(SiedlerGame game, int dice, int amountDiceThrows) { for (int i = 0; i < amountDiceThrows; i++) { System.out.println(game.getCurrentPlayerFaction().toString()); game.throwDice(dice); } } private SiedlerGame gameAfterSetupPhase() { SiedlerGame game = startGame(); for (Config.Faction faction: game.getPlayerFactions()) { game.buildSettlement(START_SETTLEMENT_POSITIONS.get(faction)); game.buildRoad(START_ROADS_POSITIONS.get(faction).first, START_ROADS_POSITIONS.get(faction).second); game.switchToNextPlayer(); } return game; } }