Skip to content

Commit

Permalink
Fix failing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Danjb1 committed Jan 1, 2020
1 parent 0932f82 commit 008404c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
10 changes: 5 additions & 5 deletions test/engine/game/tiles/LeftCeilingSlopeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ 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`
* `
*/
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;
Expand All @@ -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);
}

Expand Down
36 changes: 19 additions & 17 deletions test/engine/game/tiles/LeftSlopeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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_
* ####
Expand All @@ -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
Expand Down
24 changes: 13 additions & 11 deletions test/engine/game/tiles/RightSlopeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 008404c

Please sign in to comment.