diff --git a/src/main/java/pacmanGame/Vector2.java b/src/main/java/pacmanGame/Vector2.java index 5f7811d..ba12fdd 100644 --- a/src/main/java/pacmanGame/Vector2.java +++ b/src/main/java/pacmanGame/Vector2.java @@ -8,4 +8,17 @@ public class Vector2 { this.x = x; this.y = y; } + + @Override + public boolean equals(Object o) { + + if (o == this) { + return true; + } + if (!(o instanceof Vector2)) { + return false; + } + Vector2 b = (Vector2) o; + return x == b.x && y == b.y; + } } diff --git a/src/test/java/pacmanTests/Vector2Test.java b/src/test/java/pacmanTests/Vector2Test.java new file mode 100644 index 0000000..5e57424 --- /dev/null +++ b/src/test/java/pacmanTests/Vector2Test.java @@ -0,0 +1,36 @@ +package pacmanTests; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +import pacmanGame.*; + + +class Vector2Test { + + @Test + void Vector2_sameValues_areEqual() { + // arrange + Vector2 a = new Vector2(2, 2); + Vector2 b = new Vector2(2, 2); + boolean expected = true; + // act + boolean result = a.equals(b); + // assert + assertThat(result).isEqualTo(expected); + } + + @Test + void Vector2_differentValues_areNotEqual() { + // arrange + Vector2 a = new Vector2(2, 2); + Vector2 b = new Vector2(2, 5); + boolean expected = false; + // act + boolean result = a.equals(b); + // assert + assertThat(result).isEqualTo(expected); + } +}