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_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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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 
Exemple #6
0
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
Exemple #7
0
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
Exemple #8
0
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
Exemple #9
0
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_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"
Exemple #11
0
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
Exemple #12
0
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)
Exemple #13
0
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
Exemple #14
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_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
Exemple #16
0
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
Exemple #19
0
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
Exemple #20
0
def test_swap_best_by_age():
    item_a = Decor(age=6)
    item_b = Electronics(age=35)
    item_c = Decor(age=2)
    tai = Vendor(inventory=[item_a, item_b, item_c])

    item_d = Clothing(age=5)
    item_e = Decor(age=1)
    item_f = Clothing(age=65)
    jesse = Vendor(inventory=[item_d, item_e, item_f])

    result = tai.swap_best_by_age(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_e in tai.inventory
    assert item_e not in jesse.inventory
    assert item_c in jesse.inventory
Exemple #21
0
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_swap_newest():
    item_a = Clothing(age=0)
    item_b = Decor(age=5)
    item_c = Clothing(age=6)
    sal = Vendor(inventory=[item_a, item_b, item_c])

    item_d = Decor(age=1)
    item_e = Electronics(age=5)
    kary = Vendor(inventory=[item_d, item_e])

    result = sal.swap_newest(kary)

    assert len(sal.inventory) is 3
    assert item_a not in sal.inventory
    assert item_b in sal.inventory
    assert item_d in sal.inventory
    assert len(kary.inventory) is 2
    assert item_d not in kary.inventory
    assert item_e in kary.inventory
    assert item_a in kary.inventory
    assert result is True
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_swap_by_edge():
    item_a = Decor(edge=2.0)
    item_b = Electronics(edge=4.0)
    item_c = Decor(edge=4.0)
    tai = Vendor(inventory=[item_a, item_b, item_c])

    item_d = Clothing(edge=2.0)
    item_e = Decor(edge=4.0)
    item_f = Clothing(edge=4.0)
    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) 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
Exemple #25
0
def test_swap_by_newest():
    item_a = Decor(age=25)
    item_b = Electronics(age=10)
    item_c = Decor(age=4)
    tai = Vendor(inventory=[item_a, item_b, item_c])

    item_d = Clothing(age=17)
    item_e = Decor(age=5)
    item_f = Clothing(age=20)
    jesse = Vendor(inventory=[item_d, item_e, item_f])

    tai_newest = tai.get_newest()
    jesse_newest = jesse.get_newest()
    result = tai.swap_by_newest(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_e in tai.inventory
    assert item_e not in jesse.inventory
    assert item_c in jesse.inventory
Exemple #26
0
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
Exemple #27
0
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
Exemple #28
0
def test_swap_newest_by_category_no_inventory_is_false():
    tai = Vendor(
        inventory=[]
    )

    item_a = Decor(age=2)
    item_b = Electronics(age=1)
    item_c = Decor(age=1)
    jesse = Vendor(
        inventory=[item_a, item_b, item_c]
    )

    result = tai.swap_newest_by_category(
        other=jesse,
        my_priority="Clothing",
        their_priority="Decor"
    )

    assert not result
    assert len(tai.inventory) == 0
    assert len(jesse.inventory) == 3
    assert item_a in jesse.inventory
    assert item_b in jesse.inventory
    assert item_c in jesse.inventory
Exemple #29
0
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
Exemple #30
0
def test_electronics_has_default_category_and_to_str():
    electronics = Electronics()
    assert electronics.category is "Electronics"
    assert str(electronics) == "A gadget full of buttons and secrets."