Fix stale include re-enabling test/item, fix dead sort-by-type coverage

test/item/test_inventory.c was disabled via a commented-out
add_subdirectory(item) with no explanation - the actual cause was a stale
"item/inventory.h" include left over from before the rpg/ reorg (real path
is rpg/item/inventory.h). The current inventory.h/.c API it tests hasn't
drifted; only the include path had rotted.

Also fixes a copy-paste bug in test_inventorySort: the "sort by type"
assertions were calling INVENTORY_SORT_BY_ID again instead of
INVENTORY_SORT_BY_TYPE, so inventorySortByType/Reverse had zero real
coverage. Asserts on type grouping only (not the tied FOOD-vs-FOOD order),
since the underlying sort() is qsort and not stable.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-30 12:33:00 -05:00
parent 717902462b
commit c0292842a5
2 changed files with 20 additions and 10 deletions
+19 -9
View File
@@ -6,7 +6,7 @@
*/
#include "dusktest.h"
#include "item/inventory.h"
#include "rpg/item/inventory.h"
static void test_inventoryInit(void **state) {
@@ -352,17 +352,27 @@ static void test_inventorySort(void **state) {
assert_int_equal(inventory.storage[1].item, ITEM_ID_POTATO);
assert_int_equal(inventory.storage[2].item, ITEM_ID_POTION);
// Sort by type
inventorySort(&inventory, INVENTORY_SORT_BY_ID, false);
// Sort by type ascending - POTION (MEDICINE) sorts before POTATO/APPLE
// (both FOOD). The two FOOD items compare equal, so their relative order
// isn't guaranteed (qsort is not stable) - only the type grouping is.
inventorySort(&inventory, INVENTORY_SORT_BY_TYPE, false);
assert_int_equal(inventory.storage[0].item, ITEM_ID_POTION);
assert_int_equal(inventory.storage[1].item, ITEM_ID_POTATO);
assert_int_equal(inventory.storage[2].item, ITEM_ID_APPLE);
assert_true(
(inventory.storage[1].item == ITEM_ID_POTATO &&
inventory.storage[2].item == ITEM_ID_APPLE) ||
(inventory.storage[1].item == ITEM_ID_APPLE &&
inventory.storage[2].item == ITEM_ID_POTATO)
);
// Sort by type reverse
inventorySort(&inventory, INVENTORY_SORT_BY_ID, true);
assert_int_equal(inventory.storage[0].item, ITEM_ID_APPLE);
assert_int_equal(inventory.storage[1].item, ITEM_ID_POTATO);
// Sort by type reverse - FOOD items first (order unspecified), POTION last.
inventorySort(&inventory, INVENTORY_SORT_BY_TYPE, true);
assert_int_equal(inventory.storage[2].item, ITEM_ID_POTION);
assert_true(
(inventory.storage[0].item == ITEM_ID_POTATO &&
inventory.storage[1].item == ITEM_ID_APPLE) ||
(inventory.storage[0].item == ITEM_ID_APPLE &&
inventory.storage[1].item == ITEM_ID_POTATO)
);
// Should fail when given NULL inventory pointer
expect_assert_failure(inventorySort(NULL, INVENTORY_SORT_BY_ID, false));