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:
+1
-1
@@ -11,6 +11,6 @@ add_subdirectory(error)
|
|||||||
add_subdirectory(thread)
|
add_subdirectory(thread)
|
||||||
add_subdirectory(display)
|
add_subdirectory(display)
|
||||||
add_subdirectory(rpg)
|
add_subdirectory(rpg)
|
||||||
# add_subdirectory(item)
|
add_subdirectory(item)
|
||||||
add_subdirectory(time)
|
add_subdirectory(time)
|
||||||
add_subdirectory(util)
|
add_subdirectory(util)
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "dusktest.h"
|
#include "dusktest.h"
|
||||||
#include "item/inventory.h"
|
#include "rpg/item/inventory.h"
|
||||||
|
|
||||||
static void test_inventoryInit(void **state) {
|
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[1].item, ITEM_ID_POTATO);
|
||||||
assert_int_equal(inventory.storage[2].item, ITEM_ID_POTION);
|
assert_int_equal(inventory.storage[2].item, ITEM_ID_POTION);
|
||||||
|
|
||||||
// Sort by type
|
// Sort by type ascending - POTION (MEDICINE) sorts before POTATO/APPLE
|
||||||
inventorySort(&inventory, INVENTORY_SORT_BY_ID, false);
|
// (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[0].item, ITEM_ID_POTION);
|
||||||
assert_int_equal(inventory.storage[1].item, ITEM_ID_POTATO);
|
assert_true(
|
||||||
assert_int_equal(inventory.storage[2].item, ITEM_ID_APPLE);
|
(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
|
// Sort by type reverse - FOOD items first (order unspecified), POTION last.
|
||||||
inventorySort(&inventory, INVENTORY_SORT_BY_ID, true);
|
inventorySort(&inventory, INVENTORY_SORT_BY_TYPE, true);
|
||||||
assert_int_equal(inventory.storage[0].item, ITEM_ID_APPLE);
|
|
||||||
assert_int_equal(inventory.storage[1].item, ITEM_ID_POTATO);
|
|
||||||
assert_int_equal(inventory.storage[2].item, ITEM_ID_POTION);
|
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
|
// Should fail when given NULL inventory pointer
|
||||||
expect_assert_failure(inventorySort(NULL, INVENTORY_SORT_BY_ID, false));
|
expect_assert_failure(inventorySort(NULL, INVENTORY_SORT_BY_ID, false));
|
||||||
|
|||||||
Reference in New Issue
Block a user