Test Plan For CompanionWeaponComponent - UQcsse3200/2023-studio-2 GitHub Wiki

Overview

The test plan for the CompanionWeaponComponent class is designed to thoroughly assess the functionality of this component responsible for controlling companion weapons that interact with entities. The component responds to events related to weapon attacks and changing weapons. The key aspects covered in this test plan include initialization, event handling, player attacking, changing weapons, position calculations, and rotation angle calculations.

Test Objectives

  1. Verify that the CurrentWeapon is correctly initialised as null.
  2. Test the playerAttacking method with a valid weapon type and click position to confirm that it creates a new attack entity.
  3. Test the makeNewHolding method with an invalid weapon type to check how it handles unsupported weapon types.

Test Cases

  1. testPositionInDirection Method Testing

Valid Direction and Distance

Objective: Verify that the positionInDirection method correctly calculates a position vector based on a given direction and distance. Test Input: A direction of 45 degrees and a distance of 1 unit. Expected Output: The calculated position vector should be correctly positioned at a 45-degree angle from the initial position with a distance of 1 unit.

Zero Distance

Objective: Test the behaviour of the positionInDirection method when a distance of 0 is provided. Test Input: A direction of 90 degrees and a distance of 0 units. Expected Output: The calculated position vector should be the same as the initial position since the distance is zero.

Negative Direction

Objective: Verify how the positionInDirection method handles a negative direction value. Test Input: A direction of -30 degrees and a distance of 2 units. Expected Output: The calculated position vector should be positioned at a -30-degree angle from the initial position with a distance of 2 units.

  1. testCalcRotationAngleInDegrees Method Testing

Valid Target Point

Objective: Test the calcRotationAngleInDegrees method to calculate the rotation angle in degrees. Test Input: A target point located at coordinates (1, 1). Expected Output: The calculated rotation angle in degrees should be approximately 45 degrees. Verify that the angle calculation is accurate.

Target Point at Origin

Objective: Verify how the method handles a target point located at the origin (0, 0). Test Input: A target point located at coordinates (0, 0). Expected Output: The calculated rotation angle should be 0 degrees, indicating that the target point is at the same position as the initial entity.

Negative Coordinates

Objective: Test the behaviour of the method with negative target point coordinates. Test Input: A target point located at coordinates. Expected Output: The calculated rotation angle should be approximately -135 degrees, reflecting the angle needed to reach the negative coordinates.

Mock Objects

Entity mockCompanionEntity = mock(Entity.class);

when(mockCompanionEntity.getPosition()).thenReturn(new Vector2(0, 0));

when(mockCompanionEntity.getScale()).thenReturn(new Vector2(1, 1));

EntityPlacementService mockEntityPlacementService = mock(EntityPlacementService.class);

CompanionWeaponType mockWeaponType = CompanionWeaponType.DEATH_POTION; // Use the desired potion type for testing

Contributors

Gaurika Diwan @gaurikadiwan