From 008404ce6c24673dff57b73fafbde2c85fcb6ab5 Mon Sep 17 00:00:00 2001 From: Dan Bryce Date: Wed, 1 Jan 2020 18:56:50 +0000 Subject: [PATCH] Fix failing unit tests --- .../game/tiles/LeftCeilingSlopeTest.java | 10 +++--- test/engine/game/tiles/LeftSlopeTest.java | 36 ++++++++++--------- test/engine/game/tiles/RightSlopeTest.java | 24 +++++++------ 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/test/engine/game/tiles/LeftCeilingSlopeTest.java b/test/engine/game/tiles/LeftCeilingSlopeTest.java index 2b78467..3b77d89 100644 --- a/test/engine/game/tiles/LeftCeilingSlopeTest.java +++ b/test/engine/game/tiles/LeftCeilingSlopeTest.java @@ -133,7 +133,7 @@ public void resolveCollisions_CollideWhenIntersectingTileAboveSlope() { * GIVEN: * * Slope is at (1, 1) - * Hitbox is at (2, 1) and moving by (-0.5f, -0.25f) + * Hitbox is at (2, 1) and moving by (-0.75f, -0.25f) * * #### * #/E` @@ -141,7 +141,7 @@ public void resolveCollisions_CollideWhenIntersectingTileAboveSlope() { */ float hX = GameUtils.worldUnits(2); float hY = GameUtils.worldUnits(1); - float dx = GameUtils.worldUnits(-0.5f); + float dx = GameUtils.worldUnits(-0.75f); float dy = GameUtils.worldUnits(-0.25f); int slopeTileX = 1; int slopeTileY = 1; @@ -154,11 +154,11 @@ public void resolveCollisions_CollideWhenIntersectingTileAboveSlope() { new PostProcessCollision(slope, slopeTileX, slopeTileY, node); slope.postProcessing(result, collision); - // THEN a collision is added at ceiling level - // (because the slope node has only just entered the Slope) + // THEN a collision is added 1/4 of the way down the Slope + // (moving 0.5 units would put the slope node at the top of the slope) assertEquals(1, result.getCollisionsY().size()); assertEquals( - Tile.getTop(GameUtils.worldUnits(1)), + Tile.getTop(GameUtils.worldUnits(1)) + 0.25f, result.getNearestCollisionY().collisionPos, 0.001); } diff --git a/test/engine/game/tiles/LeftSlopeTest.java b/test/engine/game/tiles/LeftSlopeTest.java index b55ec41..02793a8 100644 --- a/test/engine/game/tiles/LeftSlopeTest.java +++ b/test/engine/game/tiles/LeftSlopeTest.java @@ -96,14 +96,14 @@ public void resolveCollisions_CollideWhenIntersectingTileUnderSlope() { * GIVEN: * * Slope is at (1, 1) - * Hitbox is at (2, 1) and moving by (-0.5f, 0.25f) + * Hitbox is at (2, 1) and moving by (-0.75f, 0.25f) * _ * #\E_ * #### */ float hX = GameUtils.worldUnits(2); float hY = GameUtils.worldUnits(1); - float dx = GameUtils.worldUnits(-0.5f); + float dx = GameUtils.worldUnits(-0.75f); float dy = GameUtils.worldUnits(0.25f); int slopeTileX = 1; int slopeTileY = 1; @@ -116,11 +116,11 @@ public void resolveCollisions_CollideWhenIntersectingTileUnderSlope() { new PostProcessCollision(slope, slopeTileX, slopeTileY, node); slope.postProcessing(result, collision); - // THEN a collision is added at floor level - // (because the slope node has only just entered the Slope) + // THEN a collision is added 1/4 of the way up the Slope + // (moving 0.5 units would put the slope node at the base of the slope) assertEquals(1, result.getCollisionsY().size()); assertEquals( - Tile.getBottom(GameUtils.worldUnits(1)), + Tile.getTop(GameUtils.worldUnits(1)) + 0.75f, result.getNearestCollisionY().collisionPos, 0.001); } @@ -130,7 +130,7 @@ public void resolveCollisions_CollideWithGroundBeforeSlopeNodeEntersSlope() { * GIVEN: * * Slope is at (1, 1) - * Hitbox is at (2, 1) and moving by (-0.25f, 0.25f) + * Hitbox is at (2, 1) and moving by (0.25f, 0.25f) * _ * #\E_ * #### @@ -148,22 +148,24 @@ public void resolveCollisions_CollideWithGroundBeforeSlopeNodeEntersSlope() { // AND the Hitbox has already collided with the ground CollisionResult result = new CollisionResult(hitbox, dx, dy); - CollisionNode node = hitbox.getBottomNodes()[0]; - Collision groundCollision = Collision.create( - hY, - Tile.getTop(hY + GameUtils.worldUnits(1)), - node, - new SolidBlock(0)); - result.addCollision_Y(groundCollision); + for (CollisionNode node : hitbox.getBottomNodes()) { + Collision groundCollision = Collision.create( + hY, + Tile.getTop(hY + GameUtils.worldUnits(1)), + node, + new SolidBlock(0)); + result.addCollision_Y(groundCollision); + } // WHEN resolving collisions with this Slope + CollisionNode bottomLeft = hitbox.getBottomNodes()[0]; + CollisionNode bottomRight = hitbox.getBottomNodes()[1]; PostProcessCollision collision = - new PostProcessCollision(slope, slopeTileX, slopeTileY, node); + new PostProcessCollision(slope, slopeTileX, slopeTileY, bottomLeft); slope.postProcessing(result, collision); - // THEN the ground collision is still present - assertEquals(1, result.getCollisionsY().size()); - assertEquals(groundCollision, result.getNearestCollisionY()); + // THEN the ground collision with the bottom-right node is still valid + assertEquals(bottomRight, result.getNearestCollisionY().node); } @Test diff --git a/test/engine/game/tiles/RightSlopeTest.java b/test/engine/game/tiles/RightSlopeTest.java index 97fc4fa..f3f9ef1 100644 --- a/test/engine/game/tiles/RightSlopeTest.java +++ b/test/engine/game/tiles/RightSlopeTest.java @@ -148,22 +148,24 @@ public void resolveCollisions_CollideWithGroundBeforeSlopeNodeEntersSlope() { // AND the Hitbox has already collided with the ground CollisionResult result = new CollisionResult(hitbox, dx, dy); - CollisionNode node = hitbox.getBottomNodes()[1]; - Collision groundCollision = Collision.create( - hY, - Tile.getTop(hY + GameUtils.worldUnits(1)), - node, - new SolidBlock(0)); - result.addCollision_Y(groundCollision); + for (CollisionNode node : hitbox.getBottomNodes()) { + Collision groundCollision = Collision.create( + hY, + Tile.getTop(hY + GameUtils.worldUnits(1)), + node, + new SolidBlock(0)); + result.addCollision_Y(groundCollision); + } // WHEN resolving collisions with this Slope + CollisionNode bottomLeft = hitbox.getBottomNodes()[0]; + CollisionNode bottomRight = hitbox.getBottomNodes()[1]; PostProcessCollision collision = - new PostProcessCollision(slope, slopeTileX, slopeTileY, node); + new PostProcessCollision(slope, slopeTileX, slopeTileY, bottomRight); slope.postProcessing(result, collision); - // THEN the ground collision is still present - assertEquals(1, result.getCollisionsY().size()); - assertEquals(groundCollision, result.getNearestCollisionY()); + // THEN the ground collision with the bottom-left node is still valid + assertEquals(bottomLeft, result.getNearestCollisionY().node); } @Test