Legger til tester for RoboRallyGame og legger til noen begrensinger

Begrenser prioritet på programmeringskort til prioriteter brukt i brettspillet
Begrenser programmet spillet mellomlagrer til et program med nøyaktig 5 kort
Fikser prioriteter brukt i tester
This commit is contained in:
Kristian Knarvik 2020-04-24 17:50:57 +02:00
parent 38cec559d9
commit 4f47e7e809
6 changed files with 88 additions and 20 deletions

View File

@ -17,6 +17,9 @@ public class ProgrammingCard implements Comparable<ProgrammingCard> {
* @param cardAction the action of the card
*/
public ProgrammingCard(int cardPriority, Action cardAction) {
if (cardPriority < 10 || cardPriority > 840 || cardPriority % 10 != 0) {
throw new IllegalArgumentException("You cannot create a programming card not part of the original game.");
}
this.cardPriority = cardPriority;
this.cardAction = cardAction;
}

View File

@ -131,6 +131,9 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
@Override
public void setProgram(List<ProgrammingCard> program) {
if (program.size() != 5) {
throw new IllegalArgumentException("Invalid program chosen.");
}
this.program = program;
}

View File

@ -270,9 +270,9 @@ public class PhaseTest {
List<ProgrammingCard> testProgram1 = new ArrayList<>();
List<ProgrammingCard> testProgram2 = new ArrayList<>();
List<ProgrammingCard> testProgram3 = new ArrayList<>();
testProgram1.add(new ProgrammingCard(1, Action.MOVE_1));
testProgram2.add(new ProgrammingCard(10, Action.MOVE_1));
testProgram3.add(new ProgrammingCard(100, Action.ROTATE_LEFT));
testProgram1.add(new ProgrammingCard(10, Action.MOVE_1));
testProgram2.add(new ProgrammingCard(20, Action.MOVE_1));
testProgram3.add(new ProgrammingCard(30, Action.ROTATE_LEFT));
for (int i = 0; i < 4; i++) {
testProgram1.add(null);
testProgram2.add(null);

View File

@ -29,9 +29,9 @@ public class ProgrammingCardDeckTest {
e.printStackTrace();
}
ArrayList<ProgrammingCard> cardList = new ArrayList<>();
programmingCard1 = new ProgrammingCard(5, Action.MOVE_1);
ProgrammingCard programmingCard2 = new ProgrammingCard(6, Action.MOVE_2);
programmingCard3 = new ProgrammingCard(7, Action.MOVE_3);
programmingCard1 = new ProgrammingCard(10, Action.MOVE_1);
ProgrammingCard programmingCard2 = new ProgrammingCard(20, Action.MOVE_2);
programmingCard3 = new ProgrammingCard(30, Action.MOVE_3);
cardList.add(programmingCard1);
cardList.add(programmingCard2);
cardList.add(programmingCard3);

View File

@ -15,9 +15,9 @@ public class ProgrammingCardTest {
@Before
public void setUp() {
programmingCard1 = new ProgrammingCard(5, Action.MOVE_1);
programmingCard2 = new ProgrammingCard(234, Action.ROTATE_LEFT);
programmingCard3 = new ProgrammingCard(2334, Action.ROTATE_LEFT);
programmingCard1 = new ProgrammingCard(50, Action.MOVE_1);
programmingCard2 = new ProgrammingCard(230, Action.ROTATE_LEFT);
programmingCard3 = new ProgrammingCard(500, Action.ROTATE_LEFT);
}
@Test
@ -28,8 +28,8 @@ public class ProgrammingCardTest {
@Test
public void testGetProgrammingCardValue() {
assertEquals(5, programmingCard1.getPriority());
assertEquals(234, programmingCard2.getPriority());
assertEquals(2334, programmingCard3.getPriority());
assertEquals(50, programmingCard1.getPriority());
assertEquals(230, programmingCard2.getPriority());
assertEquals(500, programmingCard3.getPriority());
}
}

View File

@ -1,14 +1,20 @@
package inf112.fiasko.roborally.objects;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNull;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import inf112.fiasko.roborally.elementproperties.Action;
import inf112.fiasko.roborally.elementproperties.GameState;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
public class RoboRallyGameTest {
private DrawableGame game;
private RoboRallyGame game;
@Before
public void setUp() {
@ -21,18 +27,74 @@ public class RoboRallyGameTest {
assertTrue(game.getWidth() > 0);
}
@Test
public void gameWidthIsMaximumFullHD() {
assertTrue(game.getWidth() <= 1920);
}
@Test
public void gameHeightIsPositive() {
assertTrue(game.getHeight() > 0);
}
@Test
public void gameHeightIsMaximumFullHD() {
assertTrue(game.getHeight() <= 1080);
public void initialGameStateIsCorrect() {
assertEquals(GameState.BEGINNING_OF_GAME, game.getGameState());
}
@Test
public void gameStateIsChangeable() {
game.setGameState(GameState.EXITED);
assertEquals(GameState.EXITED, game.getGameState());
}
@Test
public void gameWidthIsEqualToBoardWidth() {
assertEquals(12, game.getWidth());
}
@Test
public void gameHeightIsEqualToBoardHeight() {
assertEquals(16, game.getHeight());
}
@Test (expected = IllegalArgumentException.class)
public void invalidProgramThrowsError() {
List<ProgrammingCard> programmingCardList = new ArrayList<>();
programmingCardList.add(new ProgrammingCard(10, Action.MOVE_1));
game.setProgram(programmingCardList);
}
@Test
public void canChangeGameProgram() {
assertNull(game.getProgram());
List<ProgrammingCard> programmingCardList = new ArrayList<>();
programmingCardList.add(new ProgrammingCard(10, Action.MOVE_1));
programmingCardList.add(new ProgrammingCard(30, Action.MOVE_2));
programmingCardList.add(new ProgrammingCard(50, Action.MOVE_3));
programmingCardList.add(new ProgrammingCard(340, Action.BACK_UP));
programmingCardList.add(new ProgrammingCard(450, Action.U_TURN));
game.setProgram(programmingCardList);
assertEquals(programmingCardList, game.getProgram());
}
@Test
public void canChangePlayerHand() {
assertNull(game.getPlayerHand());
ProgrammingCard card = new ProgrammingCard(10, Action.ROTATE_RIGHT);
List<ProgrammingCard> cards = new ArrayList<>();
cards.add(card);
ProgrammingCardDeck deck = new ProgrammingCardDeck(cards);
game.setPlayerHand(deck);
assertEquals(card, game.getPlayerHand().peekTop());
}
@Test
public void canChangeWinningPlayer() {
assertNull(game.getWinningPlayerName());
String winning = "Player 1";
game.setWinningPlayerName(winning);
assertEquals(winning, game.getWinningPlayerName());
}
@Test
public void canGetPowerDown() {
assertFalse(game.getRobotPowerDown());
}
}