From 407863055a65a38fe0874d017d9ba91aae15770c Mon Sep 17 00:00:00 2001 From: MikeZyeman Date: Fri, 10 Dec 2021 19:30:44 +0100 Subject: [PATCH 1/5] Removed unfinished tests --- test/ch/zhaw/catan/SiedlerGameTest.java | 49 ++++++------------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/test/ch/zhaw/catan/SiedlerGameTest.java b/test/ch/zhaw/catan/SiedlerGameTest.java index 29fa1e7..1efd9bc 100644 --- a/test/ch/zhaw/catan/SiedlerGameTest.java +++ b/test/ch/zhaw/catan/SiedlerGameTest.java @@ -229,50 +229,25 @@ public class SiedlerGameTest { public void TestGameAfterSetupPhase() { SiedlerGame game = gameAfterSetupPhase(); - System.out.println(game.getBoard().toString()); + //throwDiceSeveralTimes(game, 5, 1); + throwDiceSeveralTimes(game, 8, 1); - throwDiceSeveralTimes(game, 5, 5); - throwDiceSeveralTimes(game, 5, 5); - throwDiceSeveralTimes(game, 5, 5); - throwDiceSeveralTimes(game, 5, 5); - throwDiceSeveralTimes(game, 5, 5); + getResourceTypeFromField(game.getBoard().getFieldsForDiceValue(8), game.getCurrentPlayerFaction()); - //game.switchToNextPlayer(); - - //throwDiceSeveralTimes(game, 6, 5); - //throwDiceSeveralTimes(game, 6, 5); - //throwDiceSeveralTimes(game, 6, 5); - //throwDiceSeveralTimes(game, 6, 5); - //throwDiceSeveralTimes(game, 6, 5); - - soutDistribution(game); - } - - - /** - * tests, if a player wins when reached the amount of points. - */ - @Test - @DisplayName("End of Game test") - public void TestGameEnd() { + //Assertions.assertEquals(game.getCurrentPlayerResource().get(), game.getBoard().getFieldsForDiceValue(8).size()); } - //TEMPORARY METHOD, WILL BE REMOVED SOON - private static void soutDistribution(SiedlerGame game) { - System.out.println("\n\nVerteilung \n\n"); - for (int i = 0 ; i < game.getPlayerFactions().size(); i++) { - HashMap resources = game.getCurrentPlayerResource(); - System.out.println(game.getCurrentPlayerFaction().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)); + private void getResourceTypeFromField(List points, Config.Faction faction) { - game.switchToNextPlayer(); + SiedlerBoard b = new SiedlerBoard(); + + for (Point point: points) { + System.out.println(point.toString()); + b.getFields(point); } } + } /** @@ -311,8 +286,6 @@ public class SiedlerGameTest { game.placeInitialRoad(secondRoad.first, secondRoad.second); } - System.out.println(game.getBoard().toString()); - return game; } From 3049650bc41ae05f27c05c2b59900a44db88553a Mon Sep 17 00:00:00 2001 From: MikeZyeman Date: Fri, 10 Dec 2021 19:48:17 +0100 Subject: [PATCH 2/5] Finished test case throwDice with 7 and TestGameAfterSetupPhase --- test/ch/zhaw/catan/SiedlerGameTest.java | 78 ++++++++----------------- 1 file changed, 24 insertions(+), 54 deletions(-) diff --git a/test/ch/zhaw/catan/SiedlerGameTest.java b/test/ch/zhaw/catan/SiedlerGameTest.java index 1efd9bc..eea1873 100644 --- a/test/ch/zhaw/catan/SiedlerGameTest.java +++ b/test/ch/zhaw/catan/SiedlerGameTest.java @@ -11,15 +11,6 @@ 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. - * - */ - /** * @class SiedlerGameTest * @@ -101,13 +92,32 @@ public class SiedlerGameTest { } /** + * Tests if the method throwDice halves the resources of the player + * 7 will be passed to the throwDice Method when called * + * Method does not halve a resource, when the amount is below 7. + * Player has gotten 8 wool resources and throws a 7 with the dice + * + * expected: throwDice with a 7 will halve wool resource, the amount should be 4 */ @Test - @DisplayName("Test") - public void TestHandle7() { - SiedlerGame game = startGame(); - //todo + @DisplayName("Test Throw Dice with value 7, expected half the resources") + public void TestThrowDiceWith7() { + SiedlerGame game = gameAfterSetupPhase(); + + throwDiceSeveralTimes(game, 8, 1); + + throwDiceSeveralTimes(game, 7, 1); + Assertions.assertEquals(2, game.getCurrentPlayerResource().get(Config.Resource.WOOL)); + + throwDiceSeveralTimes(game, 8, 1); + throwDiceSeveralTimes(game, 8, 1); + throwDiceSeveralTimes(game, 8, 1); + + Assertions.assertEquals(8, game.getCurrentPlayerResource().get(Config.Resource.WOOL)); + + throwDiceSeveralTimes(game, 7, 1); + Assertions.assertEquals(4, game.getCurrentPlayerResource().get(Config.Resource.WOOL)); } } @@ -179,18 +189,6 @@ public class SiedlerGameTest { Assertions.assertFalse(game.placeInitialSettlement(settlementPoint, false)); } - - /** - * This testcase will test, if the methods buildRoad, buildCity buildSettlement are overwritting - * already occupied positions if the same faction or any other faction are calling the method with the same positions - * - * Expected: Method placeInitialRoad placeInitialSettlement should return false, independent of the current faction playing - */ - @Test - @DisplayName("Test buildRoad, buildCity and buildSettlement with already occupied positions") - public void testBuildStructuresOnOccupiedFields() { - - } } /** @@ -229,24 +227,11 @@ public class SiedlerGameTest { public void TestGameAfterSetupPhase() { SiedlerGame game = gameAfterSetupPhase(); - //throwDiceSeveralTimes(game, 5, 1); throwDiceSeveralTimes(game, 8, 1); - - getResourceTypeFromField(game.getBoard().getFieldsForDiceValue(8), game.getCurrentPlayerFaction()); - - //Assertions.assertEquals(game.getCurrentPlayerResource().get(), game.getBoard().getFieldsForDiceValue(8).size()); + Assertions.assertEquals(2, game.getCurrentPlayerResourceStock(Config.Resource.WOOL)); } - private void getResourceTypeFromField(List points, Config.Faction faction) { - - SiedlerBoard b = new SiedlerBoard(); - - for (Point point: points) { - System.out.println(point.toString()); - b.getFields(point); - } - } } @@ -297,24 +282,9 @@ public class SiedlerGameTest { * @param amountDiceThrows Type int, The amount of dice throws */ private static void throwDiceSeveralTimes(SiedlerGame game, int dice, int amountDiceThrows) { - - //System.out.println(game.getCurrentPlayerFaction().toString() + " got " + dice + " and throw " + amountDiceThrows + " times"); - for (int i = 0; i < amountDiceThrows; i++) { game.throwDice(dice); } } - /** - * This method will setup a game to a state before a player has the points - * for being able to win the game - * - * @return SiedlerGame which is near the - */ - private static SiedlerGame gameNearEnd() { - SiedlerGame game = gameAfterSetupPhase(); - - return game; - } - } \ No newline at end of file From c16ddc6bca0620187744aba4a680f4ef0f6fd398 Mon Sep 17 00:00:00 2001 From: MikeZyeman Date: Fri, 10 Dec 2021 19:55:22 +0100 Subject: [PATCH 3/5] Redo if statement with exception throwing --- src/ch/zhaw/catan/SiedlerGame.java | 3 +++ test/ch/zhaw/catan/SiedlerGameTest.java | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index fcf3534..eff8ac0 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -32,6 +32,9 @@ public class SiedlerGame { * or players is not between two and four */ public SiedlerGame(int winPoints, int numberOfPlayers) { + if (winPoints < 3 || numberOfPlayers < Config.MIN_NUMBER_OF_PLAYERS || numberOfPlayers > 4) { + throw new IllegalArgumentException(); + } bank = new Bank(); board = new SiedlerBoard(); board.createFixGameField(); diff --git a/test/ch/zhaw/catan/SiedlerGameTest.java b/test/ch/zhaw/catan/SiedlerGameTest.java index eea1873..42a68ee 100644 --- a/test/ch/zhaw/catan/SiedlerGameTest.java +++ b/test/ch/zhaw/catan/SiedlerGameTest.java @@ -152,7 +152,6 @@ public class SiedlerGameTest { @Test @DisplayName("Starting Siedler game with one player, expects fail") public void startSiedlerGameWithLowerThanMinimumWinPoints() { - Exception exc = assertThrows(IllegalArgumentException.class, () -> { SiedlerGame game = new SiedlerGame(1, 4); }); From 1bdbc80c062bed0ef0276736c523c76c60b67ea8 Mon Sep 17 00:00:00 2001 From: MikeZyeman Date: Fri, 10 Dec 2021 19:56:10 +0100 Subject: [PATCH 4/5] Redo if statement with exception throwing --- test/ch/zhaw/catan/SiedlerGameTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ch/zhaw/catan/SiedlerGameTest.java b/test/ch/zhaw/catan/SiedlerGameTest.java index 42a68ee..854fa66 100644 --- a/test/ch/zhaw/catan/SiedlerGameTest.java +++ b/test/ch/zhaw/catan/SiedlerGameTest.java @@ -23,7 +23,7 @@ import java.util.List; * Tests the methods of SiedlerGame with values, that results to errors and failure * * - SystemTestCases - * Tests the coordination of all methods and simulates a game with all moves programmed + * Tests the coordination of all methods and simulates a game with programmed moves * Checks if the methods are being executed and the values are set correctly */ public class SiedlerGameTest { From 57e49db1f0834779c764ed674d1c2497fb461915 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 10 Dec 2021 20:15:48 +0100 Subject: [PATCH 5/5] reformat Code in SiedlerGameTest --- test/ch/zhaw/catan/SiedlerGameTest.java | 65 +++++++++++++------------ 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/test/ch/zhaw/catan/SiedlerGameTest.java b/test/ch/zhaw/catan/SiedlerGameTest.java index 854fa66..744e1e1 100644 --- a/test/ch/zhaw/catan/SiedlerGameTest.java +++ b/test/ch/zhaw/catan/SiedlerGameTest.java @@ -1,30 +1,35 @@ package ch.zhaw.catan; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import java.awt.*; -import java.util.*; +import java.awt.Point; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @class SiedlerGameTest - * + *

* contains all of the test cases for SiedlerGame class. * The Test cases are categorized into - * - Positive TestCases - * Tests the methods of SiedlerGame with the intended values - * - * - Negative TestCases - * Tests the methods of SiedlerGame with values, that results to errors and failure - * - * - SystemTestCases - * Tests the coordination of all methods and simulates a game with programmed moves - * Checks if the methods are being executed and the values are set correctly + * - Positive TestCases + * Tests the methods of SiedlerGame with the intended values + *

+ * - Negative TestCases + * Tests the methods of SiedlerGame with values, that results to errors and failure + *

+ * - SystemTestCases + * Tests the coordination of all methods and simulates a game with programmed moves + * Checks if the methods are being executed and the values are set correctly */ public class SiedlerGameTest { @@ -33,20 +38,20 @@ public class SiedlerGameTest { /** * Property START_SETTLEMENT_POSITIONS - * + *

* Lists all positions of Settlement for every faction in the initialization phase. * Each faction is assigned to a list of specific settlements, which represents as a list of points */ private final static Map> START_SETTLEMENT_POSITIONS = Map.of( - Config.Faction.BLUE, new ArrayList<>(List.of(new Point(4, 4), new Point(5, 7))), - Config.Faction.RED, new ArrayList<>(List.of(new Point(10, 4), new Point(9, 7))), - Config.Faction.GREEN, new ArrayList<>(List.of(new Point(4, 18), new Point(5, 15))), - Config.Faction.YELLOW, new ArrayList<>(List.of(new Point(10, 18), new Point(9, 15))) + Config.Faction.BLUE, new ArrayList<>(List.of(new Point(4, 4), new Point(5, 7))), + Config.Faction.RED, new ArrayList<>(List.of(new Point(10, 4), new Point(9, 7))), + Config.Faction.GREEN, new ArrayList<>(List.of(new Point(4, 18), new Point(5, 15))), + Config.Faction.YELLOW, new ArrayList<>(List.of(new Point(10, 18), new Point(9, 15))) ); /** * Property START_ROADS_POSITION - * + *

* Lists all endpoints of roads for every faction in the initialization phase. * Each faction is assigned to a specific Road, which represents as a tuple of 2 points */ @@ -78,7 +83,7 @@ public class SiedlerGameTest { public void TestGameInitializationWithAllPlayercounts(int playerAmount) { SiedlerGame game = new SiedlerGame(DEFAULT_WINPOINTS, playerAmount); - for (Config.Faction faction: game.getPlayerFactions()) { + for (Config.Faction faction : game.getPlayerFactions()) { HashMap resources = game.getCurrentPlayerResource(); Assertions.assertEquals(0, resources.get(Config.Resource.BRICK)); @@ -94,10 +99,10 @@ public class SiedlerGameTest { /** * Tests if the method throwDice halves the resources of the player * 7 will be passed to the throwDice Method when called - * + *

* Method does not halve a resource, when the amount is below 7. * Player has gotten 8 wool resources and throws a 7 with the dice - * + *

* expected: throwDice with a 7 will halve wool resource, the amount should be 4 */ @Test @@ -123,7 +128,7 @@ public class SiedlerGameTest { /** * @Class NegAtiveTestcases - * + *

* contains all negative test cases */ @Nested @@ -163,7 +168,7 @@ public class SiedlerGameTest { /** * This testcase will test, if the methods placeInitialRoad and placeInitialSettlement are overwritting * already occupied positions if the same faction or any other faction are calling the method with the same positions - * + *

* Expected: Method placeInitialRoad placeInitialSettlement should return false, independent of the current faction playing */ @Test @@ -192,7 +197,7 @@ public class SiedlerGameTest { /** * @Class SystemTestCases - * + *

* This class simulates a running game and tests multiple sequences of this game. */ @Nested @@ -276,9 +281,9 @@ public class SiedlerGameTest { /** * This method will call the method "throwDice" multiple times and passes the set value of the dice * - * @param game Type SiedlerGame, the game itself in a running state - * @param dice Type int, Set Value of dice - * @param amountDiceThrows Type int, The amount of dice throws + * @param game Type SiedlerGame, the game itself in a running state + * @param dice Type int, Set Value of dice + * @param amountDiceThrows Type int, The amount of dice throws */ private static void throwDiceSeveralTimes(SiedlerGame game, int dice, int amountDiceThrows) { for (int i = 0; i < amountDiceThrows; i++) {