From 24e36dd20597546a9df49c6af3a238dd4ceb7bd3 Mon Sep 17 00:00:00 2001 From: BlairCannon97 Date: Sat, 30 Sep 2023 13:54:35 +1000 Subject: [PATCH] Added further tests into the wave test classes. Some helper methods have been added to wave related classes. --- .../components/tasks/waves/LevelWaves.java | 17 ++++++++++++++ .../game/components/tasks/waves/WaveTask.java | 16 +++++++++---- .../tasks/waves/LevelWavesTest.java | 23 ++++++++++++++++--- .../components/tasks/waves/WaveTaskTest.java | 6 ++++- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java b/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java index a4a4aaabb..e33c5463c 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java @@ -89,4 +89,21 @@ public void setWaveIndex(int index) { public int getNumWaves() { return this.numWaves; } + + /** + * Get the current mob index + * @return mob index + */ + public int getMobIndex() { + return this.mobIndex; + } + + /** + * Get the current wave index + * @return wave index + */ + public int getWaveIndex() { + return this.waveIndex; + } + } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java b/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java index 5ffcfdea9..94eed4d80 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java @@ -30,8 +30,8 @@ public class WaveTask extends DefaultTask implements PriorityTask { "sounds/waves/wave-end/Wave_Over_01.ogg" }; - private Sound waveStart; - private Sound waveEnd; + private final Sound waveStart; + private final Sound waveEnd; /** * Constructor for the WaveTask @@ -71,7 +71,7 @@ public int getPriority() { /** * Starts the WaveTask and initialises all relevant attributes. - * Sets the current count of enmies to be the size of the current wave. + * Sets the current count of enemies to be the size of the current wave. */ @Override public void start() { @@ -121,4 +121,12 @@ public void update() { } } } -} \ No newline at end of file + + /** + * Checks if the current wave is in progress + * @return true if the wave is in progress, false otherwise + */ + public boolean isWaveInProgress() { + return waveInProgress; + } + } diff --git a/source/core/src/test/com/csse3200/game/components/tasks/waves/LevelWavesTest.java b/source/core/src/test/com/csse3200/game/components/tasks/waves/LevelWavesTest.java index 4c8746151..da0f54eff 100644 --- a/source/core/src/test/com/csse3200/game/components/tasks/waves/LevelWavesTest.java +++ b/source/core/src/test/com/csse3200/game/components/tasks/waves/LevelWavesTest.java @@ -1,21 +1,38 @@ package com.csse3200.game.components.tasks.waves; -import com.csse3200.game.areas.ForestGameArea; +import com.csse3200.game.entities.factories.WaveFactory; import com.csse3200.game.extensions.GameExtension; -import com.csse3200.game.services.GameTime; +import com.csse3200.game.services.ServiceLocator; +import org.junit.Test; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; @ExtendWith(GameExtension.class) @ExtendWith(MockitoExtension.class) class LevelWavesTest { + LevelWaves levelWaves; + WaveClass wave; + ServiceLocator serviceLocator; + @BeforeEach void setUp() { + levelWaves = (LevelWaves) WaveFactory.createWaves(); + wave = mock(WaveClass.class); + } + + @Test + public void testAddWave() { + levelWaves.addWave(wave); + assertEquals(3, levelWaves.waves.size()); + } + + @Test + public void testSpawnWaveStart() { } } diff --git a/source/core/src/test/com/csse3200/game/components/tasks/waves/WaveTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/waves/WaveTaskTest.java index 59685cfe7..0926c9e9b 100644 --- a/source/core/src/test/com/csse3200/game/components/tasks/waves/WaveTaskTest.java +++ b/source/core/src/test/com/csse3200/game/components/tasks/waves/WaveTaskTest.java @@ -1,6 +1,8 @@ package com.csse3200.game.components.tasks.waves; import com.badlogic.gdx.audio.Sound; +import com.csse3200.game.areas.ForestGameArea; +import com.csse3200.game.areas.terrain.TerrainFactory; import com.csse3200.game.components.tasks.DroidCombatTask; import com.csse3200.game.extensions.GameExtension; import com.csse3200.game.services.GameTime; @@ -14,6 +16,7 @@ import java.util.logging.Level; import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -24,6 +27,7 @@ class WaveTaskTest { WaveTask waveTask; ResourceService resourceService; LevelWaves level; + ForestGameArea gameArea; @BeforeEach void setUp() { resourceService = ServiceLocator.getResourceService(); @@ -48,9 +52,9 @@ public void testGetPriority() { @Test public void testStartWave() { - WaveTask waveTask = new WaveTask(); waveTask.start(); assertEquals(1, waveTask.getPriority()); + assertTrue(waveTask.isWaveInProgress()); } }