From 5a17e3975a6bc7f448aef2bc8ff5ddae0d6bfa90 Mon Sep 17 00:00:00 2001 From: Ahmad Abu-Aysha Date: Thu, 7 Sep 2023 15:32:52 +1000 Subject: [PATCH] updated humanWanderTask and started writing tests --- .../tasks/human/HumanWanderTask.java | 2 - .../entities/configs/EngineerConfigs.java | 3 - .../player/HumanAnimationControllerTest.java | 50 ++++++++++++++ .../tasks/human/HumanMovementTaskTest.java | 34 ++++++++++ .../tasks/human/HumanWanderTaskTest.java | 30 +++++++++ .../factories/EngineerFactoryTest.java | 66 ++++++++++++++++++- 6 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 source/core/src/test/com/csse3200/game/components/player/HumanAnimationControllerTest.java create mode 100644 source/core/src/test/com/csse3200/game/components/tasks/human/HumanMovementTaskTest.java create mode 100644 source/core/src/test/com/csse3200/game/components/tasks/human/HumanWanderTaskTest.java diff --git a/source/core/src/main/com/csse3200/game/components/tasks/human/HumanWanderTask.java b/source/core/src/main/com/csse3200/game/components/tasks/human/HumanWanderTask.java index cc27a6b6a..e3272ee06 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/human/HumanWanderTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/human/HumanWanderTask.java @@ -10,7 +10,6 @@ import com.csse3200.game.physics.components.ColliderComponent; import com.csse3200.game.physics.components.HitboxComponent; import com.csse3200.game.rendering.AnimationRenderComponent; -import com.csse3200.game.services.GameTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,7 +26,6 @@ public class HumanWanderTask extends DefaultTask implements PriorityTask { private HumanMovementTask movementTask; private HumanWaitTask waitTask; private Task currentTask; - private GameTime endTime; private boolean isDead = false; diff --git a/source/core/src/main/com/csse3200/game/entities/configs/EngineerConfigs.java b/source/core/src/main/com/csse3200/game/entities/configs/EngineerConfigs.java index e5b5159d7..21113b7a0 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/EngineerConfigs.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/EngineerConfigs.java @@ -5,9 +5,6 @@ */ public class EngineerConfigs extends BaseEntityConfig { public BaseEntityConfig engineer = new BaseEntityConfig(); - public int health = 10; public int baseAttack = 1; - - } diff --git a/source/core/src/test/com/csse3200/game/components/player/HumanAnimationControllerTest.java b/source/core/src/test/com/csse3200/game/components/player/HumanAnimationControllerTest.java new file mode 100644 index 000000000..bf104bfbb --- /dev/null +++ b/source/core/src/test/com/csse3200/game/components/player/HumanAnimationControllerTest.java @@ -0,0 +1,50 @@ +package com.csse3200.game.components.player; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class HumanAnimationControllerTest { + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + @Test + void create() { + } + + @Test + void animateIdleLeft() { + } + + @Test + void animateIdleRight() { + } + + @Test + void animateLeftWalk() { + } + + @Test + void animateRightWalk() { + } + + @Test + void animateFiring() { + } + + @Test + void animateHit() { + } + + @Test + void animateDeath() { + } +} \ No newline at end of file diff --git a/source/core/src/test/com/csse3200/game/components/tasks/human/HumanMovementTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/human/HumanMovementTaskTest.java new file mode 100644 index 000000000..4deb83386 --- /dev/null +++ b/source/core/src/test/com/csse3200/game/components/tasks/human/HumanMovementTaskTest.java @@ -0,0 +1,34 @@ +package com.csse3200.game.components.tasks.human; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class HumanMovementTaskTest { + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + @Test + void start() { + } + + @Test + void update() { + } + + @Test + void setTarget() { + } + + @Test + void stop() { + } +} \ No newline at end of file diff --git a/source/core/src/test/com/csse3200/game/components/tasks/human/HumanWanderTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/human/HumanWanderTaskTest.java new file mode 100644 index 000000000..5a24deb7c --- /dev/null +++ b/source/core/src/test/com/csse3200/game/components/tasks/human/HumanWanderTaskTest.java @@ -0,0 +1,30 @@ +package com.csse3200.game.components.tasks.human; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class HumanWanderTaskTest { + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + @Test + void getPriority() { + } + + @Test + void start() { + } + + @Test + void update() { + } +} \ No newline at end of file diff --git a/source/core/src/test/com/csse3200/game/entities/factories/EngineerFactoryTest.java b/source/core/src/test/com/csse3200/game/entities/factories/EngineerFactoryTest.java index c6bd4fee2..424e463c3 100644 --- a/source/core/src/test/com/csse3200/game/entities/factories/EngineerFactoryTest.java +++ b/source/core/src/test/com/csse3200/game/entities/factories/EngineerFactoryTest.java @@ -1,4 +1,68 @@ +package com.csse3200.game.entities.factories; + +import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.csse3200.game.entities.Entity; +import com.csse3200.game.extensions.GameExtension; +import com.csse3200.game.physics.PhysicsService; +import com.csse3200.game.rendering.AnimationRenderComponent; +import com.csse3200.game.rendering.DebugRenderer; +import com.csse3200.game.rendering.RenderService; +import com.csse3200.game.services.GameTime; +import com.csse3200.game.services.ResourceService; +import com.csse3200.game.services.ServiceLocator; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; + + import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@ExtendWith(GameExtension.class) class EngineerFactoryTest { - + Entity target = new Entity(); + private String[] texture = { + "images/engineers/engineer.png" + }; + private String[] atlas = {"images/engineers/engineer.atlas"}; + private static final String[] sounds = { + "sounds/engineers/firing_auto.mp3" + }; + + @BeforeEach + void setUp() { + GameTime gameTime = mock(GameTime.class); + when(gameTime.getDeltaTime()).thenReturn(0.02f); + ServiceLocator.registerTimeSource(gameTime); + ServiceLocator.registerPhysicsService(new PhysicsService()); + RenderService render = new RenderService(); + render.setDebug(mock(DebugRenderer.class)); + ServiceLocator.registerRenderService(render); + ResourceService resourceService = new ResourceService(); + ServiceLocator.registerResourceService(resourceService); + resourceService.loadTextureAtlases(atlas); + resourceService.loadSounds(sounds); + resourceService.loadAll(); + } + + @AfterEach + void tearDown() { + + } + + @Test + void createEngineer() { + Entity engineer = EngineerFactory.createEngineer(target); + assertNotNull(engineer); + } + + @Test + void createBaseHumanNPC() { + Entity human = EngineerFactory.createBaseHumanNPC(target); + assertNotNull(human); + } } \ No newline at end of file