Add tests and add validity check to labyrinth dimensions.

This commit is contained in:
Manuel Friedli 2020-10-06 00:48:40 +02:00
parent 15f93310e4
commit ad0759b36f
3 changed files with 192 additions and 6 deletions

View file

@ -2,21 +2,22 @@ package ch.fritteli.labyrinth.model;
public enum Direction {
TOP,
RIGHT,
BOTTOM,
LEFT,
RIGHT;
LEFT;
public Direction invert() {
switch (this) {
case TOP:
return BOTTOM;
case LEFT:
return RIGHT;
case RIGHT:
return LEFT;
case BOTTOM:
return TOP;
case LEFT:
return RIGHT;
default:
throw new IllegalStateException("Programming error: Not all enum values covered in enum Direction#invert()!");
}
throw new IllegalStateException("Programming error: Not all enum values covered in enum Direction#invert()!");
}
}

View file

@ -28,10 +28,13 @@ public class Labyrinth {
}
public Labyrinth(final int width, final int height, final long randomSeed) {
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("widht and height must be >=1");
}
this.width = width;
this.height = height;
this.randomSeed = randomSeed;
this.random = new Random(this.randomSeed);
this.random = new Random(randomSeed);
this.field = new Tile[width][height];
this.start = new Position(0, 0);
this.end = new Position(this.width - 1, this.height - 1);