def test_swap_best_by_category_no_other_match_is_false(): item_a = Decor(condition=2.0) item_b = Electronics(condition=4.0) item_c = Decor(condition=4.0) tai = Vendor(inventory=[item_c, item_b, item_a]) item_d = Clothing(condition=2.0) item_e = Decor(condition=4.0) item_f = Clothing(condition=4.0) jesse = Vendor(inventory=[item_f, item_e, item_d]) result = tai.swap_best_by_category(other=jesse, my_priority="Electronics", their_priority="Decor") assert not result assert len(tai.inventory) == 3 assert len(jesse.inventory) == 3 assert item_a in tai.inventory assert item_b in tai.inventory assert item_c in tai.inventory assert item_d in jesse.inventory assert item_e in jesse.inventory assert item_f in jesse.inventory
def test_swap_by_newest_no_other_match(): item_a = Clothing(age=2) item_b = Decor(age=4) item_c = Clothing(age=4) tai = Vendor( inventory=[item_a, item_b, item_c] ) jesse = Vendor( inventory=[] ) result = tai.swap_by_newest( 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_newest_by_category_no_match_is_false(): tanae = Vendor( inventory=[] ) item_a = Clothing(age=17) item_b = Decor(age=33) item_c = Clothing(age=54) jenda = Vendor( inventory=[item_a, item_b, item_c] ) result = tanae.swap_newest_by_category( other=jenda, my_priority="Clothing", their_priority="Decor" ) assert result is False assert len(tanae.inventory) is 0 assert len(jenda.inventory) is 3 assert item_a in jenda.inventory assert item_b in jenda.inventory assert item_c in jenda.inventory
def test_swap_newest_by_category_no_other_match(): item_a = Clothing(condition=2) item_b = Decor(condition=11) item_c = Clothing(condition=11) tanae = Vendor( inventory=[item_a, item_b, item_c] ) jenda = Vendor( inventory=[] ) result = tanae.swap_newest_by_category( other=jenda, my_priority="Decor", their_priority="Clothing" ) assert result is False assert len(tanae.inventory) is 3 assert len(jenda.inventory) is 0 assert item_a in tanae.inventory assert item_b in tanae.inventory assert item_c in tanae.inventory
def test_swap_best_by_category_no_match_is_false(): tai = Vendor( inventory=[] ) item_a = Clothing(condition=2.0) item_b = Decor(condition=4.0) item_c = Clothing(condition=4.0) jesse = Vendor( inventory=[item_a, item_b, item_c] ) result = tai.swap_best_by_category( other=jesse, my_priority="Clothing", their_priority="Decor" ) assert result is False assert len(tai.inventory) is 0 assert len(jesse.inventory) is 3 assert item_a in jesse.inventory assert item_b in jesse.inventory assert item_c in jesse.inventory
def test_swap_newest_by_category_no_priorities(): item_a = Decor(age=2.0) item_b = Electronics() item_c = Decor(age=4.0) tai = Vendor(inventory=[item_a, item_b, item_c]) item_d = Clothing(age=2.0) item_e = Decor(age=4.0) item_f = Clothing(age=1.0) jesse = Vendor(inventory=[item_d, item_e, item_f]) result = tai.swap_newest_by_category(other=jesse) assert result assert len(tai.inventory) == 3 assert len(jesse.inventory) == 3 assert item_a in tai.inventory assert item_b not in tai.inventory assert item_c in tai.inventory assert item_f in tai.inventory assert item_d in jesse.inventory assert item_e in jesse.inventory assert item_f not in jesse.inventory assert item_b in jesse.inventory
def test_swap_newest_by_category_no_match_is_false(): item_a = Decor(age=2.0) item_b = Electronics(age=4.0) item_c = Decor(age=4.0) tai = Vendor(inventory=[item_a, item_b, item_c]) item_d = Clothing(age=2.0) item_e = Decor(age=4.0) item_f = Clothing(age=4.0) jesse = Vendor(inventory=[item_d, item_e, item_f]) result = tai.swap_newest_by_category(other=jesse, my_priority="Clothing", their_priority="Clothing") assert not result assert len(tai.inventory) == 3 assert len(jesse.inventory) == 3 assert item_a in tai.inventory assert item_b in tai.inventory assert item_c in tai.inventory assert item_d in jesse.inventory assert item_e in jesse.inventory assert item_f in jesse.inventory
def test_swap_by_newest_their_list_is_empty_false(): item_a = Decor(condition=3.5, age=7.0) item_b = Electronics(condition=3.5, age=3.0) item_c = Clothing(condition=3.5, age=9.0) peter = Vendor( inventory=[item_a, item_b, item_c] ) tom = Vendor(inventory=[]) result = peter.swap_by_newest(tom) assert result is False assert len(tom.inventory) is 0 assert len(peter.inventory) is 3
def test_swap_by_newest_my_list_is_empty_return_false(): patrick = Vendor(inventory=[]) item_a = Decor(condition=3.5, age=7.0) item_b = Electronics(condition=3.5, age=3.0) item_c = Clothing(condition=3.5, age=9.0) katrina = Vendor( inventory=[item_a, item_b, item_c] ) result = patrick.swap_by_newest(katrina) assert result is False assert len(patrick.inventory) is 0 assert len(katrina.inventory) is 3
def test_items_have_condition_descriptions_that_are_the_same_regardless_of_type( ): items = [ Clothing(condition=5), Decor(condition=5), Electronics(condition=5) ] five_condition_description = items[0].condition_description() assert isinstance(five_condition_description, str) for item in items: assert item.condition_description() == five_condition_description items[0].condition = 1 one_condition_description = items[0].condition_description() assert isinstance(one_condition_description, str) for item in items: item.condition = 1 assert item.condition_description() == one_condition_description assert one_condition_description != five_condition_description
def test_swap_by_newest(): item_a = Decor(age=2) item_b = Electronics(age=7) item_c = Clothing(age=0.5) johannes = Vendor(inventory=[item_a, item_b, item_c]) item_d = Electronics(age=10) item_e = Decor(age=17) item_f = Electronics(age=1) live = Vendor(inventory=[item_d, item_e, item_f]) result = johannes.swap_by_newest(other=live) assert result is True assert len(johannes.inventory) is 3 assert len(live.inventory) is 3 assert item_c not in johannes.inventory assert item_f in johannes.inventory assert item_f not in live.inventory assert item_c in live.inventory
def test_clothing_has_default_category_and_to_str(): cloth = Clothing() assert cloth.category is "Clothing" assert str(cloth) == "The finest clothing you could wear."
def test_items_have_age_as_float(): items = [Clothing(age=15.0), Decor(age=15.0), Electronics(age=15.0)] for item in items: assert item.age == pytest.approx(15.0)
def test_condition_descriptions_work_for_floats(): items = [Clothing(condition=3.5), Decor(condition=3)] for item in items: assert item.condition_description()
from swap_meet.item import Item from swap_meet.vendor import Vendor from swap_meet.clothing import Clothing from swap_meet.electronics import Electronics from swap_meet.decor import Decor 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") print(best_item)
def test_items_have_age_as_int(): items = [Clothing(age=3), Decor(age=3), Electronics(age=3)] for item in items: assert item.age == pytest.approx(3)