Example #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
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
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
Example #7
0
def test_swap_by_newest_with_duplicates():
    item_a = Clothing(age=2)
    item_d = Clothing(age=2)
    tai = Vendor(inventory=[item_a])
    ta = Vendor(inventory=[item_d])
    is_swap = tai.swap_by_newest(ta)

    assert item_a in ta.inventory
    assert is_swap is not False
Example #8
0
def test_get_min_age():
    item_a = Clothing(age = 1)
    item_b = Clothing(age = 4)
    item_c = Decor(age = 2)
    item_d = Decor(age = 3.5)
    tai = Vendor(inventory = [item_a,item_b,item_c, item_d])
    newest_item = tai.get_min_age()
    
    assert newest_item.age == 1
Example #9
0
def test_get_newest_with_duplicates():
    item_a = Clothing(age=10)
    item_b = Clothing(age=6)
    item_c = Clothing(age=6)
    tai = Vendor(inventory=[item_a, item_b, item_c])

    newest_item = tai.get_newest()

    assert newest_item.age == 6
    assert newest_item == item_b
Example #10
0
def test_newest_by_category_with_duplicates():
    item_a = Clothing(age=2.0)
    item_b = Clothing(age=2.0)
    item_c = Clothing(age=4.0)
    tai = Vendor(inventory=[item_a, item_b, item_c])

    newest_item = tai.get_newest_by_category("Clothing")

    assert newest_item.category == "Clothing"
    assert newest_item.age == pytest.approx(2.0)
Example #11
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_edge_with_duplicates():
    item_a = Clothing(edge=2.0)
    item_b = Clothing(edge=2.0)
    item_c = Clothing(edge=4.0)
    mary = Vendor(inventory=[item_a, item_b, item_c])

    newest_item = mary.get_best_by_edge("Clothing")

    assert newest_item.category == "Clothing"
    assert newest_item.edge == pytest.approx(2.0)
Example #13
0
def test_find_newest_item():
    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])

    newest_item = tai.find_newest_item()

    assert newest_item == item_e
Example #14
0
def test_get_newest():
    item_a = Clothing(age=0)
    item_b = Decor(age=5)
    item_c = Clothing(age=6)
    item_d = Decor(age=2)
    sal = Vendor(inventory=[item_a, item_b, item_c, item_d])

    newest_item = sal.get_newest()

    assert newest_item.category == "Clothing"
    assert newest_item.age == 0
Example #15
0
def test_get_newest():
    item_a = Clothing(age=2)
    item_b = Decor(age=14)
    item_c = Clothing(age=20)
    item_d = Decor(age=5)
    item_e = Clothing(age=85)
    tai = Vendor(inventory=[item_a, item_b, item_c, item_d, item_e])

    best_item = tai.get_newest()

    assert best_item.age == 2
Example #16
0
def test_swap_by_newest_returns_false():
    tai = Vendor(inventory=[])

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

    result = tai.swap_by_newest(jesse)

    assert result is False
Example #17
0
def test_get_by_newest():
    item_a = Clothing(age=2)
    item_b = Decor(age=2)
    item_c = Clothing(age=4)
    item_d = Decor(age=5)
    item_e = Clothing(age=1)
    tai = Vendor(inventory=[item_a, item_b, item_c, item_d, item_e])

    newest_item = tai.get_by_newest()

    # get_by_newest(self, friend)
    assert newest_item == item_e
Example #18
0
def test_get_newest_returns_youngest():
    item_a = Clothing(age=6)
    item_b = Decor(age=2)
    item_c = Clothing(age=1)
    item_d = Decor(age=10)
    item_e = Clothing(age=3)
    tai = Vendor(inventory=[item_a, item_b, item_c, item_d, item_e])

    newest_item = tai.get_newest()

    assert newest_item == item_c
    assert newest_item.age == 1
Example #19
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)
Example #20
0
def test_newest_by_category():
    item_a = Clothing(age=2.0)
    item_b = Decor(age=3.0)
    item_c = Clothing(age=1.0)
    item_d = Decor(age=5.0)
    item_e = Clothing(age=3.0)
    tai = Vendor(inventory=[item_a, item_b, item_c, item_d, item_e])

    newest_item = tai.get_newest_by_category("Clothing")

    assert newest_item.category == "Clothing"
    assert newest_item.age == pytest.approx(1.0)
Example #21
0
def test_newest_by_category_with_duplicates():
    item_a = Clothing(age=9)
    item_b = Clothing(age=6)
    item_c = Clothing(age=6)
    clara = Vendor(
        inventory=[item_a, item_b, item_c]
    )

    best_item = clara.get_newest_by_category("Clothing")

    assert best_item.category == "Clothing"
    assert best_item.age == pytest.approx(6)
def test_get_newest_by_category_with_duplicates():
    item_a = Clothing(age=2)
    item_b = Clothing(age=4)
    item_c = Clothing(age=4)
    tai = Vendor(
        inventory=[item_a, item_b, item_c]
    )

    best_item = tai.get_newest_by_category("Clothing")

    assert best_item.category == "Clothing"
    assert best_item.age == 4
Example #23
0
def test_get_newest():
    item_a = Clothing(age=2)
    item_b = Decor(age=3)
    item_c = Clothing(age=4)
    item_d = Decor(age=5)
    item_e = Clothing(age=3)
    tai = Vendor(inventory=[item_a, item_b, item_c, item_d, item_e])

    newest_item = tai.get_newest()

    assert newest_item.category == "Clothing"
    assert newest_item.age == pytest.approx(2)
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_get_newest_by_category():
    item_a = Clothing(condition=None, age=2)
    item_b = Decor(condition=None, age=2)
    item_c = Clothing(condition=None, age=4)
    item_d = Decor(condition=None, age=5)
    item_e = Clothing(condition=None, age=3)
    tai = Vendor(
        inventory=[item_a, item_b, item_c, item_d, item_e]
    )

    best_item = tai.get_newest_by_category("Clothing")

    assert best_item.category == "Clothing"
    assert best_item.age == 4
Example #26
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
Example #27
0
def test_newest_by_category():
    item_a = Clothing(age=17)
    item_b = Decor(age=23)
    item_c = Clothing(age=45)
    item_d = Decor(age=56)
    item_e = Clothing(age=37)
    clara = Vendor(
        inventory=[item_a, item_b, item_c, item_d, item_e]
    )

    best_item = clara.get_newest_by_category("Clothing")

    assert best_item.category == "Clothing"
    assert best_item.age == pytest.approx(17)
Example #28
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)
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
Example #30
0
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