KeyboardInputComponent - UQcsse3200/2024-studio-3 GitHub Wiki
Test Environment
- Framework: JUnit 5
- Objects Used: KeyboardPlayerInputComponent, Entity (mocked), EventHandler (mocked)
Test Cases - Testing KeyboardPlayerInputComponent Methods
-
Component Initialisation Objective: To verify that the KeyboardPlayerInputComponent is properly initialised and linked with the Entity and its EventHandler. Purpose: Ensure the component is set up correctly to handle key inputs and trigger corresponding events. Expected Results: The KeyboardPlayerInputComponent is not null after initialisation. The Entity and its EventHandler are properly mocked and linked with the input component.
-
Triggering Interaction Objective: To verify that pressing the "E" key triggers the "interact" event. Purpose: Ensure that interaction is correctly handled when the player presses the interaction key. Expected Results: After pressing the "E" key, the "interact" event should be triggered exactly once.
-
Triggering Walk Up Objective: To verify that pressing the "W" key triggers the "walk" event with the correct vector for upward movement. Purpose: Ensure that the player character correctly moves up when the "W" key is pressed. Expected Results: After pressing the "W" key, the "walk" event should be triggered exactly once with the vector (0, 1).
-
Triggering Walk Left Objective: To verify that pressing the "A" key triggers the "walk" event with the correct vector for leftward movement. Purpose: Ensure that the player character correctly moves left when the "A" key is pressed. Expected Results: After pressing the "A" key, the "walk" event should be triggered exactly once with the vector (-1.0f, 0.0f).
-
Triggering Walk Down Objective: To verify that pressing the "S" key triggers the "walk" event with the correct vector for downward movement. Purpose: Ensure that the player character correctly moves down when the "S" key is pressed. Expected Results: After pressing the "S" key, the "walk" event should be triggered exactly once with the vector (0.0f, -1.0f).
-
Triggering Walk Right Objective: To verify that pressing the "D" key triggers the "walk" event with the correct vector for rightward movement. Purpose: Ensure that the player character correctly moves right when the "D" key is pressed. Expected Results: After pressing the "D" key, the "walk" event should be triggered exactly once with the vector (1.0f, 0.0f).
-
Stopping Movement on Button Release Objective: To verify that releasing a movement key triggers the "walkStop" event. Purpose: Ensure that the player character stops moving when the key is released. Expected Results: After pressing and releasing the "W" key, the "walkStop" event should be triggered. After pressing and releasing the "A" key, the "walkStop" event should be triggered twice in total (once for "W" and once for "A").