Wind Gust Projectile Test - UQcsse3200/2024-studio-2 GitHub Wiki

Wind Gust Projectile Test

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

In ProjectileFactoryTest

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.");
}