1
0
mirror of https://github.com/inf112-v20/Fiasko.git synced 2025-07-04 07:04:42 +02:00

Legger til manglende sjekking av retning for en vegg som instansieres

Legger til en test som sjekker at en exception blir kastet når en ugyldig vegg blir forsøkt instansiert
Legger til en test som sjekker at en exception blir kastet når en ugyldig tile blir forsøkt instansiert
This commit is contained in:
2020-03-02 13:26:42 +01:00
parent d7186d38c3
commit c6083c2a70
3 changed files with 15 additions and 0 deletions
src
main
java
inf112
fiasko
roborally
objects
test
java
inf112
fiasko
roborally

@ -17,6 +17,9 @@ public class Wall {
* @param direction The direction of the wall * @param direction The direction of the wall
*/ */
public Wall (WallType wallType, Direction direction) { 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.wallType = wallType;
this.direction = direction; this.direction = direction;
} }

@ -1,5 +1,6 @@
package inf112.fiasko.roborally.element_properties; package inf112.fiasko.roborally.element_properties;
import inf112.fiasko.roborally.objects.Tile;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
@ -44,6 +45,11 @@ public class TileTypeTest {
assertNull(TileType.getTileTypeFromID(-1)); assertNull(TileType.getTileTypeFromID(-1));
} }
@Test (expected = IllegalArgumentException.class)
public void invalidTileDirectionThrowsError() {
new Tile(TileType.TILE, Direction.NORTH_EAST);
}
@Test @Test
public void allTilesHaveUniqueId() { public void allTilesHaveUniqueId() {
/* This test is also done implicitly by the allTileTypesIDConversionToIDAndBack test, but that test may fail /* This test is also done implicitly by the allTileTypesIDConversionToIDAndBack test, but that test may fail

@ -1,5 +1,6 @@
package inf112.fiasko.roborally.element_properties; package inf112.fiasko.roborally.element_properties;
import inf112.fiasko.roborally.objects.Wall;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
@ -44,6 +45,11 @@ public class WallTypeTest {
assertNull(TileType.getTileTypeFromID(-1)); assertNull(TileType.getTileTypeFromID(-1));
} }
@Test (expected = IllegalArgumentException.class)
public void invalidWallDirectionThrowsError() {
new Wall(WallType.WALL_NORMAL, Direction.NORTH_EAST);
}
@Test @Test
public void allWallsHaveUniqueId() { public void allWallsHaveUniqueId() {
/* This test is also done implicitly by the allTileTypesIDConversionToIDAndBack test, but that test may fail /* This test is also done implicitly by the allTileTypesIDConversionToIDAndBack test, but that test may fail