Browse Source

Added Update Function to GameManager

remotes/origin/menu
fdai7012 11 months ago
committed by Julian
parent
commit
758ec71519
  1. 9
      src/main/java/pacmanGame/GameManager.java
  2. 51
      src/test/java/pacmanTests/GameManagerTest.java

9
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++;
}
}

51
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);
}
}
Loading…
Cancel
Save