Skip to content
Snippets Groups Projects
Commit 35856494 authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

Added tests for RandomRotatedTruchetTileGenerator

parent f3679cc1
No related branches found
No related tags found
No related merge requests found
package model; package model;
import java.util.Objects;
public class RotatedTile implements Tile { public class RotatedTile implements Tile {
private final Tile tile; private final Tile tile;
private final Rotation rotation; private final Rotation rotation;
...@@ -13,4 +15,17 @@ public class RotatedTile implements Tile { ...@@ -13,4 +15,17 @@ public class RotatedTile implements Tile {
public Side side(CardinalDirection direction) { public Side side(CardinalDirection direction) {
return tile.side(rotation.rotatedDirection(direction)); return tile.side(rotation.rotatedDirection(direction));
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RotatedTile that = (RotatedTile) o;
return Objects.equals(tile, that.tile) && rotation == that.rotation;
}
@Override
public int hashCode() {
return Objects.hash(tile, rotation);
}
} }
package model; package model;
import java.util.Objects;
public class TruchetTile implements Tile{ public class TruchetTile implements Tile{
private final Side northWestSide; private final Side northWestSide;
private final Side southEastSide; private final Side southEastSide;
...@@ -16,4 +18,17 @@ public class TruchetTile implements Tile{ ...@@ -16,4 +18,17 @@ public class TruchetTile implements Tile{
case NORTH, WEST -> northWestSide; case NORTH, WEST -> northWestSide;
}; };
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TruchetTile that = (TruchetTile) o;
return Objects.equals(northWestSide, that.northWestSide) && Objects.equals(southEastSide, that.southEastSide);
}
@Override
public int hashCode() {
return Objects.hash(northWestSide, southEastSide);
}
} }
package model;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.assertj.core.api.Assertions.assertThat;
public class RandomRotatedTruchetTileGeneratorTest {
@Test
void testNextTile(){
Side redSide = new ColoredSide(Color.RED);
Side blueSide = new ColoredSide(Color.BLUE);
Tile truchetTile = new TruchetTile(redSide, blueSide);
List<Tile> rotatedTiles = new ArrayList<>();
for(Rotation rotation : Rotation.values())
rotatedTiles.add(new RotatedTile(truchetTile, rotation));
TileGenerator tileGenerator = new RandomRotatedTruchetTileGenerator(Color.RED, Color.BLUE, new Random(0));
for(int index = 0; index < 10; index++)
assertThat(tileGenerator.nextTile(EmptySquare.EMPTY_SQUARE)).isIn(rotatedTiles);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment