From 6ff7bb5e77dc69ccf9812b56f0cd0ab23cda78d4 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Tue, 23 Jan 2024 16:07:45 +0100 Subject: [PATCH] Added Clone function to Vector 2 --- src/main/java/pacmanGame/Vector2.java | 4 ++++ src/test/java/pacmanTests/Vector2Test.java | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/pacmanGame/Vector2.java b/src/main/java/pacmanGame/Vector2.java index 2a27169..d2e95ef 100644 --- a/src/main/java/pacmanGame/Vector2.java +++ b/src/main/java/pacmanGame/Vector2.java @@ -28,4 +28,8 @@ public class Vector2 { y + b.y ); } + + public Vector2 Clone() { + return new Vector2(this.x, this.y); + } } diff --git a/src/test/java/pacmanTests/Vector2Test.java b/src/test/java/pacmanTests/Vector2Test.java index ab5e465..e633dd0 100644 --- a/src/test/java/pacmanTests/Vector2Test.java +++ b/src/test/java/pacmanTests/Vector2Test.java @@ -45,4 +45,16 @@ class Vector2Test { // assert assertThat(expected).isEqualTo(result); } + + @Test + void Vector2_clone_createsClone() { + // arrange + Vector2 original = new Vector2(1, 8); + Vector2 comparator = new Vector2(1, 8); + // act + Vector2 clone = original.Clone(); + original = new Vector2(11, 12); + // assert + assertThat(clone).isEqualTo(comparator); + } }