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

first draft of the project

parent c2158773
No related branches found
No related tags found
No related merge requests found
package model;
public enum CardinalDirection {
NORTH, EAST, SOUTH, WEST;
}
package model;
import javafx.scene.paint.Color;
import java.util.Arrays;
import java.util.HashMap;
public class Tile {
private static final int NUMBER_OF_SIDES = 4;
private final Color colors[] = new Color[NUMBER_OF_SIDES];
public Tile(Color[] colors) {
if(colors.length != NUMBER_OF_SIDES)
throw new IllegalArgumentException("A tile is defined by " + NUMBER_OF_SIDES
+ "and not" + colors.length + "sides.");
for(int index = 0; index < NUMBER_OF_SIDES; index++)
this.colors[index] = colors[index];
}
public Color getColor(CardinalDirection direction){
return colors[direction.ordinal()];
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tile tile = (Tile) o;
return Arrays.equals(colors, tile.colors);
}
@Override
public int hashCode() {
return Arrays.hashCode(colors);
}
}
package model;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class TileTest {
@Test
void testGetColor(){
Tile tile = new Tile(new Color[]{Color.BLACK, Color.BLUE, Color.WHITE, Color.BLUE});
assertThat(tile.getColor(CardinalDirection.NORTH)).isEqualTo(Color.BLACK);
assertThat(tile.getColor(CardinalDirection.EAST)).isEqualTo(Color.BLUE);
assertThat(tile.getColor(CardinalDirection.SOUTH)).isEqualTo(Color.WHITE);
assertThat(tile.getColor(CardinalDirection.WEST)).isEqualTo(Color.BLUE);
}
@Test
void testEquals(){
Color[] colors1 = new Color[]{Color.BLACK, Color.BLUE, Color.WHITE, Color.BLUE};
Color[] colors2 = new Color[]{Color.BLACK, Color.BLUE, Color.WHITE, Color.WHITE};
Tile tile1 = new Tile(colors1);
Tile tile2 = new Tile(colors1);
Tile tile3 = new Tile(colors2);
assertThat(tile1)
.isEqualTo(tile1)
.isEqualTo(tile2)
.isNotEqualTo(tile3);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment