diff --git a/src/main/java/inf112/fiasko/roborally/objects/Wall.java b/src/main/java/inf112/fiasko/roborally/objects/Wall.java index 8f4c941..cbe3ab5 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Wall.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Wall.java @@ -17,6 +17,9 @@ public class Wall { * @param direction The direction of the wall */ public Wall (WallType wallType, Direction direction) { + if (direction.getDirectionID() % 2 == 0 && wallType != WallType.WALL_CORNER) { + throw new IllegalArgumentException("Invalid direction for wall type submitted"); + } this.wallType = wallType; this.direction = direction; } diff --git a/src/test/java/inf112/fiasko/roborally/element_properties/TileTypeTest.java b/src/test/java/inf112/fiasko/roborally/element_properties/TileTypeTest.java index 880a397..4bf8f84 100644 --- a/src/test/java/inf112/fiasko/roborally/element_properties/TileTypeTest.java +++ b/src/test/java/inf112/fiasko/roborally/element_properties/TileTypeTest.java @@ -1,5 +1,6 @@ package inf112.fiasko.roborally.element_properties; +import inf112.fiasko.roborally.objects.Tile; import org.junit.Test; import java.util.ArrayList; @@ -44,6 +45,11 @@ public class TileTypeTest { assertNull(TileType.getTileTypeFromID(-1)); } + @Test (expected = IllegalArgumentException.class) + public void invalidTileDirectionThrowsError() { + new Tile(TileType.TILE, Direction.NORTH_EAST); + } + @Test public void allTilesHaveUniqueId() { /* This test is also done implicitly by the allTileTypesIDConversionToIDAndBack test, but that test may fail diff --git a/src/test/java/inf112/fiasko/roborally/element_properties/WallTypeTest.java b/src/test/java/inf112/fiasko/roborally/element_properties/WallTypeTest.java index a622b43..88b7ea8 100644 --- a/src/test/java/inf112/fiasko/roborally/element_properties/WallTypeTest.java +++ b/src/test/java/inf112/fiasko/roborally/element_properties/WallTypeTest.java @@ -1,5 +1,6 @@ package inf112.fiasko.roborally.element_properties; +import inf112.fiasko.roborally.objects.Wall; import org.junit.Test; import java.util.ArrayList; @@ -44,6 +45,11 @@ public class WallTypeTest { assertNull(TileType.getTileTypeFromID(-1)); } + @Test (expected = IllegalArgumentException.class) + public void invalidWallDirectionThrowsError() { + new Wall(WallType.WALL_NORMAL, Direction.NORTH_EAST); + } + @Test public void allWallsHaveUniqueId() { /* This test is also done implicitly by the allTileTypesIDConversionToIDAndBack test, but that test may fail