Test Plan for Inventory Component - UQcsse3200/2024-studio-3 GitHub Wiki

1. Introduction

This test plan outlines the test cases for the InventoryComponent class. The InventoryComponent is responsible for managing a player's inventory in the game, including adding, removing, and manipulating items.

2. Test Objectives

  • Verify the correct initialization of the InventoryComponent
  • Ensure proper handling of inventory capacity
  • Test the addition and removal of items
  • Verify the functionality of item selection
  • Test edge cases and error handling

3. Test Cases

3.1 Initialization Tests

3.1.1 Valid Initialization

  • Test Method: shouldInitialize()
  • Objective: Verify that the InventoryComponent initializes correctly with a valid capacity.
  • Expected Result: The component should initialize with the specified capacity.

3.1.2 Invalid Initialization

  • Test Method: shouldNotInitialize()
  • Objective: Ensure that the InventoryComponent throws an exception when initialized with invalid capacities (0 or negative).
  • Expected Result: An IllegalArgumentException should be thrown with the message "Invalid size parameter. Must be an integer > 0."

3.2 Capacity Management Tests

3.2.1 Set Capacity

  • Test Methods: shouldSetCapacity(), shouldNotSetCapacity()
  • Objective: Verify that the capacity can be set to a valid value and that invalid values are rejected.
  • Expected Result: Valid capacities should be set correctly, while invalid capacities should throw an IllegalArgumentException.

3.2.2 Increase Capacity

  • Test Methods: shouldIncreaseCapacity(), shouldNotIncreaseCapacity(), shouldIncreaseAndKeepExistingItems()
  • Objective: Ensure that the inventory capacity can be increased and that existing items are retained.
  • Expected Result: The capacity should increase when a larger value is provided, and existing items should remain in their positions.

3.3 Item Management Tests

3.3.1 Add Item

  • Test Methods: shouldAddItem(), shouldNotAddItem(), shouldAddItemAt(), shouldAddToFirstSlot()
  • Objective: Verify that items can be added to the inventory correctly, both to the first available slot and to specific positions.
  • Expected Result: Items should be added successfully when the inventory is not full, and adding to a full inventory should be handled gracefully.

3.3.2 Remove Item

  • Test Methods: shouldRemoveAtIndex(), shouldNotRemoveAtNegativeIndex(), shouldNotRemoveAt(), shouldNotRemoveEmptySlot()
  • Objective: Ensure that items can be removed from the inventory correctly and that invalid removals are handled properly.
  • Expected Result: Items should be removed successfully from valid positions, and attempts to remove from invalid positions or empty slots should throw appropriate exceptions.

3.3.3 Find Item

  • Test Methods: shouldFindItem(), shouldNotFindItem()
  • Objective: Verify that the inventory can correctly identify whether it contains a specific item.
  • Expected Result: The find() method should return true for items in the inventory and false for items not in the inventory.

3.4 Inventory State Tests

3.4.1 Empty State

  • Test Methods: shouldBeEmpty(), shouldBeNotEmpty(), shouldBeEmptyAfterRemove()
  • Objective: Verify that the inventory correctly reports its empty/non-empty state.
  • Expected Result: The isEmpty() method should return true when the inventory contains no items and false otherwise.

3.4.2 Full State

  • Test Methods: shouldBeFull(), shouldBeNotFull()
  • Objective: Ensure that the inventory correctly reports when it is full.
  • Expected Result: The isFull() method should return true when the inventory is at capacity and false otherwise.

3.5 Item Selection Tests

3.5.1 Set Selected Item

  • Test Methods: shouldSetSelected(), shouldNotSetSelected()
  • Objective: Verify that the selected item index can be set correctly and that invalid selections are rejected.
  • Expected Result: Valid selections should be set correctly, while invalid selections should throw an IllegalArgumentException.

3.5.2 Get Selected Item

  • Test Method: shouldGetSelectedItem()
  • Objective: Ensure that the correct item is returned when querying the selected item.
  • Expected Result: The getSelectedItem() method should return the item at the selected index or null if the slot is empty.

3.6 Item Retrieval Tests

3.6.1 Get Item at Index

  • Test Methods: shouldGetCorrectItem(), shouldGetNull(), shouldNotGetItemWithNegIndex(), shouldNotGetItemWithInvalidIndex()
  • Objective: Verify that items can be retrieved from specific indices and that invalid indices are handled correctly.
  • Expected Result: Valid indices should return the correct item or null for empty slots, while invalid indices should throw an IllegalArgumentException.

3.6.2 Get First and Last Items

  • Test Methods: firstItemShouldBeNull(), shouldGetFirstItem(), lastItemShouldBeNull(), shouldGetLastItem()
  • Objective: Ensure that the first and last items in the inventory can be retrieved correctly.
  • Expected Result: The methods should return the correct items or null for empty inventories.

3.7 Complex Scenario Tests

3.7.1 Multiple Operations

  • Test Methods: shouldAddMultipleItemsAndRemove(), shouldFillInventoryRemoveAndAddAgain(), shouldIncreaseCapacityAndAdd()
  • Objective: Verify that the inventory behaves correctly under a series of operations including adding, removing, and resizing.
  • Expected Result: The inventory should maintain consistency and correctness throughout multiple operations.

4. Test Execution

All tests should be executed as part of the test suite in InventoryComponentTest.java. The testing framework (JUnit) will report on the success or failure of each test case.

5. Conclusion

This test plan covers the core functionality of the InventoryComponent, including initialization, capacity management, item manipulation, and various edge cases. Successful execution of all test cases will provide confidence in the robustness and correctness of the InventoryComponent implementation.