From a2790a3f9a2cff5860638b57e0c1003c0124a493 Mon Sep 17 00:00:00 2001 From: Samantha Sullivan Date: Tue, 3 Oct 2023 07:55:37 +1000 Subject: [PATCH] added tests for createLevel in waveFactoryTests --- .../entities/factories/WaveFactoryTest.java | 88 ++++++++++++++++++- 1 file changed, 85 insertions(+), 3 deletions(-) diff --git a/source/core/src/test/com/csse3200/game/entities/factories/WaveFactoryTest.java b/source/core/src/test/com/csse3200/game/entities/factories/WaveFactoryTest.java index 282833612..0d9ec419d 100644 --- a/source/core/src/test/com/csse3200/game/entities/factories/WaveFactoryTest.java +++ b/source/core/src/test/com/csse3200/game/entities/factories/WaveFactoryTest.java @@ -109,24 +109,31 @@ void testCreateLevel() { assertNotNull(lvl3); } + /** + * The three following tests ensure that every wave in the level is created correctly + * Since the waves are stored in a hashmap, by definition the mobs are unique and this + * quality does not have to be checked. + * */ @Test - void testCorrectMobs() { - //TODO incomplete, only tests level 1 - + void testLevel1Creation() { List lvl1Mobs = lvl1.getWaves(); int waveNum = 1; for (WaveClass wave : lvl1Mobs) { + + // check the number of mobs in a wave if (waveNum % 5 != 0) { assertEquals(2, wave.getEntities().size()); } else { assertEquals(3, wave.getEntities().size()); } + // check if the boss is in the wave if it is a boss wave if (waveNum % 5 == 0) { assertTrue(wave.getEntities().containsKey(LVL1_BOSS)); } + // check the health of the mobs and ensure the mobs are the correct type for (Map.Entry entry : wave.getEntities().entrySet()) { String mob = entry.getKey(); int[] spawn = entry.getValue(); @@ -145,5 +152,80 @@ void testCorrectMobs() { } assertEquals(6, waveNum); } + @Test + void testLevel2Creation() { + + List lvl1Mobs = lvl2.getWaves(); + + int waveNum = 1; + for (WaveClass wave : lvl1Mobs) { + + // check the number of mobs in a wave + if (waveNum % 5 != 0) { + assertEquals(2, wave.getEntities().size()); + } else { + assertEquals(3, wave.getEntities().size()); + } + + // check if the boss is in the wave if it is a boss wave + if (waveNum % 5 == 0) { + assertTrue(wave.getEntities().containsKey(LVL2_BOSS)); + } + + for (Map.Entry entry : wave.getEntities().entrySet()) { + String mob = entry.getKey(); + int[] spawn = entry.getValue(); + + if (waveNum % 5 != 0) { + assertTrue(LVL2_MOBS.contains(mob)); + assertEquals(MIN_HEALTH + (waveNum * 2), spawn[1]); + } else { + if (mob == LVL2_BOSS) { + assertEquals(MIN_BOSS_HEALTH + (waveNum * 2), spawn[1]); + } + } + } + + waveNum++; + } + assertEquals(11, waveNum); + } + @Test + void testLevel3Creation() { + + List lvl1Mobs = lvl3.getWaves(); + + int waveNum = 1; + for (WaveClass wave : lvl1Mobs) { + // check the number of mobs in a wave + if (waveNum % 5 != 0) { + assertEquals(2, wave.getEntities().size()); + } else { + assertEquals(3, wave.getEntities().size()); + } + + // check if the boss is in the wave if it is a boss wave + if (waveNum % 5 == 0) { + assertTrue(wave.getEntities().containsKey(LVL3_BOSS)); + } + + // check the health of the mobs and ensure the mobs are the correct type + for (Map.Entry entry : wave.getEntities().entrySet()) { + String mob = entry.getKey(); + int[] spawn = entry.getValue(); + + if (waveNum % 5 != 0) { + assertTrue(LVL3_MOBS.contains(mob)); + assertEquals(MIN_HEALTH + (waveNum * 3), spawn[1]); + } else { + if (mob == LVL3_BOSS) { + assertEquals(MIN_BOSS_HEALTH + (waveNum * 3), spawn[1]); + } + } + } + waveNum++; + } + assertEquals(16, waveNum); + } }