From 8f845460cccd2ffbaa0bd3d30d2db9f8bbf20e5b Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 31 Jan 2024 20:51:39 +0100 Subject: [PATCH] Added test for isWithin Function in Vector2 --- src/test/java/pacmanTests/Vector2Test.java | 38 +++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/test/java/pacmanTests/Vector2Test.java b/src/test/java/pacmanTests/Vector2Test.java index e633dd0..2613f2f 100644 --- a/src/test/java/pacmanTests/Vector2Test.java +++ b/src/test/java/pacmanTests/Vector2Test.java @@ -45,7 +45,7 @@ class Vector2Test { // assert assertThat(expected).isEqualTo(result); } - + @Test void Vector2_clone_createsClone() { // arrange @@ -57,4 +57,40 @@ class Vector2Test { // assert assertThat(clone).isEqualTo(comparator); } + + @Test + void Vector2_isWithin_returnsTrueWhenWithin() { + // arrange + Vector2 area = new Vector2(30, 30); + Vector2 point = new Vector2(2, 8); + // act + boolean isWithin = point.isWithin(area); + boolean expectedWithin = true; + // assert + assertThat(isWithin).isEqualTo(expectedWithin); + } + + @Test + void Vector2_isWithin_returnsFalseWhenOutside() { + // arrange + Vector2 area = new Vector2(30, 30); + Vector2 point = new Vector2(53, 8); + // act + boolean isWithin = point.isWithin(area); + boolean expectedWithin = false; + // assert + assertThat(isWithin).isEqualTo(expectedWithin); + } + + @Test + void Vector2_isWithin_returnsFalseOnEqual() { + // arrange + Vector2 area = new Vector2(30, 30); + Vector2 point = new Vector2(30, 15); + // act + boolean isWithin = point.isWithin(area); + boolean expectedWithin = false; + // assert + assertThat(isWithin).isEqualTo(expectedWithin); + } }