From c0292842a5cb4b0719d9ca61eefc22d7730a773b Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 30 Aug 2026 12:33:00 -0500 Subject: [PATCH] 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 --- test/CMakeLists.txt | 2 +- test/item/test_inventory.c | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 986b88bf..67450807 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,6 +11,6 @@ add_subdirectory(error) add_subdirectory(thread) add_subdirectory(display) add_subdirectory(rpg) -# add_subdirectory(item) +add_subdirectory(item) add_subdirectory(time) add_subdirectory(util) \ No newline at end of file diff --git a/test/item/test_inventory.c b/test/item/test_inventory.c index 5f41e54e..bfe0d848 100644 --- a/test/item/test_inventory.c +++ b/test/item/test_inventory.c @@ -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));