Browse Source

Added Add function to Vector2

remotes/origin/menu
fdai7012 11 months ago
committed by Julian
parent
commit
9a91d96191
  1. 7
      src/main/java/pacmanGame/Vector2.java
  2. 12
      src/test/java/pacmanTests/Vector2Test.java

7
src/main/java/pacmanGame/Vector2.java

@ -21,4 +21,11 @@ public class Vector2 {
Vector2 b = (Vector2) o;
return x == b.x && y == b.y;
}
public Vector2 Add(Vector2 b) {
return new Vector2(
x + b.x,
y + b.y
);
}
}

12
src/test/java/pacmanTests/Vector2Test.java

@ -33,4 +33,16 @@ class Vector2Test {
// assert
assertThat(result).isEqualTo(expected);
}
@Test
void Vector2_addedValues_addUp() {
// arrange
Vector2 a = new Vector2(1, 8);
Vector2 b = new Vector2(3, -5);
Vector2 expected = new Vector2(4, 3);
// act
Vector2 result = a.Add(b);
// assert
assertThat(expected).isEqualTo(result);
}
}
Loading…
Cancel
Save