diff --git a/src/main/java/com/github/hanyaeger/core/entities/motion/MotionApplier.java b/src/main/java/com/github/hanyaeger/core/entities/motion/MotionApplier.java index 14d5b9ade..1457280b8 100644 --- a/src/main/java/com/github/hanyaeger/core/entities/motion/MotionApplier.java +++ b/src/main/java/com/github/hanyaeger/core/entities/motion/MotionApplier.java @@ -67,14 +67,14 @@ public double getSpeedInDirection(final Direction direction) { @Override public double getSpeedInDirection(final double direction) { var calculatedSpeed = 0D; - if (Double.compare(getDirection(), direction) != 0) { - final var normalizedVector = createVector(1, direction); - final var dotProduct = normalizedVector.dotProduct(motion); - if (dotProduct > 0) { - calculatedSpeed = calculateDenormalizedVector(normalizedVector, motion).magnitude(); - } + final var normalizedVector = createVector(1, direction); + final var dotProduct = normalizedVector.dotProduct(motion); + + if (dotProduct > 0) { + calculatedSpeed = calculateDenormalizedVector(normalizedVector, motion).magnitude(); } + return calculatedSpeed; } diff --git a/src/test/java/com/github/hanyaeger/core/entities/motion/MotionApplierTest.java b/src/test/java/com/github/hanyaeger/core/entities/motion/MotionApplierTest.java index e16469acd..b29087f0c 100644 --- a/src/test/java/com/github/hanyaeger/core/entities/motion/MotionApplierTest.java +++ b/src/test/java/com/github/hanyaeger/core/entities/motion/MotionApplierTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import static org.junit.jupiter.api.Assertions.*; @@ -743,6 +745,20 @@ void nullifySpeedInZeroDirectionDoesNotResultInNaNTest() { @Nested class GetSpeedInDirectionTests { + @ParameterizedTest + @EnumSource(Direction.class) + void getSpeedInExactDirectionGivesSpeedTest(Direction direction){ + // Arrange + var speed = 3.7; + + // Act + sut.setMotion(speed, direction); + var speedInDirection = sut.getSpeedInDirection(direction); + + // Assert + assertEquals(3.7, speedInDirection, DELTA); + } + @Test void getSpeedInOppositeDirectionGives0Test() { // Arrange