From 758ec71519614f42d95776253d2c3d55ed5cefe6 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 17 Jan 2024 17:16:44 +0100 Subject: [PATCH] Added Update Function to GameManager --- src/main/java/pacmanGame/GameManager.java | 9 +++- .../java/pacmanTests/GameManagerTest.java | 51 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/test/java/pacmanTests/GameManagerTest.java diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index f754e90..24c070c 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -4,9 +4,16 @@ public class GameManager { public int time = 0; public Map map; + public Visualizer visualizer; public GameManager() { map = new Map(); + visualizer = new VisualizerPlainText(this); + } + + public void Update() { + visualizer.Update(); + + time++; } - } diff --git a/src/test/java/pacmanTests/GameManagerTest.java b/src/test/java/pacmanTests/GameManagerTest.java new file mode 100644 index 0000000..f895647 --- /dev/null +++ b/src/test/java/pacmanTests/GameManagerTest.java @@ -0,0 +1,51 @@ +package pacmanTests; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +import pacmanGame.GameManager; +import pacmanGame.Map; +import pacmanGame.VisualizerPlainText; + + +class GameManagerTest { + + @Test + void GameManager_Update_increasesTime() { + // arrange + + GameManager gameManager = new GameManager(); + VisualizerPlainText vpt = new VisualizerPlainText(gameManager); + + // act + + int initialTime = gameManager.time; + gameManager.Update(); + int updatedTime = gameManager.time; + + int expectedUpdatedTime = initialTime + 1; + + // assert + assertThat(expectedUpdatedTime).isEqualTo(updatedTime); + } + + @Test + void GameManager_Update_updatesVisualizer() { + // arrange + + GameManager gameManager = new GameManager(); + VisualizerPlainText vpt = (VisualizerPlainText) gameManager.visualizer; + + // act + + String initialVptOutput = (String)vpt.GetOutput(); + gameManager.Update(); + String updatedVptOutput = (String)vpt.GetOutput(); + + + // assert + assertThat(initialVptOutput).isNotEqualTo(updatedVptOutput); + } +}