From 338376c2c668933bbbd361623a992e79af854a34 Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Tue, 19 Jan 2021 00:02:14 -0500 Subject: [PATCH 1/9] Extract updating runEnergy from setting runEnergy --- .../java/io/luna/game/model/mob/Player.java | 25 +++++++++++-------- .../io/luna/game/model/mob/WalkingQueue.java | 17 ++++++++----- .../model/mob/persistence/PlayerData.java | 2 +- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/luna/game/model/mob/Player.java b/src/main/java/io/luna/game/model/mob/Player.java index 24f17763f..4a5f141a9 100644 --- a/src/main/java/io/luna/game/model/mob/Player.java +++ b/src/main/java/io/luna/game/model/mob/Player.java @@ -608,19 +608,23 @@ public double getRunEnergy() { /** * Sets the run energy percentage. * - * @param newRunEnergy The value to set to. + * @param runEnergy The value to set to. */ - public void setRunEnergy(double newRunEnergy, boolean update) { - if (newRunEnergy > 100.0) { - newRunEnergy = 100.0; + public void setRunEnergy(double runEnergy) { + if (runEnergy > 100.0) { + runEnergy = 100.0; } - if (runEnergy != newRunEnergy) { - runEnergy = newRunEnergy; - if (update) { - queue(new UpdateRunEnergyMessageWriter((int) runEnergy)); - } + if (runEnergy < 0) { + runEnergy = 0; } + + this.runEnergy = runEnergy; + } + + /** Updates the client with the current run energy. */ + public void updateRunEnergy() { + queue(new UpdateRunEnergyMessageWriter((int) runEnergy)); } /** @@ -635,7 +639,8 @@ public void increaseRunEnergy(double amount) { } else if (newEnergy < 0.0) { newEnergy = 0.0; } - setRunEnergy(newEnergy, true); + setRunEnergy(newEnergy); + updateRunEnergy(); } /** diff --git a/src/main/java/io/luna/game/model/mob/WalkingQueue.java b/src/main/java/io/luna/game/model/mob/WalkingQueue.java index b74d108eb..f68e300b0 100644 --- a/src/main/java/io/luna/game/model/mob/WalkingQueue.java +++ b/src/main/java/io/luna/game/model/mob/WalkingQueue.java @@ -163,7 +163,9 @@ public void process() { } if (restoreEnergy && mob.getType() == EntityType.PLAYER) { - incrementRunEnergy(); + Player player = mob.asPlr(); + incrementRunEnergy(player); + player.updateRunEnergy(); } mob.setWalkingDirection(walkingDirection); @@ -274,20 +276,22 @@ private boolean decrementRunEnergy(Player player) { .pow(Math.E, 0.0027725887222397812376689284858327062723020005374410 * totalWeight); double newValue = player.getRunEnergy() - energyReduction; if (newValue <= 0.0) { - player.setRunEnergy(0.0, true); + player.setRunEnergy(0.0); + player.updateRunEnergy(); + player.setRunning(false); runningPath = false; return false; } - player.setRunEnergy(newValue, true); + player.setRunEnergy(newValue); + player.updateRunEnergy(); return true; } /** * A function that implements an algorithm to restore run energy. */ - private void incrementRunEnergy() { - Player player = mob.asPlr(); + void incrementRunEnergy(Player player) { double runEnergy = player.getRunEnergy(); if (runEnergy >= 100.0) { @@ -300,7 +304,8 @@ private void incrementRunEnergy() { double newValue = runEnergy + energyRestoration; newValue = Math.min(newValue, 100.0); - player.setRunEnergy(newValue, true); + player.setRunEnergy(newValue); + player.updateRunEnergy(); } /** diff --git a/src/main/java/io/luna/game/model/mob/persistence/PlayerData.java b/src/main/java/io/luna/game/model/mob/persistence/PlayerData.java index fcee966ff..d03bd41e5 100644 --- a/src/main/java/io/luna/game/model/mob/persistence/PlayerData.java +++ b/src/main/java/io/luna/game/model/mob/persistence/PlayerData.java @@ -66,7 +66,7 @@ public void load(Player player) { player.getIgnores().addAll(ignores); player.setUnbanDate(unbanDate); player.setUnmuteDate(unmuteDate); - player.setRunEnergy(runEnergy, false); + player.setRunEnergy(runEnergy); player.setWeight(weight, false); player.getAttributes().load(attributes); } From 176a3dd61bbfbe7d67f8961607bfd040be7449e0 Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Tue, 19 Jan 2021 03:37:01 -0500 Subject: [PATCH 2/9] Improve readability of global and temporary fields in WalkingQueue Replaces direct access to these fields with getters --- .../io/luna/game/model/mob/WalkingQueue.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/io/luna/game/model/mob/WalkingQueue.java b/src/main/java/io/luna/game/model/mob/WalkingQueue.java index f68e300b0..c13f2b362 100644 --- a/src/main/java/io/luna/game/model/mob/WalkingQueue.java +++ b/src/main/java/io/luna/game/model/mob/WalkingQueue.java @@ -94,12 +94,12 @@ public int getY() { /** * A deque of current steps. */ - private final Deque current = new ArrayDeque<>(); + private final Deque currentQueue = new ArrayDeque<>(); /** * A deque of previous steps. */ - private final Deque previous = new ArrayDeque<>(); + private final Deque previousQueue = new ArrayDeque<>(); /** * The mob. @@ -131,34 +131,34 @@ public WalkingQueue(Mob mob) { */ public void process() { // TODO clean up function - Step current = new Step(mob.getPosition()); + Step currentStep = new Step(mob.getPosition()); Direction walkingDirection = Direction.NONE; Direction runningDirection = Direction.NONE; boolean restoreEnergy = true; - Step next = this.current.poll(); - if (next != null) { - previous.add(next); - walkingDirection = Direction.between(current, next); - current = next; + Step nextStep = this.currentQueue.poll(); + if (nextStep != null) { + previousQueue.add(nextStep); + walkingDirection = Direction.between(currentStep, nextStep); + currentStep = nextStep; if (mob.getType() == EntityType.PLAYER) { Player player = mob.asPlr(); if (player.isRunning() || runningPath) { - next = decrementRunEnergy(player) ? this.current.poll() : null; - if (next != null) { + nextStep = decrementRunEnergy(player) ? this.currentQueue.poll() : null; + if (nextStep != null) { restoreEnergy = false; - previous.add(next); - runningDirection = Direction.between(current, next); - current = next; + previousQueue.add(nextStep); + runningDirection = Direction.between(currentStep, nextStep); + currentStep = nextStep; } } } - Position newPosition = new Position(current.getX(), current.getY(), mob.getPosition().getZ()); + Position newPosition = new Position(currentStep.getX(), currentStep.getY(), mob.getPosition().getZ()); mob.setPosition(newPosition); } @@ -202,23 +202,23 @@ public void walk(Position firstPos, Position... otherPos) { * @param step The step to add. */ public void addFirst(Step step) { - current.clear(); + currentQueue.clear(); runningPath = false; Queue backtrack = new ArrayDeque<>(); for (; ; ) { - Step prev = previous.pollLast(); + Step prev = previousQueue.pollLast(); if (prev == null) { break; } backtrack.add(prev); if (prev.equals(step)) { backtrack.forEach(this::add); - previous.clear(); + previousQueue.clear(); return; } } - previous.clear(); + previousQueue.clear(); add(step); } @@ -229,7 +229,7 @@ public void addFirst(Step step) { * @param next The step to add. */ public void add(Step next) { - Step last = current.peekLast(); + Step last = currentQueue.peekLast(); if (last == null) { last = new Step(mob.getPosition()); } @@ -253,7 +253,7 @@ public void add(Step next) { } else if (deltaY > 0) { deltaY--; } - current.add(new Step(nextX - deltaX, nextY - deltaY)); + currentQueue.add(new Step(nextX - deltaX, nextY - deltaY)); } } @@ -261,8 +261,8 @@ public void add(Step next) { * Clears the current and previous steps. */ public void clear() { - current.clear(); - previous.clear(); + currentQueue.clear(); + previousQueue.clear(); } /** @@ -314,7 +314,7 @@ void incrementRunEnergy(Player player) { * @return The amount of remaining steps. */ public int getRemainingSteps() { - return current.size(); + return currentQueue.size(); } /** From cc934499edaeb48ba922b23f988fd163a9d479dd Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Tue, 19 Jan 2021 15:12:34 -0500 Subject: [PATCH 3/9] Increase readability of WalkingQueue.process() by removing ternary operator --- src/main/java/io/luna/game/model/mob/WalkingQueue.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/luna/game/model/mob/WalkingQueue.java b/src/main/java/io/luna/game/model/mob/WalkingQueue.java index c13f2b362..c497a3fe3 100644 --- a/src/main/java/io/luna/game/model/mob/WalkingQueue.java +++ b/src/main/java/io/luna/game/model/mob/WalkingQueue.java @@ -147,7 +147,11 @@ public void process() { if (mob.getType() == EntityType.PLAYER) { Player player = mob.asPlr(); if (player.isRunning() || runningPath) { - nextStep = decrementRunEnergy(player) ? this.currentQueue.poll() : null; + if (decrementRunEnergy(player)) { + nextStep = this.currentQueue.poll(); + } else { + nextStep = null; + } if (nextStep != null) { restoreEnergy = false; previousQueue.add(nextStep); @@ -157,7 +161,6 @@ public void process() { } } - Position newPosition = new Position(currentStep.getX(), currentStep.getY(), mob.getPosition().getZ()); mob.setPosition(newPosition); } @@ -204,7 +207,6 @@ public void walk(Position firstPos, Position... otherPos) { public void addFirst(Step step) { currentQueue.clear(); runningPath = false; - Queue backtrack = new ArrayDeque<>(); for (; ; ) { Step prev = previousQueue.pollLast(); @@ -305,7 +307,6 @@ void incrementRunEnergy(Player player) { newValue = Math.min(newValue, 100.0); player.setRunEnergy(newValue); - player.updateRunEnergy(); } /** From 107c3d32824a49d7d35a9c004574894231e700c0 Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Tue, 19 Jan 2021 15:56:40 -0500 Subject: [PATCH 4/9] Deconstruct WalkingQueue.decrementRun into several methods --- .../io/luna/game/model/mob/WalkingQueue.java | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/main/java/io/luna/game/model/mob/WalkingQueue.java b/src/main/java/io/luna/game/model/mob/WalkingQueue.java index c497a3fe3..16cef5704 100644 --- a/src/main/java/io/luna/game/model/mob/WalkingQueue.java +++ b/src/main/java/io/luna/game/model/mob/WalkingQueue.java @@ -147,7 +147,9 @@ public void process() { if (mob.getType() == EntityType.PLAYER) { Player player = mob.asPlr(); if (player.isRunning() || runningPath) { - if (decrementRunEnergy(player)) { + if (hasEnoughEnergyToRun(player)) { + useEnergy(player); + player.updateRunEnergy(); nextStep = this.currentQueue.poll(); } else { nextStep = null; @@ -175,6 +177,31 @@ public void process() { mob.setRunningDirection(runningDirection); } + double getRemainingEnergy(double weight, double runEnergy) { + double energyReduction = 0.117 * 2 * Math + .pow(Math.E, 0.0027725887222397812376689284858327062723020005374410 * weight); + return runEnergy - energyReduction; + } + + boolean hasEnoughEnergyToRun(Player player) { + double energyRemaining = getRemainingEnergy(player.getWeight(), player.getRunEnergy()); + return energyRemaining >= 0; + } + + /** + * Depletes a player's energy. If the player doesn't have enough energy, the player will stop running. + */ + void useEnergy(Player player) { + double energyLeft = getRemainingEnergy(player.getWeight(), player.getRunEnergy()); + if (hasEnoughEnergyToRun(player)) { + player.setRunEnergy(energyLeft); + } else { + player.setRunEnergy(0.0); + player.setRunning(false); + runningPath = false; + } + } + /** * Walks to the specified offsets. * @@ -267,29 +294,6 @@ public void clear() { previousQueue.clear(); } - /** - * A function that implements an algorithm to deplete run energy. - * - * @return {@code false} if the player can no longer run. - */ - private boolean decrementRunEnergy(Player player) { - double totalWeight = player.getWeight(); - double energyReduction = 0.117 * 2 * Math - .pow(Math.E, 0.0027725887222397812376689284858327062723020005374410 * totalWeight); - double newValue = player.getRunEnergy() - energyReduction; - if (newValue <= 0.0) { - player.setRunEnergy(0.0); - player.updateRunEnergy(); - - player.setRunning(false); - runningPath = false; - return false; - } - player.setRunEnergy(newValue); - player.updateRunEnergy(); - return true; - } - /** * A function that implements an algorithm to restore run energy. */ From f52247be50b026c1834434d0f9671e31a5fb4dfe Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Tue, 19 Jan 2021 16:12:52 -0500 Subject: [PATCH 5/9] Extract methods related to using runEnergy from WalkingQueue to Player --- .../java/io/luna/game/model/mob/Player.java | 10 ++++++++++ .../io/luna/game/model/mob/WalkingQueue.java | 17 +++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/luna/game/model/mob/Player.java b/src/main/java/io/luna/game/model/mob/Player.java index 4a5f141a9..86fc9b9be 100644 --- a/src/main/java/io/luna/game/model/mob/Player.java +++ b/src/main/java/io/luna/game/model/mob/Player.java @@ -643,6 +643,16 @@ public void increaseRunEnergy(double amount) { updateRunEnergy(); } + boolean hasEnoughEnergyToRun() { + return runEnergyAfterReduction() >= 0; + } + + /** @return the remaining {@code runEnergy} after a running a single step.*/ + double runEnergyAfterReduction() { + double energyReduction = 0.117 * 2 * Math + .pow(Math.E, 0.0027725887222397812376689284858327062723020005374410 * getWeight()); + return getRunEnergy() - energyReduction; + } /** * @return The combined weight of the inventory and equipment. */ diff --git a/src/main/java/io/luna/game/model/mob/WalkingQueue.java b/src/main/java/io/luna/game/model/mob/WalkingQueue.java index 16cef5704..9d94fd806 100644 --- a/src/main/java/io/luna/game/model/mob/WalkingQueue.java +++ b/src/main/java/io/luna/game/model/mob/WalkingQueue.java @@ -147,7 +147,7 @@ public void process() { if (mob.getType() == EntityType.PLAYER) { Player player = mob.asPlr(); if (player.isRunning() || runningPath) { - if (hasEnoughEnergyToRun(player)) { + if (player.hasEnoughEnergyToRun()) { useEnergy(player); player.updateRunEnergy(); nextStep = this.currentQueue.poll(); @@ -177,23 +177,12 @@ public void process() { mob.setRunningDirection(runningDirection); } - double getRemainingEnergy(double weight, double runEnergy) { - double energyReduction = 0.117 * 2 * Math - .pow(Math.E, 0.0027725887222397812376689284858327062723020005374410 * weight); - return runEnergy - energyReduction; - } - - boolean hasEnoughEnergyToRun(Player player) { - double energyRemaining = getRemainingEnergy(player.getWeight(), player.getRunEnergy()); - return energyRemaining >= 0; - } - /** * Depletes a player's energy. If the player doesn't have enough energy, the player will stop running. */ void useEnergy(Player player) { - double energyLeft = getRemainingEnergy(player.getWeight(), player.getRunEnergy()); - if (hasEnoughEnergyToRun(player)) { + double energyLeft = player.runEnergyAfterReduction(); + if (player.hasEnoughEnergyToRun()) { player.setRunEnergy(energyLeft); } else { player.setRunEnergy(0.0); From 0cd60f2ee55f5736ab75ce20879e755b769081b6 Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Tue, 19 Jan 2021 23:52:31 -0500 Subject: [PATCH 6/9] Create null objects for testing purposes --- .../luna/game/model/mob/PlayerSettings.java | 2 +- .../io/luna/game/model/mob/WalkingQueue.java | 2 +- .../game/model/mob/NullPlayerSettings.java | 50 +++++++++++++++++++ .../luna/game/model/mob/NullWalkingQueue.java | 20 ++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 src/test/java/io/luna/game/model/mob/NullPlayerSettings.java create mode 100644 src/test/java/io/luna/game/model/mob/NullWalkingQueue.java diff --git a/src/main/java/io/luna/game/model/mob/PlayerSettings.java b/src/main/java/io/luna/game/model/mob/PlayerSettings.java index d822a94b8..a32d03585 100644 --- a/src/main/java/io/luna/game/model/mob/PlayerSettings.java +++ b/src/main/java/io/luna/game/model/mob/PlayerSettings.java @@ -9,7 +9,7 @@ * * @author lare96 */ -public final class PlayerSettings { +public class PlayerSettings { /** * An enumerated type whose elements represent brightness levels. diff --git a/src/main/java/io/luna/game/model/mob/WalkingQueue.java b/src/main/java/io/luna/game/model/mob/WalkingQueue.java index 9d94fd806..caae63a51 100644 --- a/src/main/java/io/luna/game/model/mob/WalkingQueue.java +++ b/src/main/java/io/luna/game/model/mob/WalkingQueue.java @@ -17,7 +17,7 @@ * @author lare96 * @author Graham */ -public final class WalkingQueue { +public class WalkingQueue { // TODO Rewrite diff --git a/src/test/java/io/luna/game/model/mob/NullPlayerSettings.java b/src/test/java/io/luna/game/model/mob/NullPlayerSettings.java new file mode 100644 index 000000000..7c11f731a --- /dev/null +++ b/src/test/java/io/luna/game/model/mob/NullPlayerSettings.java @@ -0,0 +1,50 @@ +package io.luna.game.model.mob; + +/** A {@link PlayerSettings} designed for testing purposes only. */ +public class NullPlayerSettings extends PlayerSettings { + + @Override + public void showRunning() { + return; + } + + @Override + public void showAutoRetaliate() { + return; + } + + @Override + public void showBrightnessLevel() { + return; + } + + @Override + public void showMouseType() { + return; + } + + @Override + public void showChatEffects() { + return; + } + + @Override + public void showSplitPrivateChat() { + return; + } + + @Override + public void showAcceptAid() { + return; + } + + @Override + public void showMusicVolume() { + return; + } + + @Override + public void showEffectsVolume() { + return; + } +} diff --git a/src/test/java/io/luna/game/model/mob/NullWalkingQueue.java b/src/test/java/io/luna/game/model/mob/NullWalkingQueue.java new file mode 100644 index 000000000..594989a5d --- /dev/null +++ b/src/test/java/io/luna/game/model/mob/NullWalkingQueue.java @@ -0,0 +1,20 @@ +package io.luna.game.model.mob; + +/** + * A {@link WalkingQueue} designed for testing purposes only. + */ +class NullWalkingQueue extends WalkingQueue { + /** + * Create a new {@link WalkingQueue}. + * + * @param mob The mob. + */ + NullWalkingQueue(Mob mob) { + super(mob); + } + + @Override + void updateEnergy() { + return; + } +} From 85c9966ca18805c82c2f63063b83036cfad2941b Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Tue, 19 Jan 2021 23:55:42 -0500 Subject: [PATCH 7/9] Hide calls to player.updateRunEnergy into separate method This makes WalkingQueue.process() testable using null objects. --- src/main/java/io/luna/game/model/mob/WalkingQueue.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/luna/game/model/mob/WalkingQueue.java b/src/main/java/io/luna/game/model/mob/WalkingQueue.java index caae63a51..58b9839f5 100644 --- a/src/main/java/io/luna/game/model/mob/WalkingQueue.java +++ b/src/main/java/io/luna/game/model/mob/WalkingQueue.java @@ -115,7 +115,6 @@ public int getY() { * If the current path is a running path. */ private boolean runningPath; - /** * Create a new {@link WalkingQueue}. * @@ -149,7 +148,7 @@ public void process() { if (player.isRunning() || runningPath) { if (player.hasEnoughEnergyToRun()) { useEnergy(player); - player.updateRunEnergy(); + updateEnergy(); nextStep = this.currentQueue.poll(); } else { nextStep = null; @@ -170,13 +169,17 @@ public void process() { if (restoreEnergy && mob.getType() == EntityType.PLAYER) { Player player = mob.asPlr(); incrementRunEnergy(player); - player.updateRunEnergy(); + updateEnergy(); } mob.setWalkingDirection(walkingDirection); mob.setRunningDirection(runningDirection); } + void updateEnergy(){ + mob.asPlr().updateRunEnergy(); + } + /** * Depletes a player's energy. If the player doesn't have enough energy, the player will stop running. */ From 13dad392d103b1dacb57cf9eb7bcf180f025fa52 Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Wed, 20 Jan 2021 00:43:36 -0500 Subject: [PATCH 8/9] Make LunaContext extensible to allow mocking for tests --- src/main/java/io/luna/LunaContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/luna/LunaContext.java b/src/main/java/io/luna/LunaContext.java index c96de6298..127157891 100644 --- a/src/main/java/io/luna/LunaContext.java +++ b/src/main/java/io/luna/LunaContext.java @@ -9,7 +9,7 @@ * * @author lare96 */ -public final class LunaContext { +public class LunaContext { /** * The world. From dcf97357da6c436bb66b1a5bd733ac71e6c5ebb8 Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Wed, 20 Jan 2021 00:44:08 -0500 Subject: [PATCH 9/9] Add behavioural tests for WalkingQueue --- .../luna/game/model/mob/WalkingQueueTest.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/test/java/io/luna/game/model/mob/WalkingQueueTest.java diff --git a/src/test/java/io/luna/game/model/mob/WalkingQueueTest.java b/src/test/java/io/luna/game/model/mob/WalkingQueueTest.java new file mode 100644 index 000000000..f38f40824 --- /dev/null +++ b/src/test/java/io/luna/game/model/mob/WalkingQueueTest.java @@ -0,0 +1,111 @@ +package io.luna.game.model.mob; + +import io.luna.LunaContext; +import io.luna.game.model.Position; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + +class WalkingQueueTest { + private final PlayerCredentials credentials = new PlayerCredentials("test", "test"); + private final LunaContext context = mock(LunaContext.class); + private final Player player = new Player(context, credentials); + + private final WalkingQueue queue = new NullWalkingQueue(player); + private final Position startPosition = new Position(0, 0); + + + private WalkingQueueTest() { + player.setSettings(new NullPlayerSettings()); + } + + @BeforeEach + void init() { + player.setPosition(startPosition); + player.setRunning(false); + queue.clear(); + } + + @Test + void whenPlayerIsNotMoving_thenDoNotTakeAnySteps() { + player.setPosition(startPosition); + + //No movement applied + queue.process(); + + assertEquals(startPosition, player.getPosition()); + } + + @Test + void whenPlayerIsWalking_thenTakeOneStep() { + player.setRunEnergy(100); + + queue.walk(2, 2); + queue.process(); + + var stepsTaken = player.getPosition().computeLongestDistance(startPosition); + assertEquals(stepsTaken, 1); + } + + @Test + void whenPlayerIsNotMoving_thenIncreaseRunEnergy() { + var startingEnergy = 0.0; + player.setRunEnergy(startingEnergy); + player.setPosition(startPosition); + + // No movement applied + queue.process(); + + assertTrue(player.getRunEnergy() > startingEnergy); + } + + @Test + void whenPlayerIsWalking_thenIncreaseRunEnergy() { + var startingEnergy = 0.0; + player.setRunEnergy(startingEnergy); + player.setPosition(startPosition); + + queue.walk(1, 1); + queue.process(); + + assertTrue(player.getRunEnergy() > startingEnergy); + } + @Test + void whenPlayerIsRunning_AndHasEnergy_thenDecreaseRunEnergy(){ + var startingEnergy = 100; + player.setRunEnergy(startingEnergy); + player.setRunning(true); + + queue.walk(2, 2); + queue.process(); + + assertTrue(player.getRunEnergy() < startingEnergy); + } + + @Test + void whenPlayerIsRunning_AndHasEnergy_thenTakeTwoSteps() { + player.setRunEnergy(100); + player.setRunning(true); + + queue.walk(2, 2); + queue.process(); + + var stepsTaken = player.getPosition().computeLongestDistance(startPosition); + assertEquals(stepsTaken, 2); + } + + @Test + void whenPlayerIsRunning_AndOutOfEnergy_thenTakeOneStep() { + player.setRunEnergy(0); + player.setRunning(true); + + queue.walk(2, 2); + queue.process(); + + var stepsTaken = player.getPosition().computeLongestDistance(startPosition); + assertEquals(stepsTaken, 1); + } +} \ No newline at end of file