Test Plan for KeyMapping - UQcsse3200/2024-studio-1 GitHub Wiki

Objective:

The goal is to verify that the KeyMapping class is correctly handling default key bindings, allowing custom key bindings, and modifying the key map.


Test Cases:

1. Test Case: Verify Default Walk Key Mappings

  • Description: Verify that the default key mappings for walking are set correctly when the class is initialized.
  • Steps:
    1. Initialize the KeyMapping class.
    2. Retrieve the default key map.
    3. Assert that the correct key bindings are set for walking (W, A, S, D).
  • Expected Result: The default key bindings should map W to WALK_UP, A to WALK_LEFT, D to WALK_RIGHT, and S to WALK_DOWN.

2. Test Case: Verify Default Shoot Key Mappings

  • Description: Verify that the default key mappings for shooting are set correctly.
  • Steps:
    1. Initialize the KeyMapping class.
    2. Retrieve the default key map.
    3. Assert that the correct key bindings are set for shooting (Arrow keys).
  • Expected Result: The default key bindings should map the arrow keys (LEFT, UP, RIGHT, DOWN) to shooting directions.

3. Test Case: Verify Default Item Key Mappings

  • Description: Verify that the default key bindings for item usage are set correctly (e.g., Space for melee, numbers for item usage).
  • Steps:
    1. Initialize the KeyMapping class.
    2. Retrieve the default key map.
    3. Assert that the correct key bindings are set for items (Space for melee, numbers 1-3 for item usage).
  • Expected Result: Space should be mapped to MELEE, and numbers 1, 2, 3 should be mapped to USE_1, USE_2, and USE_3.

4. Test Case: Set and Verify Custom Key Binding

  • Description: Verify that a custom key binding can be set and is correctly reflected in the key map.
  • Steps:
    1. Initialize the KeyMapping class.
    2. Set a custom key binding for a new key (e.g., number 4).
    3. Retrieve the updated key map.
    4. Assert that the custom key binding has been set correctly.
  • Expected Result: Number 4 should be mapped to the new key binding (e.g., USE_4).

5. Test Case: Verify Custom Key Mapping

  • Description: Verify that a custom key mapping is returned correctly after setting it.
  • Steps:
    1. Initialize the KeyMapping class.
    2. Set a custom key binding for an unused key (e.g., F1).
    3. Retrieve the updated key map.
    4. Assert that the custom key binding is reflected in the key map.
  • Expected Result: F1 should be mapped to the new key binding (e.g., SHOOT_UP).

6. Test Case: Modify Existing Key Binding

  • Description: Verify that modifying an existing key binding updates the key map correctly.
  • Steps:
    1. Initialize the KeyMapping class.
    2. Set a key binding for a key (e.g., number 4).
    3. Modify the key binding for the same key.
    4. Retrieve the updated key map.
    5. Assert that the key binding has been updated, and the old binding no longer exists.
  • Expected Result: Number 4 should reflect the modified key binding (e.g., from USE_4 to WALK_UP), and the old binding should no longer be present.

Testing Environment:

  • Unit Testing Framework: JUnit 5 (Jupiter)
  • Extensions: GameExtension for LibGDX-related tests
  • Assertions: Use assertEquals and assertNotEquals to verify correct key bindings.

Conclusion:

This test plan covers both the verification of default key bindings and the functionality of setting and modifying custom key mappings in the KeyMapping class.