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

Added tests for ColoredSide

parent 96cce2e3
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import javafx.scene.paint.Color; ...@@ -4,6 +4,7 @@ import javafx.scene.paint.Color;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
public class ColoredSide implements Side { public class ColoredSide implements Side {
private final Color color; private final Color color;
...@@ -32,4 +33,24 @@ public class ColoredSide implements Side { ...@@ -32,4 +33,24 @@ public class ColoredSide implements Side {
public Color color() { public Color color() {
return color; return color;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ColoredSide that = (ColoredSide) o;
return Objects.equals(color, that.color);
}
@Override
public int hashCode() {
return Objects.hash(color);
}
@Override
public String toString() {
return "ColoredSide{" +
"color=" + color +
'}';
}
} }
package model; package model;
import java.util.Objects;
public class UniformTile implements Tile{ public class UniformTile implements Tile{
private final Side side; private final Side side;
...@@ -11,4 +13,17 @@ public class UniformTile implements Tile{ ...@@ -11,4 +13,17 @@ public class UniformTile implements Tile{
public Side side(CardinalDirection direction) { public Side side(CardinalDirection direction) {
return side; return side;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UniformTile that = (UniformTile) o;
return Objects.equals(side, that.side);
}
@Override
public int hashCode() {
return side != null ? side.hashCode() : 0;
}
} }
package model;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class ColoredSideTest {
Side redSide;
Side blueSide;
Side redSide2;
@BeforeEach
void initializeSides(){
redSide = new ColoredSide(Color.RED);
blueSide = new ColoredSide(Color.BLUE);
redSide2 = new ColoredSide(Color.RED);
}
@Test
void testColor(){
assertThat(redSide.color()).isEqualTo(Color.RED);
assertThat(blueSide.color()).isEqualTo(Color.BLUE);
}
@Test
void testEquals(){
assertThat(redSide2).isEqualTo(redSide2);
assertThat(redSide).isEqualTo(redSide2);
assertThat(redSide).isNotEqualTo(blueSide);
}
@Test
void testAccept(){
assertThat(blueSide.accept(blueSide)).isTrue();
assertThat(blueSide.accept(redSide2)).isFalse();
assertThat(redSide.accept(redSide2)).isTrue();
}
@Test
void testCompatibleSides(){
List<Side> sides = List.of(redSide, blueSide, redSide2);
assertThat(blueSide.compatibleSides(sides))
.containsExactly(blueSide)
.hasSize(1)
.doesNotContain(redSide);
assertThat(redSide.compatibleSides(sides))
.contains(redSide, redSide2)
.hasSize(2)
.doesNotContain(blueSide);
assertThat(sides).containsExactly(redSide, blueSide, redSide2);
}
@Test
void testToString(){
assertThat(redSide.toString()).isEqualTo("ColoredSide{color=0xff0000ff}");
assertThat(blueSide.toString()).isEqualTo("ColoredSide{color=0x0000ffff}");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment