Browse Source

Added Equals function to Vector2

remotes/origin/menu
fdai7012 12 months ago
committed by Julian
parent
commit
8a21b354f3
  1. 13
      src/main/java/pacmanGame/Vector2.java
  2. 36
      src/test/java/pacmanTests/Vector2Test.java

13
src/main/java/pacmanGame/Vector2.java

@ -8,4 +8,17 @@ public class Vector2 {
this.x = x; this.x = x;
this.y = y; 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;
}
} }

36
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);
}
}
Loading…
Cancel
Save