Added UnitTests for reconstruction/simulation for a real game
This commit is contained in:
		
							parent
							
								
									2d5cfc5e9e
								
							
						
					
					
						commit
						e9a6113097
					
				| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
<project version="4">
 | 
					<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" />
 | 
					    <output url="file://$PROJECT_DIR$/out" />
 | 
				
			||||||
  </component>
 | 
					  </component>
 | 
				
			||||||
</project>
 | 
					</project>
 | 
				
			||||||
| 
						 | 
					@ -45,11 +45,9 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
        return view.toString();
 | 
					        return view.toString();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    //TODO: Add fields, constructors and methods as you see fit. Do NOT change the signature
 | 
					    //TODO: Add fields, constructors and methods as you see fit. Do NOT change the signature
 | 
				
			||||||
    //      of the methods below.
 | 
					    //      of the methods below.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Returns the fields associated with the specified dice value.
 | 
					     * Returns the fields associated with the specified dice value.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,13 +1,21 @@
 | 
				
			||||||
package ch.zhaw.catan;
 | 
					package ch.zhaw.catan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import static org.junit.jupiter.api.Assertions.assertEquals;
 | 
				
			||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
 | 
					import static org.junit.jupiter.api.Assertions.assertTrue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import ch.zhaw.catan.games.ThreePlayerStandard;
 | 
				
			||||||
import org.beryx.textio.TextIO;
 | 
					import org.beryx.textio.TextIO;
 | 
				
			||||||
import org.beryx.textio.TextIoFactory;
 | 
					import org.beryx.textio.TextIoFactory;
 | 
				
			||||||
import org.beryx.textio.TextTerminal;
 | 
					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.Test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.awt.*;
 | 
					import java.awt.*;
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.HashMap;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/***
 | 
					/***
 | 
				
			||||||
| 
						 | 
					@ -17,12 +25,12 @@ import java.awt.*;
 | 
				
			||||||
 * to get several different game states.
 | 
					 * to get several different game states.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SiedlerGameTest {
 | 
					public class SiedlerGameTest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    private final static int DEFAULT_WINPOINTS = 10;
 | 
				
			||||||
    public void dummyTestMethod() {
 | 
					    private final static int DEFAULT_PLAYERAMOUNT = 4;
 | 
				
			||||||
        assertTrue(false);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * To Test getLongestRoad in SiedlerGame isolatet do:
 | 
					     * To Test getLongestRoad in SiedlerGame isolatet do:
 | 
				
			||||||
| 
						 | 
					@ -48,7 +56,108 @@ public class SiedlerGameTest {
 | 
				
			||||||
        board.setEdge(new Point(4, 10), new Point(5, 9), new Road(Config.Faction.BLUE,new Point(4, 10),new Point(5, 9)));
 | 
					        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.setCorner(new Point(3,7),new Settlement(Config.Faction.BLUE,new Point(3,7)));
 | 
				
			||||||
        //SiedlerGame.getLongestRoadFaction(board,faction);
 | 
					        //SiedlerGame.getLongestRoadFaction(board,faction);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 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<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));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        System.out.println(model.tradeWithBankFourToOne(Config.Resource.WOOL, Config.Resource.WOOL));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    public void TestGameInSetupPhase() {
 | 
				
			||||||
 | 
					        SiedlerGame game = new SiedlerGame(DEFAULT_WINPOINTS, DEFAULT_PLAYERAMOUNT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    public void TestGameAfterSetupPhase() {
 | 
				
			||||||
 | 
					        SiedlerGame game = new SiedlerGame(DEFAULT_WINPOINTS, DEFAULT_PLAYERAMOUNT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        throwDiceSeveralTimes(game, 5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        System.out.println("\n\nVerteilung \n\n");
 | 
				
			||||||
 | 
					        for (Config.Faction faction: game.getPlayerFactions()) {
 | 
				
			||||||
 | 
					            HashMap<Config.Resource, Integer> resources = game.getCurrentPlayerResource();
 | 
				
			||||||
 | 
					            System.out.printf(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 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 = new SiedlerGame(DEFAULT_WINPOINTS, DEFAULT_PLAYERAMOUNT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (Config.Faction faction: game.getPlayerFactions()) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return game;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue