Browse Source

Added Clone function to Vector 2

remotes/origin/menu
fdai2751 12 months ago
parent
commit
6ff7bb5e77
  1. 4
      src/main/java/pacmanGame/Vector2.java
  2. 12
      src/test/java/pacmanTests/Vector2Test.java

4
src/main/java/pacmanGame/Vector2.java

@ -28,4 +28,8 @@ public class Vector2 {
y + b.y y + b.y
); );
} }
public Vector2 Clone() {
return new Vector2(this.x, this.y);
}
} }

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

@ -45,4 +45,16 @@ class Vector2Test {
// assert // assert
assertThat(expected).isEqualTo(result); 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);
}
} }
Loading…
Cancel
Save