Added test classes for separation of purpose.
This commit is contained in:
		
							parent
							
								
									1bbb05ebfd
								
							
						
					
					
						commit
						5770d86a6f
					
				| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
 | 
			
		||||
  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
 | 
			
		||||
    <output url="file://$PROJECT_DIR$/out" />
 | 
			
		||||
  </component>
 | 
			
		||||
</project>
 | 
			
		||||
| 
						 | 
				
			
			@ -7,10 +7,7 @@ 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 org.junit.jupiter.api.*;
 | 
			
		||||
 | 
			
		||||
import java.awt.*;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
| 
						 | 
				
			
			@ -28,25 +25,14 @@ import java.util.List;
 | 
			
		|||
 | 
			
		||||
public class SiedlerGameTest {
 | 
			
		||||
 | 
			
		||||
    private final static int DEFAULT_WINPOINTS = 10;
 | 
			
		||||
    private final static int DEFAULT_WINPOINTS = 5;
 | 
			
		||||
    private final static int DEFAULT_PLAYERAMOUNT = 4;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private final static Map<Config.Faction, Point> 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<Config.Faction, Tuple<Point, Point>> 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))
 | 
			
		||||
            ));
 | 
			
		||||
    @Nested
 | 
			
		||||
    @DisplayName("Positive test cases")
 | 
			
		||||
    class PositiveTestcases {
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * To Test getLongestRoad in SiedlerBoard
 | 
			
		||||
| 
						 | 
				
			
			@ -73,6 +59,21 @@ public class SiedlerGameTest {
 | 
			
		|||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         *
 | 
			
		||||
         */
 | 
			
		||||
        @Test
 | 
			
		||||
        @DisplayName("Test")
 | 
			
		||||
        public void TestHandle7() {
 | 
			
		||||
 | 
			
		||||
            SiedlerGame game = SystemTestcases.startGame();
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nested
 | 
			
		||||
    @DisplayName("Negative test cases")
 | 
			
		||||
    class NegativeTestcases {
 | 
			
		||||
        /**
 | 
			
		||||
         * Tests if the method will fail when given false Data
 | 
			
		||||
         * {@link ThreePlayerStandard#getAfterSetupPhaseAlmostEmptyBank(int)}
 | 
			
		||||
| 
						 | 
				
			
			@ -115,9 +116,48 @@ public class SiedlerGameTest {
 | 
			
		|||
 | 
			
		||||
            System.out.println(model.tradeWithBankFourToOne(Config.Resource.WOOL, Config.Resource.WOOL));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @Class SystemTestCases
 | 
			
		||||
     *
 | 
			
		||||
     * This class simulates a running game and tests multiple sequences of this game.
 | 
			
		||||
     * Those test cases will be
 | 
			
		||||
     *
 | 
			
		||||
     */
 | 
			
		||||
    @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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        @Test
 | 
			
		||||
    public void TestGameInSetupPhase() {
 | 
			
		||||
        @DisplayName("Game initializing")
 | 
			
		||||
        public void TestGameInitialization() {
 | 
			
		||||
            SiedlerGame game = startGame();
 | 
			
		||||
 | 
			
		||||
            for (Config.Faction faction: game.getPlayerFactions()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -133,6 +173,40 @@ public class SiedlerGameTest {
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * This will test when
 | 
			
		||||
         */
 | 
			
		||||
        @Test
 | 
			
		||||
        public void TestGameInSetupPhase() {
 | 
			
		||||
            SiedlerGame game = gameInSetupPhase();
 | 
			
		||||
 | 
			
		||||
            for (Config.Faction faction: game.getPlayerFactions()) {
 | 
			
		||||
                HashMap<Config.Resource, Integer> 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();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static SiedlerGame gameInSetupPhase() {
 | 
			
		||||
            SiedlerGame game = startGame();
 | 
			
		||||
 | 
			
		||||
            for (Config.Faction faction: game.getPlayerFactions()) {
 | 
			
		||||
 | 
			
		||||
                game.placeInitialSettlement(START_SETTLEMENT_POSITIONS.get(faction), false);
 | 
			
		||||
                game.placeInitialRoad(START_ROADS_POSITIONS.get(faction).first, START_ROADS_POSITIONS.get(faction).second);
 | 
			
		||||
 | 
			
		||||
                game.switchToNextPlayer();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return game;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Test
 | 
			
		||||
        public void TestGameAfterSetupPhase() {
 | 
			
		||||
            SiedlerGame game = gameAfterSetupPhase();
 | 
			
		||||
| 
						 | 
				
			
			@ -153,33 +227,34 @@ public class SiedlerGameTest {
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static SiedlerGame gameAfterSetupPhase() {
 | 
			
		||||
            SiedlerGame game = gameInSetupPhase();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            return game;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Test
 | 
			
		||||
    public void TestGameInMiddle() {
 | 
			
		||||
        @DisplayName("End of Game test")
 | 
			
		||||
        public void TestGameEnd() {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    private SiedlerGame startGame() {
 | 
			
		||||
        return new SiedlerGame(DEFAULT_WINPOINTS, DEFAULT_PLAYERAMOUNT);
 | 
			
		||||
        private static SiedlerGame gameNearEnd() {
 | 
			
		||||
            SiedlerGame game = gameAfterSetupPhase();
 | 
			
		||||
 | 
			
		||||
            return game;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    private void throwDiceSeveralTimes(SiedlerGame game, int dice, int amountDiceThrows) {
 | 
			
		||||
        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);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue