diff --git a/src/main/java/pacmanGame/Vector2.java b/src/main/java/pacmanGame/Vector2.java index ba12fdd..2a27169 100644 --- a/src/main/java/pacmanGame/Vector2.java +++ b/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 + ); + } } diff --git a/src/test/java/pacmanTests/Vector2Test.java b/src/test/java/pacmanTests/Vector2Test.java index 5e57424..ab5e465 100644 --- a/src/test/java/pacmanTests/Vector2Test.java +++ b/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); + } }