Improve sorting
This commit is contained in:
@@ -326,7 +326,7 @@ static void test_inventoryItemFull(void **state) {
|
||||
inventory.storageSize = 2;
|
||||
}
|
||||
|
||||
static void test_inventorySortById(void **state) {
|
||||
static void test_inventorySort(void **state) {
|
||||
(void)state;
|
||||
|
||||
inventorystack_t storage[5];
|
||||
@@ -339,24 +339,42 @@ static void test_inventorySortById(void **state) {
|
||||
inventorySet(&inventory, ITEM_ID_POTION, 2);
|
||||
|
||||
// Sort by ID
|
||||
inventorySortById(&inventory);
|
||||
inventorySort(&inventory, INVENTORY_SORT_BY_ID, false);
|
||||
|
||||
// Check order
|
||||
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);
|
||||
|
||||
// Sort by ID 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);
|
||||
assert_int_equal(inventory.storage[2].item, ITEM_ID_POTION);
|
||||
|
||||
// Sort by type
|
||||
inventorySort(&inventory, INVENTORY_SORT_BY_ID, 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);
|
||||
|
||||
// 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);
|
||||
assert_int_equal(inventory.storage[2].item, ITEM_ID_POTION);
|
||||
|
||||
// Should fail when given NULL inventory pointer
|
||||
expect_assert_failure(inventorySortById(NULL));
|
||||
expect_assert_failure(inventorySort(NULL, INVENTORY_SORT_BY_ID, false));
|
||||
|
||||
// Should fail when given NULL storage pointer
|
||||
inventory.storage = NULL;
|
||||
expect_assert_failure(inventorySortById(&inventory));
|
||||
expect_assert_failure(inventorySort(&inventory, INVENTORY_SORT_BY_ID, false));
|
||||
inventory.storage = storage;
|
||||
|
||||
// Should fail when given zero storage size
|
||||
inventory.storageSize = 0;
|
||||
expect_assert_failure(inventorySortById(&inventory));
|
||||
expect_assert_failure(inventorySort(&inventory, INVENTORY_SORT_BY_ID, false));
|
||||
inventory.storageSize = 5;
|
||||
}
|
||||
|
||||
@@ -370,7 +388,7 @@ int main(int argc, char** argv) {
|
||||
cmocka_unit_test(test_inventoryGetCount),
|
||||
cmocka_unit_test(test_inventoryIsFull),
|
||||
cmocka_unit_test(test_inventoryItemFull),
|
||||
cmocka_unit_test(test_inventorySortById)
|
||||
cmocka_unit_test(test_inventorySort),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
Reference in New Issue
Block a user