from engine.item import ItemInstance from engine.world import World def make_world(): return World() def test_ground_items_at_is_empty_by_default(): world = make_world() assert world.ground_items_at("field", 3, 4, 0) == [] def test_drop_item_at_makes_it_visible_at_that_tile(): world = make_world() item = ItemInstance("item-1", "bandage") world.drop_item_at("field", 3, 4, 0, item) assert world.ground_items_at("field", 3, 4, 0) == [item] def test_drop_item_at_floors_fractional_coordinates(): world = make_world() item = ItemInstance("item-1", "bandage") world.drop_item_at("field", 3.9, 4.2, 0.0, item) assert world.ground_items_at("field", 3, 4, 0) == [item] def test_multiple_items_can_stack_on_the_same_tile(): world = make_world() a = ItemInstance("item-1", "bandage") b = ItemInstance("item-2", "sealant") world.drop_item_at("field", 3, 4, 0, a) world.drop_item_at("field", 3, 4, 0, b) assert world.ground_items_at("field", 3, 4, 0) == [a, b] def test_different_tiles_are_independent(): world = make_world() item = ItemInstance("item-1", "bandage") world.drop_item_at("field", 3, 4, 0, item) assert world.ground_items_at("field", 3, 5, 0) == [] assert world.ground_items_at("other_map", 3, 4, 0) == [] def test_remove_ground_item_removes_and_returns_the_matching_item(): world = make_world() a = ItemInstance("item-1", "bandage") b = ItemInstance("item-2", "sealant") world.drop_item_at("field", 3, 4, 0, a) world.drop_item_at("field", 3, 4, 0, b) removed = world.remove_ground_item("field", 3, 4, 0, "item-1") assert removed is a assert world.ground_items_at("field", 3, 4, 0) == [b] def test_remove_ground_item_returns_none_when_not_found(): world = make_world() world.drop_item_at("field", 3, 4, 0, ItemInstance("item-1", "bandage")) assert world.remove_ground_item("field", 3, 4, 0, "no-such-id") is None def test_remove_last_item_cleans_up_the_empty_tile_entry(): world = make_world() world.drop_item_at("field", 3, 4, 0, ItemInstance("item-1", "bandage")) world.remove_ground_item("field", 3, 4, 0, "item-1") assert ("field", 3, 4, 0) not in world.ground_items