def test_removing_not_found_is_false(): item = "item to remove" vendor = Vendor(inventory=["a", "b", "c"]) result = vendor.remove(item) assert len(vendor.inventory) is 3 assert result is False
def test_adding_to_inventory(): vendor = Vendor() item = "new item" result = vendor.add(item) assert len(vendor.inventory) is 1 assert item in vendor.inventory assert result is item
def test_removing_from_inventory_returns_item(): item = "item to remove" vendor = Vendor(inventory=["a", "b", "c", item]) result = vendor.remove(item) assert len(vendor.inventory) is 3 assert item not in vendor.inventory assert result is item
def test_best_by_category_no_matches_is_none(): item_a = Decor(condition=2.0) item_b = Decor(condition=2.0) item_c = Decor(condition=4.0) tai = Vendor(inventory=[item_a, item_b, item_c]) best_item = tai.get_best_by_category("Electronics") assert best_item is None
def test_get_no_matching_items_by_category(): item_a = Item(category="clothing") item_b = Item(category="clothing") item_c = Item(category="clothing") vendor = Vendor(inventory=[item_a, item_b, item_c]) items = vendor.get_by_category("electronics") assert len(items) is 0
def test_best_by_category_with_duplicates(): item_a = Clothing(condition=2.0) item_b = Clothing(condition=4.0) item_c = Clothing(condition=4.0) tai = Vendor(inventory=[item_a, item_b, item_c]) best_item = tai.get_best_by_category("Clothing") assert best_item.category == "Clothing" assert best_item.condition == pytest.approx(4.0)
def test_best_by_category(): item_a = Clothing(condition=2.0) item_b = Decor(condition=2.0) item_c = Clothing(condition=4.0) item_d = Decor(condition=5.0) item_e = Clothing(condition=3.0) tai = Vendor(inventory=[item_a, item_b, item_c, item_d, item_e]) best_item = tai.get_best_by_category("Clothing") assert best_item.category == "Clothing" assert best_item.condition == pytest.approx(4.0)
def test_get_items_by_category(): item_a = Item(category="clothing") item_b = Item(category="electronics") item_c = Item(category="clothing") vendor = Vendor(inventory=[item_a, item_b, item_c]) items = vendor.get_by_category("clothing") assert len(items) is 2 assert item_a in items assert item_c in items assert item_b not in items
def test_vendor_takes_optional_inventory(): inventory = ["a", "b", "c"] vendor = Vendor(inventory=inventory) assert len(vendor.inventory) is 3 assert "a" in inventory assert "b" in inventory assert "c" in inventory
def test_swap_best_by_category_no_other_match(): item_a = Clothing(condition=2.0) item_b = Decor(condition=4.0) item_c = Clothing(condition=4.0) tai = Vendor(inventory=[item_a, item_b, item_c]) jesse = Vendor(inventory=[]) result = tai.swap_best_by_category(other=jesse, my_priority="Decor", their_priority="Clothing") assert result is False assert len(tai.inventory) is 3 assert len(jesse.inventory) is 0 assert item_a in tai.inventory assert item_b in tai.inventory assert item_c in tai.inventory
def test_swap_best_by_category(): item_a = Decor(condition=2.0) item_b = Electronics(condition=4.0) item_c = Decor(condition=4.0) tai = Vendor(inventory=[item_a, item_b, item_c]) item_d = Clothing(condition=2.0) item_e = Decor(condition=4.0) item_f = Clothing(condition=4.0) jesse = Vendor(inventory=[item_d, item_e, item_f]) result = tai.swap_best_by_category(other=jesse, my_priority="Clothing", their_priority="Decor") assert result is True assert len(tai.inventory) is 3 assert len(jesse.inventory) is 3 assert item_c not in tai.inventory assert item_f in tai.inventory assert item_f not in jesse.inventory assert item_c in jesse.inventory
def test_vendor_has_inventory(): vendor = Vendor() assert len(vendor.inventory) is 0