Skip to content

Bosses Projectile Tests

Phurin Vanasrivilai edited this page Oct 17, 2024 · 3 revisions

Unit Tests for Bosses Projectiles

This document describes the unit tests implemented for projectiles created by the ProjectileFactory, specifically focusing on the Water Spiral from Leviathan and Wind Gust from Griffin. These tests ensure that the projectiles are correctly instantiated with the necessary components, animations, and AI tasks.

In ProjectileFactoryTest, tests for Water Spiral from Leviathan

Test: TestWaterSpiralHasComponents

This test verifies that the WaterSpiral entity created by the ProjectileFactory has all the essential components.

  • Components Checked:
    • PhysicsComponent
    • PhysicsMovementComponent
    • WaterSpiralAnimationController
    • ProjectileAttackComponent
    • HitboxComponent
    • ColliderComponent
    • AITaskComponent

Test Purpose:

Ensures that the projectile is correctly configured with all necessary components for movement, collision, attack handling, and AI control.

Code:

@Test
void TestWaterSpiralHasComponents() {
    Entity waterSpiral = ProjectileFactory.createWaterSpiral(new Entity());

    assertNotNull(waterSpiral.getComponent(PhysicsComponent.class));
    assertNotNull(waterSpiral.getComponent(PhysicsMovementComponent.class));
    assertNotNull(waterSpiral.getComponent(WaterSpiralAnimationController.class));
    assertNotNull(waterSpiral.getComponent(ProjectileAttackComponent.class));
    assertNotNull(waterSpiral.getComponent(HitboxComponent.class));
    assertNotNull(waterSpiral.getComponent(ColliderComponent.class));
    assertNotNull(waterSpiral.getComponent(AITaskComponent.class));
}

Test: TestWaterSpiralAnimationLoaded

This test checks if the WaterSpiral projectile has the appropriate animation loaded.

  • Animation Checked: waterSpiral

Test Purpose:

Ensures that the water spiral projectile displays the correct animation when rendered.

Code:

@Test
void TestWaterSpiralAnimationLoaded() {
    Entity waterSpiral = ProjectileFactory.createWaterSpiral(new Entity());
    AnimationRenderComponent animationComponent = waterSpiral.getComponent(AnimationRenderComponent.class);

    assertNotNull(animationComponent);
    assertTrue(animationComponent.hasAnimation("waterSpiral"), "WaterSpiral should have waterSpiral animation.");
}

Test: TestWaterSpiralSpeed

This test verifies that the WaterSpiral projectile has the correct movement speed.

  • Speed Checked: 6.0f for both X and Y directions.

Test Purpose:

Ensures that the water spiral projectile moves at the expected speed when launched.

Code:

@Test
void TestWaterSpiralSpeed() {
    Entity waterSpiral = ProjectileFactory.createWaterSpiral(new Entity());
    PhysicsMovementComponent movementComponent = waterSpiral.getComponent(PhysicsMovementComponent.class);

    Vector2 expectedSpeed = new Vector2(6.0f, 6.0f);
    assertEquals(expectedSpeed, movementComponent.getMaxSpeed());
}

Test: TestWaterSpiralAITask

This test ensures that the WaterSpiral projectile has the correct AI task configuration, specifically checking for the presence of a ProjectileMovementTask.

  • Components Checked:
    • AITaskComponent
    • Contains ProjectileMovementTask

Test Purpose:

Ensures that the WaterSpiral projectile has an AI task responsible for its movement and no task is active initially.

Code:

@Test
void TestWaterSpiralAITask() {
    Entity waterSpiral = ProjectileFactory.createWaterSpiral(new Entity());
    AITaskComponent aiTaskComponent = waterSpiral.getComponent(AITaskComponent.class);

    assertNotNull(aiTaskComponent, "AITaskComponent should not be null for WaterSpiral.");

    boolean containsProjectileMovementTask = false;
    for (PriorityTask task : aiTaskComponent.getTasks()) {
        if (task instanceof ProjectileMovementTask) {
            containsProjectileMovementTask = true;
            break;
        }
    }

    assertTrue(containsProjectileMovementTask, "WaterSpiral AI task list should contain a ProjectileMovementTask.");
    assertNull(aiTaskComponent.getCurrentTask(), "No task should be active initially for WaterSpiral.");
}

Test: TestWindGustHasComponents

This test checks whether the WindGust entity, created by the ProjectileFactory, has all the necessary components for functioning.

  • Components Checked:
    • PhysicsComponent
    • PhysicsMovementComponent
    • WindGustAnimationController
    • ProjectileAttackComponent
    • HitboxComponent
    • ColliderComponent
    • AITaskComponent

Test Purpose:

Ensures that the WindGust projectile is properly initialized with all required components for its movement, collision, attack mechanics, and AI behavior.

Code:

@Test
void TestWindGustHasComponents() {
    Entity windGust = ProjectileFactory.createWindGust(new Entity());

    assertNotNull(windGust.getComponent(PhysicsComponent.class));
    assertNotNull(windGust.getComponent(PhysicsMovementComponent.class));
    assertNotNull(windGust.getComponent(WindGustAnimationController.class));
    assertNotNull(windGust.getComponent(ProjectileAttackComponent.class));
    assertNotNull(windGust.getComponent(HitboxComponent.class));
    assertNotNull(windGust.getComponent(ColliderComponent.class));
    assertNotNull(windGust.getComponent(AITaskComponent.class));
}

Test: TestWindGustAnimationLoaded

This test ensures that the WindGust entity created by the ProjectileFactory has its animation properly loaded.

  • Components Checked:
    • AnimationRenderComponent

Test Purpose:

Verifies that the WindGust projectile contains the correct animation by checking if the AnimationRenderComponent has the "windGust" animation.

Code:

@Test
void TestWindGustAnimationLoaded() {
    Entity windGust = ProjectileFactory.createWindGust(new Entity());
    AnimationRenderComponent animationComponent = windGust.getComponent(AnimationRenderComponent.class);

    assertNotNull(animationComponent);
    assertTrue(animationComponent.hasAnimation("windGust"), "WindGust should have windGust animation.");
}

Test: TestWindGustAITask

This test checks that the WindGust entity created by the ProjectileFactory has the correct AI task components configured.

  • Components Checked:
    • AITaskComponent

Test Purpose:

Ensures that the WindGust projectile is set up with an AI task for projectile movement and that no task is active initially.

Code:

@Test
void TestWindGustAITask() {
    Entity windGust = ProjectileFactory.createWindGust(new Entity());

    AITaskComponent aiTaskComponent = windGust.getComponent(AITaskComponent.class);

    assertNotNull(aiTaskComponent, "AITaskComponent should not be null for WindGust.");

    boolean containsProjectileMovementTask = false;
    for (PriorityTask task : aiTaskComponent.getTasks()) {
        if (task instanceof ProjectileMovementTask) {
            containsProjectileMovementTask = true;
            break;
        }
    }

    assertTrue(containsProjectileMovementTask, "The AI task list for WindGust should contain a ProjectileMovementTask.");

    assertNull(aiTaskComponent.getCurrentTask(), "No task should be active initially for WindGust.");
}
Clone this wiki locally