From 9a91d961914e301a68ddaf1dfaf3a0c7705d11d4 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 17 Jan 2024 16:24:37 +0100 Subject: [PATCH] Added Add function to Vector2 --- src/main/java/pacmanGame/Vector2.java | 7 +++++++ src/test/java/pacmanTests/Vector2Test.java | 12 ++++++++++++ 2 files changed, 19 insertions(+) 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); + } }