Test Plan: CombatStatsComponentTests - UQcsse3200/2024-studio-2 GitHub Wiki

Objective

To ensure the functionality and correctness of the CombatStatsComponent class, focusing on various attributes such as health, hunger, strength, defense, speed, and experience. The aim is to validate that the component properly handles setting, adding, and bounding these attributes.

Test Coverage

  1. Health Management

    • Test Case: shouldSetGetHealth
      • Purpose: Verify that the health is set and retrieved correctly, adhering to minimum and maximum constraints.
      • Steps:
        1. Initialize CombatStatsComponent with default health values.
        2. Set health to various values including within, below, and above the allowed range.
        3. Verify health is capped at maximum and minimum values.
        4. Confirm that setting health within bounds is accurate.
      • Verification:
        • Check that health values are correctly bounded and retrieved.
  2. Death Status

    • Test Case: shouldCheckIsDead
      • Purpose: Ensure the isDead status accurately reflects the health status.
      • Steps:
        1. Initialize CombatStatsComponent with non-zero health.
        2. Set health to zero and verify isDead() returns true.
      • Verification:
        • Verify isDead() reflects the correct status based on health.
  3. Hunger Management

    • Test Case: shouldSetHungerWithinBounds

      • Purpose: Validate that hunger is set correctly within specified bounds.
      • Steps:
        1. Initialize CombatStatsComponent with default hunger values.
        2. Set hunger to various values including above and below bounds.
        3. Confirm hunger values adhere to the allowed range.
      • Verification:
        • Ensure hunger is capped at maximum and minimum values.
    • Test Case: shouldAddHungerWithCap

      • Purpose: Check that adding hunger respects the maximum and minimum bounds.
      • Steps:
        1. Initialize CombatStatsComponent.
        2. Add and subtract hunger values and verify hunger does not exceed bounds.
      • Verification:
        • Confirm hunger is within acceptable limits after addition.
  4. Strength Management

    • Test Case: shouldSetStrength

      • Purpose: Verify strength is set and retrieved correctly, adhering to minimum and maximum constraints.
      • Steps:
        1. Initialize CombatStatsComponent with default strength values.
        2. Set strength to various values including within, below, and above the allowed range.
      • Verification:
        • Ensure strength values are capped and set correctly.
    • Test Case: shouldAddStrength

      • Purpose: Ensure that adding strength respects the minimum constraint.
      • Steps:
        1. Initialize CombatStatsComponent.
        2. Add and subtract strength values and verify strength does not drop below zero.
      • Verification:
        • Check that strength is correctly updated and bounded.
  5. Defense Management

    • Test Case: shouldSetDefense

      • Purpose: Confirm that defence is set and retrieved correctly for constraints.
      • Steps:
        1. Initialize CombatStatsComponent with default defence values.
        2. Set defence to various values including within, below, and above bounds.
      • Verification:
        • Verify defence is correctly set and bounded.
    • Test Case: shouldAddDefense

      • Purpose: Ensure adding defence respects the minimum constraint.
      • Steps:
        1. Initialize CombatStatsComponent.
        2. Add and subtract defence values and verify defence does not drop below zero.
      • Verification:
        • Confirm that defense is correctly updated and bounded.
  6. Speed Management

    • Test Case: shouldSetSpeed

      • Purpose: Verify that speed is set and retrieved correctly, adhering to minimum and maximum constraints.
      • Steps:
        1. Initialize CombatStatsComponent with default speed values.
        2. Set speed to various values including within, below, and above the allowed range.
      • Verification:
        • Ensure speed values are capped and set correctly.
    • Test Case: shouldAddSpeed

      • Purpose: Check that adding speed respects the minimum constraint.
      • Steps:
        1. Initialize CombatStatsComponent.
        2. Add and subtract speed values and verify speed does not drop below zero.
      • Verification:
        • Confirm speed is correctly updated and bounded.
  7. Experience Management

    • Test Case: shouldSetExperienceAndHandleOverflow

      • Purpose: Verify that experience is set correctly and handles overflow as expected.
      • Steps:
        1. Initialize CombatStatsComponent with default experience values.
        2. Set experience to values that exceed and fall below bounds.
        3. Verify experience respects overflow and underflow constraints.
      • Verification:
        • Check that experience is correctly capped and updated.
    • Test Case: shouldAddExperienceWithOverflow

      • Purpose: Ensure adding experience respects overflow constraints and updates correctly.
      • Steps:
        1. Initialize CombatStatsComponent.
        2. Add and subtract experience values and verify experience respects overflow limits.
      • Verification:
        • Confirm experience is correctly updated and bounded.
  8. Leveling Up

    • Test Case: shouldLevelUpAndIncreaseStats

      • Purpose: Validate that levelling up increases stats correctly when experience is gained.
      • Steps:
        1. Initialize CombatStatsComponent with specific values.
        2. Add experience to trigger a level-up.
        3. Verify that stats (health, strength, defense, speed) are increased as expected.
      • Verification:
        • Ensure stats increase correctly and experience is adjusted.
    • Test Case: shouldLevelUpAndIncreaseStats2

      • Purpose: Verify stats increase correctly with experience overflow beyond the maximum.
      • Steps:
        1. Initialize CombatStatsComponent.
        2. Set experience to a value that causes level-up.
        3. Check the updated stats to ensure correct increment.
      • Verification:
        • Confirm stats increase appropriately and experience is managed.
    • Test Case: shouldNotLevelUpAndIncreaseStats

      • Purpose: Ensure that if levelling up is not allowed, stats remain unchanged despite experience gain.
      • Steps:
        1. Initialize CombatStatsComponent with levelling disabled.
        2. Add experience and verify no stats are increased.
      • Verification:
        • Confirm that stats remain unchanged when levelling is disabled.

Testing Methodology

  • Unit Testing: Verification of individual methods of CombatStatsComponent to ensure correct behaviour.
  • Integration Testing: Testing of interactions between CombatStatsComponent and other game components to ensure proper integration.
  • Automated Testing: Usage of automated tests to verify component behaviour and catch regressions.

Conclusion

By following this test plan, we ensure that the CombatStatsComponent class performs as expected, handling health, hunger, strength, defense, speed, and experience appropriately. The plan aims to deliver a reliable and robust component, integral to the game's combat system.