diff --git a/src/main/java/controller/GridController.java b/src/main/java/controller/GridController.java index 49f0021ccfed5b2755af9607acfc2cf280c3250d..db1ece2cacdf6e53408c20c1275d87b716142872 100644 --- a/src/main/java/controller/GridController.java +++ b/src/main/java/controller/GridController.java @@ -2,26 +2,30 @@ package controller; import javafx.fxml.FXML; import javafx.scene.paint.Color; import model.*; -import view.GridTileCanvas; +import view.GridCanvas; import java.util.List; import java.util.Random; public class GridController { + public static final Color COLOR_FIRST_NAME_ONE = Color.RED; + public static final Color COLOR_LAST_NAME_ONE = Color.BLUE; + public static final Color COLOR_FIRST_NAME_TWO = Color.GREEN; + public static final Color COLOR_LAST_NAME_TWO = Color.YELLOW; Random random = new Random(); @FXML - public GridTileCanvas gridTileCanvas; + public GridCanvas gridCanvas; public void initialize() { clearGrid(); } public void fillGrid(TileGenerator tileGenerator) { - gridTileCanvas.fillGrid(tileGenerator); + gridCanvas.fillGrid(tileGenerator); } public void drawGrid() { - gridTileCanvas.update(); + gridCanvas.update(); } public void clearGrid(){ @@ -40,42 +44,61 @@ public class GridController { } @FXML - public void updateRedUniformTile(){ - updateGrid(new UniformTileGenerator(new InternalSide(Color.RED))); + public void updateFirstNameOneUniformTile(){ + updateGrid(new UniformTileGenerator(COLOR_FIRST_NAME_ONE)); + } + + @FXML + public void updateFirstNameTwoUniformTile() { + updateGrid(new UniformTileGenerator(COLOR_FIRST_NAME_TWO)); + } + + @FXML + public void updateLastNameOneUniformTile(){ + updateGrid(new UniformTileGenerator(COLOR_LAST_NAME_ONE)); + } + + @FXML + public void updateLastNameTwoUniformTile() { + updateGrid(new UniformTileGenerator(COLOR_LAST_NAME_TWO)); } @FXML public void updateRandomColorUniformTile(){ - updateGrid(new RandomUniformTileGenerator(List.of(Color.RED, Color.BLUE, Color.BLACK), random)); + updateGrid(new RandomUniformTileGenerator(List.of(COLOR_FIRST_NAME_ONE, COLOR_LAST_NAME_ONE, COLOR_LAST_NAME_TWO), random)); } @FXML public void updateRandomTruchetTile(){ - updateGrid(new RandomRotatedTruchetTileGenerator(Color.RED, Color.BLUE, random)); + updateGrid(new RandomRotatedTruchetTileGenerator(COLOR_FIRST_NAME_ONE, COLOR_LAST_NAME_ONE, random)); } + @FXML public void updateRandomWangTile() { - updateGrid(new RandomWangTileGenerator(List.of(Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW), random)); + updateGrid(new RandomWangTileGenerator(List.of(COLOR_FIRST_NAME_ONE, COLOR_LAST_NAME_ONE, COLOR_FIRST_NAME_TWO, COLOR_LAST_NAME_TWO), random)); } + @FXML public void updateRandomConstrainedWangTile() { - updateGrid(new RandomConstrainedWangTileGenerator(List.of(Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW), random)); + updateGrid(new RandomConstrainedWangTileGenerator(List.of(COLOR_FIRST_NAME_ONE, COLOR_LAST_NAME_ONE, COLOR_FIRST_NAME_TWO, Color.YELLOW), random)); } + @FXML public void updateConstrainedTruchetTile() { - updateGrid(new ConstrainedRotatedTruchetTileGenerator(Color.RED, Color.BLUE, random)); + updateGrid(new ConstrainedRotatedTruchetTileGenerator(COLOR_FIRST_NAME_ONE, COLOR_LAST_NAME_ONE, random)); } + @FXML public void updateRandomWangTileSet() { updateGrid(new RandomTileSetGenerator(List.of( - new WangTile(new Side[]{new InternalSide(Color.RED), new InternalSide(Color.BLUE), new InternalSide(Color.RED), new InternalSide(Color.RED)}), - new WangTile(new Side[]{new InternalSide(Color.RED), new InternalSide(Color.RED), new InternalSide(Color.BLUE), new InternalSide(Color.BLUE)}), - new WangTile(new Side[]{new InternalSide(Color.RED), new InternalSide(Color.GREEN), new InternalSide(Color.GREEN), new InternalSide(Color.GREEN)}), - new WangTile(new Side[]{new InternalSide(Color.BLUE), new InternalSide(Color.GREEN), new InternalSide(Color.RED), new InternalSide(Color.BLUE)}), - new WangTile(new Side[]{new InternalSide(Color.BLUE), new InternalSide(Color.BLUE), new InternalSide(Color.BLUE), new InternalSide(Color.RED)}), - new WangTile(new Side[]{new InternalSide(Color.BLUE), new InternalSide(Color.RED), new InternalSide(Color.GREEN), new InternalSide(Color.GREEN)}), - new WangTile(new Side[]{new InternalSide(Color.GREEN), new InternalSide(Color.GREEN), new InternalSide(Color.BLUE), new InternalSide(Color.GREEN)}), - new WangTile(new Side[]{new InternalSide(Color.GREEN), new InternalSide(Color.RED), new InternalSide(Color.RED), new InternalSide(Color.RED)}), - new WangTile(new Side[]{new InternalSide(Color.GREEN), new InternalSide(Color.BLUE), new InternalSide(Color.GREEN), new InternalSide(Color.BLUE)})), random)); + new WangTile(new Side[]{new ColoredSide(COLOR_LAST_NAME_ONE), new ColoredSide(COLOR_FIRST_NAME_ONE), new ColoredSide(COLOR_FIRST_NAME_ONE), new ColoredSide(COLOR_FIRST_NAME_ONE)}), + new WangTile(new Side[]{new ColoredSide(COLOR_LAST_NAME_TWO), new ColoredSide(COLOR_FIRST_NAME_ONE), new ColoredSide(COLOR_FIRST_NAME_ONE), new ColoredSide(COLOR_FIRST_NAME_ONE)}), + new WangTile(new Side[]{new ColoredSide(COLOR_LAST_NAME_ONE), new ColoredSide(COLOR_FIRST_NAME_ONE), new ColoredSide(COLOR_LAST_NAME_ONE), new ColoredSide(COLOR_FIRST_NAME_TWO)}), + new WangTile(new Side[]{new ColoredSide(COLOR_LAST_NAME_TWO), new ColoredSide(COLOR_FIRST_NAME_ONE), new ColoredSide(COLOR_LAST_NAME_ONE), new ColoredSide(COLOR_FIRST_NAME_TWO)}), + new WangTile(new Side[]{new ColoredSide(COLOR_FIRST_NAME_ONE), new ColoredSide(COLOR_FIRST_NAME_TWO), new ColoredSide(COLOR_LAST_NAME_TWO), new ColoredSide(COLOR_FIRST_NAME_ONE)}), + new WangTile(new Side[]{new ColoredSide(COLOR_FIRST_NAME_TWO), new ColoredSide(COLOR_FIRST_NAME_TWO), new ColoredSide(COLOR_LAST_NAME_TWO), new ColoredSide(COLOR_FIRST_NAME_ONE)}), + new WangTile(new Side[]{new ColoredSide(COLOR_FIRST_NAME_ONE), new ColoredSide(COLOR_FIRST_NAME_TWO), new ColoredSide(COLOR_FIRST_NAME_TWO), new ColoredSide(COLOR_FIRST_NAME_TWO)}), + new WangTile(new Side[]{new ColoredSide(COLOR_FIRST_NAME_TWO), new ColoredSide(COLOR_FIRST_NAME_TWO), new ColoredSide(COLOR_FIRST_NAME_TWO), new ColoredSide(COLOR_FIRST_NAME_TWO)})), random)); + } } diff --git a/src/main/java/model/ArrayGrid.java b/src/main/java/model/ArrayGrid.java index 312392b61bc17bd2f2bf715221628f3e8e9a2981..9d74a0f144772691b1863023abb268e1aa4dc6e6 100644 --- a/src/main/java/model/ArrayGrid.java +++ b/src/main/java/model/ArrayGrid.java @@ -5,7 +5,6 @@ public class ArrayGrid implements Grid { private final int numberOfRows; private final int numberOfColumns; private final Square[][] squares; - private final Square outOfGridSquare = new ArraySquare(); /** * Creates a new {@code Grid} instance given the number of rows and columns. * @@ -43,7 +42,7 @@ public class ArrayGrid implements Grid { int rowNeighbor = row + direction.deltaRow; int columnNeighbor = column + direction.deltaColumn; Square neighboringSquare = - containsCoordinates(rowNeighbor, columnNeighbor) ? getSquare(rowNeighbor, columnNeighbor) : outOfGridSquare; + containsCoordinates(rowNeighbor, columnNeighbor) ? getSquare(rowNeighbor, columnNeighbor) : EmptySquare.EMPTY_SQUARE; getSquare(row, column).setNeighbor(neighboringSquare, direction); } } diff --git a/src/main/java/model/ArraySquare.java b/src/main/java/model/ArraySquare.java index b470781e5f86f9ad9cdb0d4965f20393e301722b..0027ae9c245852d2ebac224ac249079e3919db40 100644 --- a/src/main/java/model/ArraySquare.java +++ b/src/main/java/model/ArraySquare.java @@ -4,11 +4,7 @@ import java.util.ArrayList; import java.util.List; public class ArraySquare implements Square { - private static final Tile EMPTY_TILE = new UniformTile(EmptySide.EMPTY_SIDE); - private static final Square EMPTY_SQUARE = new ArraySquare(); - - private Tile tile = EMPTY_TILE; - + private Tile tile = EmptyTile.EMPTY_TILE; private final Square[] neighborhood = new Square[CardinalDirection.NUMBER_OF_DIRECTIONS]; public ArraySquare() { @@ -17,7 +13,7 @@ public class ArraySquare implements Square { private void setEmptyNeighborhood(){ for(CardinalDirection direction : CardinalDirection.values()) - setNeighbor(EMPTY_SQUARE, direction); + setNeighbor(EmptySquare.EMPTY_SQUARE, direction); } public Tile getTile(){ diff --git a/src/main/java/model/InternalSide.java b/src/main/java/model/ColoredSide.java similarity index 87% rename from src/main/java/model/InternalSide.java rename to src/main/java/model/ColoredSide.java index 11b1b7a318b060c6fcc3b42500a018b620353e48..9eed9feda3e501453633875314a10b3314979c8c 100644 --- a/src/main/java/model/InternalSide.java +++ b/src/main/java/model/ColoredSide.java @@ -5,10 +5,10 @@ import javafx.scene.paint.Color; import java.util.ArrayList; import java.util.List; -public class InternalSide implements Side { +public class ColoredSide implements Side { private final Color color; - public InternalSide(Color color) { + public ColoredSide(Color color) { this.color = color; } diff --git a/src/main/java/model/ConstrainedRotatedTruchetTileGenerator.java b/src/main/java/model/ConstrainedRotatedTruchetTileGenerator.java index f41c280b85d5c0c6c9b061dbc0c29cb320beb006..9f1739ea6b19be5d797dcd0ea419dbca757f70f4 100644 --- a/src/main/java/model/ConstrainedRotatedTruchetTileGenerator.java +++ b/src/main/java/model/ConstrainedRotatedTruchetTileGenerator.java @@ -11,7 +11,7 @@ public class ConstrainedRotatedTruchetTileGenerator implements TileGenerator{ private final List<Tile> rotatedTruchetTiles = new ArrayList<>(); private final Random randomGenerator; public ConstrainedRotatedTruchetTileGenerator(Color color1, Color color2, Random randomGenerator) { - Tile truchetTile = new TruchetTile(new InternalSide(color1), new InternalSide(color2)); + Tile truchetTile = new TruchetTile(new ColoredSide(color1), new ColoredSide(color2)); for(Rotation rotation : Rotation.values()){ rotatedTruchetTiles.add(new RotatedTile(truchetTile, rotation)); } diff --git a/src/main/java/model/EmptyGrid.java b/src/main/java/model/EmptyGrid.java index 98b69c11ce4907347f6ec7ad5c0e540e0286091d..7a3d47a9993f01ae370afaf197d4b5d1ae1ce8b6 100644 --- a/src/main/java/model/EmptyGrid.java +++ b/src/main/java/model/EmptyGrid.java @@ -5,7 +5,6 @@ import java.util.Iterator; public class EmptyGrid implements Grid{ private final int numberOfRows; private final int numberOfColumns; - private static final Square EMPTY_SQUARE = new ArraySquare(); public EmptyGrid(int numberOfRows, int numberOfColumns) { this.numberOfRows = numberOfRows; @@ -14,7 +13,7 @@ public class EmptyGrid implements Grid{ @Override public Square getSquare(int rowIndex, int columnIndex) { - return EMPTY_SQUARE; + return EmptySquare.EMPTY_SQUARE; } @Override @@ -41,7 +40,7 @@ public class EmptyGrid implements Grid{ @Override public Square next() { - return EMPTY_SQUARE; + return EmptySquare.EMPTY_SQUARE; } }; } diff --git a/src/main/java/model/EmptySquare.java b/src/main/java/model/EmptySquare.java new file mode 100644 index 0000000000000000000000000000000000000000..97b91b422780205f5ade7140353b5a6d0b08c8c2 --- /dev/null +++ b/src/main/java/model/EmptySquare.java @@ -0,0 +1,40 @@ +package model; + +import java.util.List; + +public class EmptySquare implements Square{ + public static final Square EMPTY_SQUARE = new EmptySquare(); + + private EmptySquare() {} + + @Override + public boolean accept(Tile tile) { + return true; + } + + @Override + public void put(Tile tile) {} + + @Override + public Tile getTile() { + return EmptyTile.EMPTY_TILE; + } + + @Override + public List<Tile> compatibleTiles(List<Tile> tiles) { + return tiles; + } + + @Override + public List<Side> compatibleSides(List<Side> sides, CardinalDirection direction) { + return sides; + } + + @Override + public Square getNeighbor(CardinalDirection direction) { + return EMPTY_SQUARE; + } + + @Override + public void setNeighbor(Square neighbor, CardinalDirection direction) {} +} diff --git a/src/main/java/model/EmptyTile.java b/src/main/java/model/EmptyTile.java new file mode 100644 index 0000000000000000000000000000000000000000..605c9deae439591c4390382f4fdc1ff79f9f5b1e --- /dev/null +++ b/src/main/java/model/EmptyTile.java @@ -0,0 +1,12 @@ +package model; + +public class EmptyTile implements Tile{ + public static Tile EMPTY_TILE = new EmptyTile(); + + private EmptyTile(){} + + @Override + public Side side(CardinalDirection direction) { + return EmptySide.EMPTY_SIDE; + } +} diff --git a/src/main/java/model/EmptyTileGenerator.java b/src/main/java/model/EmptyTileGenerator.java index 97f281a9500b2048bc87f1a7456c049507864374..cc539aa765a6366d020511f82af952578a4ba837 100644 --- a/src/main/java/model/EmptyTileGenerator.java +++ b/src/main/java/model/EmptyTileGenerator.java @@ -1,10 +1,8 @@ package model; public class EmptyTileGenerator implements TileGenerator{ - private Tile emptyTile = new UniformTile(EmptySide.EMPTY_SIDE); - @Override public Tile nextTile(Square square) { - return emptyTile; + return EmptyTile.EMPTY_TILE; } } diff --git a/src/main/java/model/RandomConstrainedWangTileGenerator.java b/src/main/java/model/RandomConstrainedWangTileGenerator.java index 72dce8fe20cdbc8743f97a3e07ec828a6d1397b6..21ed1d624f5f53a87e60a5f4b3feca5e635101c7 100644 --- a/src/main/java/model/RandomConstrainedWangTileGenerator.java +++ b/src/main/java/model/RandomConstrainedWangTileGenerator.java @@ -13,7 +13,7 @@ public class RandomConstrainedWangTileGenerator implements TileGenerator { public RandomConstrainedWangTileGenerator(List<Color> colors, Random randomGenerator) { for(Color color : colors) - this.availableSides.add(new InternalSide(color)); + this.availableSides.add(new ColoredSide(color)); this.randomGenerator = randomGenerator; } diff --git a/src/main/java/model/RandomRotatedTruchetTileGenerator.java b/src/main/java/model/RandomRotatedTruchetTileGenerator.java index 69b8a533fa6cfc5163fc5a7e6295003f39da0423..13e7d9855a63c309b0a046fd2b8577755b9f05fe 100644 --- a/src/main/java/model/RandomRotatedTruchetTileGenerator.java +++ b/src/main/java/model/RandomRotatedTruchetTileGenerator.java @@ -11,7 +11,7 @@ public class RandomRotatedTruchetTileGenerator implements TileGenerator{ public RandomRotatedTruchetTileGenerator(Color color1, Color color2, Random randomGenerator) { this.randomGenerator = randomGenerator; - this.truchetTile = new TruchetTile(new InternalSide(color1), new InternalSide(color2)); + this.truchetTile = new TruchetTile(new ColoredSide(color1), new ColoredSide(color2)); } @Override diff --git a/src/main/java/model/RandomUniformTileGenerator.java b/src/main/java/model/RandomUniformTileGenerator.java index 636116aaf30fda616076cbf2daf853a290076342..51bab92c2ddd1d341a81c4af95ff75fd2ba69de6 100644 --- a/src/main/java/model/RandomUniformTileGenerator.java +++ b/src/main/java/model/RandomUniformTileGenerator.java @@ -8,17 +8,17 @@ import java.util.List; import java.util.Random; public class RandomUniformTileGenerator implements TileGenerator{ - private final List<Side> colors = new ArrayList<>(); + private final List<Tile> tiles = new ArrayList<>(); private final Random randomGenerator; public RandomUniformTileGenerator(List<Color> colors, Random randomGenerator) { for(Color color : colors) - this.colors.add(new InternalSide(color)); + this.tiles.add(new UniformTile(new ColoredSide(color))); this.randomGenerator = randomGenerator; } @Override public Tile nextTile(Square square) { - return new UniformTile(RandomUtil.randomElement(colors, randomGenerator)); + return RandomUtil.randomElement(tiles, randomGenerator); } } diff --git a/src/main/java/model/RandomWangTileGenerator.java b/src/main/java/model/RandomWangTileGenerator.java index 7f0e8772ae4249ccb65e87f0948826466ab7b7f4..80b30b3e17ac093ff0c31f2ea4cc8a33cc83abe5 100644 --- a/src/main/java/model/RandomWangTileGenerator.java +++ b/src/main/java/model/RandomWangTileGenerator.java @@ -13,7 +13,7 @@ public class RandomWangTileGenerator implements TileGenerator{ public RandomWangTileGenerator(List<Color> colors, Random randomGenerator) { for(Color color : colors) - this.availableSides.add(new InternalSide(color)); + this.availableSides.add(new ColoredSide(color)); this.randomGenerator = randomGenerator; } diff --git a/src/main/java/model/UniformTileGenerator.java b/src/main/java/model/UniformTileGenerator.java index 6b3f13721707dc4fe0cb2961fd3eb5a46ef8651b..4dbd3ad0606cb44102e6f0c274b5ffc854951e88 100644 --- a/src/main/java/model/UniformTileGenerator.java +++ b/src/main/java/model/UniformTileGenerator.java @@ -1,10 +1,12 @@ package model; +import javafx.scene.paint.Color; + public class UniformTileGenerator implements TileGenerator{ private final Tile tile; - public UniformTileGenerator(Side side) { - tile = new UniformTile(side); + public UniformTileGenerator(Color color) { + tile = new UniformTile(new ColoredSide(color)); } @Override diff --git a/src/main/java/view/GridTileCanvas.java b/src/main/java/view/GridCanvas.java similarity index 86% rename from src/main/java/view/GridTileCanvas.java rename to src/main/java/view/GridCanvas.java index a1fdf23f572e8c4dfef4925817674a6415d2d44f..6d77b27b76a13fc531ca3ab3672bd754191f932a 100644 --- a/src/main/java/view/GridTileCanvas.java +++ b/src/main/java/view/GridCanvas.java @@ -7,7 +7,7 @@ import javafx.scene.paint.Color; import model.*; import java.util.List; -public class GridTileCanvas extends Canvas { +public class GridCanvas extends Canvas { public final double tileWidth; private final double tileHeight; @@ -16,10 +16,10 @@ public class GridTileCanvas extends Canvas { private final Grid tileGrid; private final GraphicsContext graphicsContext; - public GridTileCanvas(@NamedArg("tileWidth") Double tileWidth, - @NamedArg("tileHeight") Double tileHeight, - @NamedArg("numberOfColumns") Integer numberOfColumns, - @NamedArg("numberOfRows") Integer numberOfRows) { + public GridCanvas(@NamedArg("tileWidth") Double tileWidth, + @NamedArg("tileHeight") Double tileHeight, + @NamedArg("numberOfColumns") Integer numberOfColumns, + @NamedArg("numberOfRows") Integer numberOfRows) { this.tileWidth = tileWidth; this.tileHeight = tileHeight; this.numberOfColumns = numberOfColumns; diff --git a/src/main/resources/view/GridCanvas.fxml b/src/main/resources/view/GridCanvas.fxml index 009d4c0ccc74ec5032a327383e6c7e4792c14ac9..538f58cf07a55c3538c4fbbe187d4afbf26e7712 100644 --- a/src/main/resources/view/GridCanvas.fxml +++ b/src/main/resources/view/GridCanvas.fxml @@ -3,7 +3,7 @@ <?import javafx.scene.layout.*?> -<?import view.GridTileCanvas?> +<?import view.GridCanvas?> <?import java.lang.Double?> <?import java.lang.Integer?> <?import javafx.scene.control.MenuBar?> @@ -17,7 +17,13 @@ <Menu mnemonicParsing="false" text="Uniform Tiles"> <MenuItem mnemonicParsing="false" onAction="#updateEmptyUniformTile" text="Empty"> </MenuItem> - <MenuItem mnemonicParsing="false" onAction="#updateRedUniformTile" text="Red"> + <MenuItem mnemonicParsing="false" onAction="#updateFirstNameOneUniformTile" text="Firstname 1"> + </MenuItem> + <MenuItem mnemonicParsing="false" onAction="#updateLastNameOneUniformTile" text="Lastname 1"> + </MenuItem> + <MenuItem mnemonicParsing="false" onAction="#updateFirstNameTwoUniformTile" text="Firstname 2"> + </MenuItem> + <MenuItem mnemonicParsing="false" onAction="#updateLastNameTwoUniformTile" text="Lastname 2"> </MenuItem> <MenuItem mnemonicParsing="false" onAction="#updateRandomColorUniformTile" text="Random color"> </MenuItem> @@ -37,10 +43,10 @@ </MenuItem> </Menu> </MenuBar> - <GridTileCanvas AnchorPane.topAnchor="40." - xmlns="http://javafx.com/javafx" - xmlns:fx="http://javafx.com/fxml" - fx:id="gridTileCanvas"> + <GridCanvas AnchorPane.topAnchor="40." + xmlns="http://javafx.com/javafx" + xmlns:fx="http://javafx.com/fxml" + fx:id="gridCanvas"> <tileWidth> <Double fx:value="20"/> </tileWidth> @@ -53,5 +59,5 @@ <numberOfRows> <Integer fx:value="50"/> </numberOfRows> - </GridTileCanvas> + </GridCanvas> </AnchorPane> \ No newline at end of file diff --git a/src/test/java/model/EmptyGridTest.java b/src/test/java/model/EmptyGridTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c28e3088db24fca6e91d2cee5842c48811d231c7 --- /dev/null +++ b/src/test/java/model/EmptyGridTest.java @@ -0,0 +1,27 @@ +package model; + +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + +public class EmptyGridTest { + @Test + void testGetNumberOfRows(){ + assertThat(new EmptyGrid(10,20).getNumberOfRows()).isEqualTo(10); + assertThat(new EmptyGrid(100,200).getNumberOfRows()).isEqualTo(100); + } + + @Test + void testGetNumberOfColumns(){ + assertThat(new EmptyGrid(10,20).getNumberOfColumns()).isEqualTo(20); + assertThat(new EmptyGrid(100,200).getNumberOfColumns()).isEqualTo(200); + } + + @Test + void testGetSquare(){ + Grid emptyGrid = new EmptyGrid(100,20); + assertThat(emptyGrid.getSquare(0, 0)).isEqualTo(EmptySquare.EMPTY_SQUARE); + assertThat(emptyGrid.getSquare(10, 9)).isEqualTo(EmptySquare.EMPTY_SQUARE); + assertThat(emptyGrid.getSquare(99, 19)).isEqualTo(EmptySquare.EMPTY_SQUARE); + } + +} diff --git a/src/test/java/model/EmptySideTest.java b/src/test/java/model/EmptySideTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f3b676fad5c60d91af6704b2dc48cfe4f45aaa9e --- /dev/null +++ b/src/test/java/model/EmptySideTest.java @@ -0,0 +1,25 @@ +package model; + +import javafx.scene.paint.Color; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +public class EmptySideTest { + @Test + void testCompatibleSides(){ + List<Side> sides = List.of(EmptySide.EMPTY_SIDE); + assertThat(EmptySide.EMPTY_SIDE.compatibleSides(sides)).containsExactly(EmptySide.EMPTY_SIDE); + } + + @Test + void testColor(){ + assertThat(EmptySide.EMPTY_SIDE.color()).isEqualTo(Color.WHITE); + } + @Test + void testAccept(){ + assertThat(EmptySide.EMPTY_SIDE.accept(EmptySide.EMPTY_SIDE)).isTrue(); + } + +} diff --git a/src/test/java/model/EmptySquareTest.java b/src/test/java/model/EmptySquareTest.java new file mode 100644 index 0000000000000000000000000000000000000000..085ac7e17ef3adcee027232aaabdd353dda676da --- /dev/null +++ b/src/test/java/model/EmptySquareTest.java @@ -0,0 +1,35 @@ +package model; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class EmptySquareTest { + @Test + void testAccept(){ + assertThat(EmptySquare.EMPTY_SQUARE.accept(EmptyTile.EMPTY_TILE)).isTrue(); + } + + @Test + void testGetTile(){ + assertThat(EmptySquare.EMPTY_SQUARE.getTile()).isEqualTo(EmptyTile.EMPTY_TILE); + } + + @Test + void testCompatibleTiles(){ + assertThat(EmptySquare.EMPTY_SQUARE.compatibleTiles(List.of(EmptyTile.EMPTY_TILE))).containsExactly(EmptyTile.EMPTY_TILE); + } + + @Test + void testCompatibleSides(){ + assertThat(EmptySquare.EMPTY_SQUARE.compatibleSides(List.of(EmptySide.EMPTY_SIDE), CardinalDirection.NORTH)).containsExactly(EmptySide.EMPTY_SIDE); + } + + @Test + void testGetNeighbor(){ + assertThat(EmptySquare.EMPTY_SQUARE.getNeighbor(CardinalDirection.NORTH)).isEqualTo(EmptySquare.EMPTY_SQUARE); + } + +} diff --git a/src/test/java/model/EmptyTileGeneratorTest.java b/src/test/java/model/EmptyTileGeneratorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..7147c514d636d6085e1733f306bbb2c53d0c7625 --- /dev/null +++ b/src/test/java/model/EmptyTileGeneratorTest.java @@ -0,0 +1,13 @@ +package model; + +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + +public class EmptyTileGeneratorTest { + @Test + void testNextTile(){ + TileGenerator tileGenerator = new EmptyTileGenerator(); + assertThat(tileGenerator.nextTile(EmptySquare.EMPTY_SQUARE)).isEqualTo(EmptyTile.EMPTY_TILE); + assertThat(tileGenerator.nextTile(EmptySquare.EMPTY_SQUARE)).isEqualTo(EmptyTile.EMPTY_TILE); + } +} diff --git a/src/test/java/model/EmptyTileTest.java b/src/test/java/model/EmptyTileTest.java new file mode 100644 index 0000000000000000000000000000000000000000..6724c3031856b36977b190bdec58cb163d247ba6 --- /dev/null +++ b/src/test/java/model/EmptyTileTest.java @@ -0,0 +1,15 @@ +package model; + +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + +public class EmptyTileTest { + + @Test + void testSide(){ + assertThat(EmptyTile.EMPTY_TILE.side(CardinalDirection.NORTH)).isEqualTo(EmptySide.EMPTY_SIDE); + assertThat(EmptyTile.EMPTY_TILE.side(CardinalDirection.SOUTH)).isEqualTo(EmptySide.EMPTY_SIDE); + assertThat(EmptyTile.EMPTY_TILE.side(CardinalDirection.EAST)).isEqualTo(EmptySide.EMPTY_SIDE); + assertThat(EmptyTile.EMPTY_TILE.side(CardinalDirection.WEST)).isEqualTo(EmptySide.EMPTY_SIDE); + } +} diff --git a/src/test/java/model/WangTileTest.java b/src/test/java/model/WangTileTest.java index 422b9288c5412971b095bc7bf03f570c552f0c54..c199e3d0033898e40941f4bd92a17132e4605f68 100644 --- a/src/test/java/model/WangTileTest.java +++ b/src/test/java/model/WangTileTest.java @@ -8,8 +8,8 @@ public class WangTileTest { @Test void testGetColor(){ - WangTile tile = new WangTile(new Side[]{new InternalSide(Color.BLACK), new InternalSide(Color.BLUE), - new InternalSide(Color.WHITE), new InternalSide(Color.BLUE)}); + WangTile tile = new WangTile(new Side[]{new ColoredSide(Color.BLACK), new ColoredSide(Color.BLUE), + new ColoredSide(Color.WHITE), new ColoredSide(Color.BLUE)}); assertThat(tile.side(CardinalDirection.NORTH).color()).isEqualTo(Color.BLACK); assertThat(tile.side(CardinalDirection.EAST).color()).isEqualTo(Color.BLUE); assertThat(tile.side(CardinalDirection.SOUTH).color()).isEqualTo(Color.WHITE);