Water Spiral Projectile Test - UQcsse3200/2024-studio-2 GitHub Wiki

Water Spiral Projectile Test

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

In ProjectileFactoryTest

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