def test_best_by_edge_no_matches_is_none(): item_a = Electronics(edge=1.0) item_b = Decor(edge=2.0) item_c = Electronics(edge=4.0) item_d = Decor(edge=5.0) item_e = Electronics(edge=3.0) mary = Vendor(inventory=[item_a, item_b, item_c, item_d, item_e]) newest_item = mary.get_best_by_edge("Clothing") assert newest_item is None
def test_best_by_edge(): item_a = Electronics(edge=1.0) item_b = Decor(edge=2.0) item_c = Electronics(edge=4.0) item_d = Decor(edge=5.0) item_e = Electronics(edge=3.0) mary = Vendor(inventory=[item_a, item_b, item_c, item_d, item_e]) newest_item = mary.get_best_by_edge("Electronics") assert newest_item.category == "Electronics" assert newest_item.edge == pytest.approx(1.0)
def test_swap_newest_by_category(): item_a = Decor(age=41) item_b = Electronics(age=32) item_c = Decor(age=28) tanae = Vendor( inventory=[item_a, item_b, item_c] ) item_d = Clothing(age=48) item_e = Decor(age=17) item_f = Clothing(age=23) jenda = Vendor( inventory=[item_d, item_e, item_f] ) result = tanae.swap_newest_by_category( other=jenda, my_priority="Clothing", their_priority="Decor" ) assert result is True assert len(tanae.inventory) is 3 assert len(jenda.inventory) is 3 assert item_c not in tanae.inventory assert item_f in tanae.inventory assert item_f not in jenda.inventory assert item_c in jenda.inventory
def test_items_have_condition_descriptions_that_are_the_same_regardless_of_type( ): # arrange items = [ Clothing(condition=5), Decor(condition=5), Electronics(condition=5) ] # act five_condition_description = items[0].condition_description() # assert assert type(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 type(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_return_true(): item_a = Electronics(condition=3.5, age=7.0) item_b = Item(condition=3.5, age=5.0) item_c = Decor(condition=3.5, age=2.0) jesse = Vendor( inventory=[item_a, item_b, item_c] ) item_d = Item(condition=3.5, age=7.0) item_e = Decor(condition=3.5, age=3.0) item_f = Clothing(condition=3.5, age=9.0) mai = Vendor( inventory=[item_d, item_e, item_f] ) result = jesse.swap_by_newest(mai) assert result is True assert len(mai.inventory) is 3 assert len(jesse.inventory) is 3 assert item_c not in jesse.inventory assert item_a in jesse.inventory assert item_e not in mai.inventory assert item_f in mai.inventory
def test_swap_newest_by_category_no_other_match_is_false(): item_a = Decor() item_b = Electronics() item_c = Decor() tai = Vendor( inventory=[item_c, item_b, item_a] ) item_d = Clothing() item_e = Decor() item_f = Clothing() jesse = Vendor( inventory=[item_f, item_e, item_d] ) result = tai.swap_newest_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(): item_a = Decor(age="Vintage") item_b = Electronics(age="New") item_c = Decor(age="New") tai = Vendor( inventory=[item_a, item_b, item_c] ) item_d = Clothing(age="Vintage") item_e = Decor(age="New") item_f = Clothing(age="New") jesse = Vendor( inventory=[item_d, item_e, item_f] ) result = tai.swap_by_newest( other=jesse, my_priority="Clothing", their_priority="Decor" ) assert result is True assert len(tai.inventory) == 3 assert len(jesse.inventory) == 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_swap_newest_by_category(): item_a = Decor(age=2) item_b = Electronics(age=1) item_c = Decor(age=1) tai = Vendor( inventory=[item_a, item_b, item_c] ) item_d = Clothing(age=2) item_e = Decor(age=3) item_f = Clothing(age=1) jesse = Vendor( inventory=[item_d, item_e, item_f] ) result = tai.swap_newest_by_category( other=jesse, my_priority="Clothing", their_priority="Decor" ) assert 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 not 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_c in jesse.inventory
def test_swap_best_by_category_reordered(): 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="Clothing", their_priority="Decor") assert 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 not 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_c in jesse.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_items_have_condition_as_float(): items = [ Clothing(condition=3.5), Decor(condition=3.5), Electronics(condition=3.5) ] for item in items: assert item.condition == pytest.approx(3.5)
def test_swap_by_newest(): item_a = Clothing(condition=4, age=datetime.datetime(2021, 2, 1)) item_b = Decor(condition=4, age=datetime.datetime(2021, 3, 1)) item_c = Clothing(condition=4, age=datetime.datetime(2021, 4, 1)) item_d = Decor(condition=4, age=datetime.datetime(2021, 5, 1)) item_e = Clothing(condition=4, age=datetime.datetime(2021, 6, 1)) tai = Vendor(inventory=[item_a, item_b, item_c, item_d, item_e]) item_f = Electronics(condition=4, age=datetime.datetime(2021, 4, 1)) item_g = Decor(condition=4, age=datetime.datetime(2021, 3, 1)) item_h = Decor(condition=4, age=datetime.datetime(2021, 8, 1)) item_i = Electronics(condition=4, age=datetime.datetime(2021, 1, 1)) item_j = Clothing(condition=4, age=datetime.datetime(2021, 6, 1)) other_vendor = Vendor(inventory=[item_f, item_g, item_h, item_i, item_j]) tai.swap_by_newest(other_vendor) assert item_e in other_vendor.inventory assert item_h in tai.inventory
def test_get_newest_returns_newest_item(): 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]) result = johannes.get_newest() assert result is item_c
def test_newest_item_with_duplicates(): item_a = Decor(year=1999) item_b = Electronics(year=1970) item_c = Clothing(year=1999) madison = Vendor(inventory=[item_a, item_b, item_c]) newest_item = madison.get_newest_item() assert newest_item.age == 22 assert newest_item.year == 1999
def test_items_have_expected_default_age(): item = Item() clothing = Clothing() decor = Decor() electronics = Electronics() assert item.age == Item.DEFAULT_ITEM_AGE assert clothing.age == Item.DEFAULT_ITEM_AGE assert decor.age == Item.DEFAULT_ITEM_AGE assert electronics.age == Item.DEFAULT_ITEM_AGE
def test_items_can_be_assigned_age(): item = Item(age = 1) clothing = Clothing(age = 1) decor = Decor(age = 1) electronics = Electronics(age = 1) assert item.age == 1 assert clothing.age == 1 assert decor.age == 1 assert electronics.age == 1
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_swap_by_newest_works_with_really_old_items(): item_a = Clothing(age=3857327832) item_b = Decor(age=3758239357346849) item_c = Electronics(age=73728834859649327) johannes = Vendor(inventory=[item_a, item_b, item_c]) item_d = Electronics(age=863993285383268) item_e = Decor(age=869393864386548438) item_f = Clothing(age=94639489) 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_a not in johannes.inventory assert item_f in johannes.inventory assert item_f not in live.inventory assert item_a in live.inventory
def test_swap_by_newest_swaps_first_item_when_all_items_are_same_age(): item_a = Clothing(age=5) item_b = Decor(age=5) item_c = Electronics(age=5) johannes = Vendor(inventory=[item_a, item_b, item_c]) item_d = Electronics(age=5) item_e = Decor(age=5) item_f = Clothing(age=5) 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_a not in johannes.inventory assert item_d in johannes.inventory assert item_d not in live.inventory assert item_a in live.inventory
def test_get_newest_item(): item_a = Clothing(year=2005) item_b = Electronics(year=2002) item_c = Clothing(year=1955) item_d = Decor(year=1982) item_e = Clothing(year=2013) madison = Vendor(inventory=[item_a, item_b, item_c, item_d, item_e]) newest_item = madison.get_newest_item() assert newest_item.year == 2013 assert newest_item.age == 8 assert newest_item.category == "Clothing"
def test_swap_best_by_category_no_other_match2(): item_a = Clothing(condition=2.0) item_b = Decor(condition=4.0) item_c = Clothing(condition=4.0) item_d = Electronics(condition=4.0) tai = Vendor(inventory=[item_a, item_b, item_c]) jesse = Vendor(inventory=[item_d]) result = tai.swap_best_by_category(other=jesse, my_priority="Decor", their_priority="Clothing") assert result is False
def test_get_min_age(): item_a = Decor(condition=3.5) item_b = Electronics(condition=3.5) item_c = Clothing(condition=3.5, age=9.0) item_d = Item(condition=3.5, age=1.0) item_e = Clothing(condition=3.5, age=6.0) kate = Vendor( inventory=[item_a, item_b, item_c, item_d, item_e] ) result = kate.get_min_age() assert result.category == "Electronics" assert result.age == pytest.approx(0.0)
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_swap_by_newest_empty_other_inventory(): item_a = Decor(year=2001) item_b = Electronics(year=1937) item_c = Decor(year=2016) madison = Vendor(inventory=[item_a, item_b, item_c]) jesse = Vendor(inventory=[]) result = madison.swap_by_newest(other_vendor=jesse, ) assert result is False assert len(madison.inventory) is 3 assert len(jesse.inventory) is 0 assert item_a in madison.inventory assert item_b in madison.inventory assert item_c in madison.inventory
def test_swap_by_newest_no_age_is_false(): item_d = Electronics() tai = Vendor(inventory=[item_d]) item_a = Clothing() item_b = Decor() item_c = Clothing() jesse = Vendor(inventory=[item_a, item_b, item_c]) result = tai.swap_by_newest(other=jesse) assert result is False assert len(tai.inventory) is 1 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_by_newest(): item_a = Decor(year=2001) item_b = Electronics(year=1937) item_c = Decor(year=2016) madison = Vendor(inventory=[item_a, item_b, item_c]) item_d = Clothing(year=2018) item_e = Decor(year=1995) item_f = Clothing(year=2019) jesse = Vendor(inventory=[item_d, item_e, item_f]) result = madison.swap_by_newest(other_vendor=jesse, ) assert result is True assert len(madison.inventory) is 3 assert len(jesse.inventory) is 3 assert item_c not in madison.inventory assert item_f in madison.inventory assert item_f not in jesse.inventory assert item_c in jesse.inventory
def test_swap_by_newest(): item_a = Decor(age=2) item_b = Electronics(age=4) item_c = Decor(age=4) tai = Vendor(inventory=[item_a, item_b, item_c]) item_d = Clothing(age=2) item_e = Decor(age=4) item_f = Clothing(age=4) jesse = Vendor(inventory=[item_d, item_e, item_f]) result = tai.swap_by_newest(other=jesse, ) assert result is True assert len(tai.inventory) is 3 assert len(jesse.inventory) is 3 assert item_a not in tai.inventory assert item_d in tai.inventory assert item_d not in jesse.inventory assert item_a in jesse.inventory
def test_swap_by_age(): item_a = Decor(condition=2.0, age=3) item_b = Electronics(condition=4.0, age=2) item_c = Decor(condition=4.0, age=1) tai = Vendor(inventory=[item_a, item_b, item_c]) item_d = Clothing(condition=2.0, age=2) item_e = Decor(condition=4.0, age=1) item_f = Clothing(condition=4.0, age=0) jesse = Vendor(inventory=[item_d, item_e, item_f]) result = tai.swap_by_newest(other=jesse, ) 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_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