From 97f9ff417497e98bd412211eaff032c3450b08c4 Mon Sep 17 00:00:00 2001 From: Melley Gebretatios Date: Tue, 4 Oct 2022 11:00:18 -0400 Subject: [PATCH 01/17] pass test wave 1 --- swap_meet/vendor.py | 18 +++++++++++++++++- tests/unit_tests/test_wave_01.py | 15 +++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..1693391e8 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,18 @@ class Vendor: - pass \ No newline at end of file + def __init__(self, inventory=None): + inventory = inventory if inventory is not None else [] + self.inventory = inventory + + def add(self, item): + self.inventory.append(item) + return item + + def remove(self, item): + if item in self.inventory: + self.inventory.remove(item) + return item + else: + return False + + + diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index 58478ccf9..cac53f26d 100644 --- a/tests/unit_tests/test_wave_01.py +++ b/tests/unit_tests/test_wave_01.py @@ -2,12 +2,12 @@ import pytest from swap_meet.vendor import Vendor -@pytest.mark.skip +#@pytest.mark.skip def test_vendor_has_inventory(): vendor = Vendor() assert len(vendor.inventory) == 0 -@pytest.mark.skip +#@pytest.mark.skip def test_vendor_takes_optional_inventory(): inventory = ["a", "b", "c"] vendor = Vendor(inventory=inventory) @@ -16,7 +16,7 @@ def test_vendor_takes_optional_inventory(): assert "b" in vendor.inventory assert "c" in vendor.inventory -@pytest.mark.skip +#@pytest.mark.skip def test_adding_to_inventory(): vendor = Vendor() item = "new item" @@ -27,7 +27,7 @@ def test_adding_to_inventory(): assert item in vendor.inventory assert result == item -@pytest.mark.skip +#@pytest.mark.skip def test_removing_from_inventory_returns_item(): item = "item to remove" vendor = Vendor( @@ -40,7 +40,7 @@ def test_removing_from_inventory_returns_item(): assert item not in vendor.inventory assert result == item -@pytest.mark.skip +#@pytest.mark.skip def test_removing_not_found_is_false(): item = "item to remove" vendor = Vendor( @@ -48,8 +48,11 @@ def test_removing_not_found_is_false(): ) result = vendor.remove(item) + + assert len(vendor.inventory) == 3 + assert not result # assert False - raise Exception("Complete this test according to comments below.") + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* From fd4c0944521a6dc5bf84de1594c8e8ba5436990f Mon Sep 17 00:00:00 2001 From: Anaiq <> Date: Tue, 4 Oct 2022 10:27:39 -0500 Subject: [PATCH 02/17] commited out skip on test wave 1 --- tests/unit_tests/test_wave_01.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index 58478ccf9..0bba25cd9 100644 --- a/tests/unit_tests/test_wave_01.py +++ b/tests/unit_tests/test_wave_01.py @@ -2,12 +2,12 @@ import pytest from swap_meet.vendor import Vendor -@pytest.mark.skip +# @pytest.mark.skip def test_vendor_has_inventory(): vendor = Vendor() assert len(vendor.inventory) == 0 -@pytest.mark.skip +# @pytest.mark.skip def test_vendor_takes_optional_inventory(): inventory = ["a", "b", "c"] vendor = Vendor(inventory=inventory) @@ -16,7 +16,7 @@ def test_vendor_takes_optional_inventory(): assert "b" in vendor.inventory assert "c" in vendor.inventory -@pytest.mark.skip +# @pytest.mark.skip def test_adding_to_inventory(): vendor = Vendor() item = "new item" @@ -27,7 +27,7 @@ def test_adding_to_inventory(): assert item in vendor.inventory assert result == item -@pytest.mark.skip +# @pytest.mark.skip def test_removing_from_inventory_returns_item(): item = "item to remove" vendor = Vendor( @@ -40,7 +40,7 @@ def test_removing_from_inventory_returns_item(): assert item not in vendor.inventory assert result == item -@pytest.mark.skip +# @pytest.mark.skip def test_removing_not_found_is_false(): item = "item to remove" vendor = Vendor( @@ -53,3 +53,4 @@ def test_removing_not_found_is_false(): # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* + \ No newline at end of file From 20b4c50e25dae076b66539b48ea20cf59264ec08 Mon Sep 17 00:00:00 2001 From: Anaiq <> Date: Tue, 4 Oct 2022 10:30:36 -0500 Subject: [PATCH 03/17] commiting vendor.py --- swap_meet/vendor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..0bca6d46d 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,3 @@ class Vendor: - pass \ No newline at end of file + pass + From 0440e368232f79950e34c5dce67fee77f33cf44e Mon Sep 17 00:00:00 2001 From: Melley Gebretatios Date: Tue, 4 Oct 2022 12:13:27 -0400 Subject: [PATCH 04/17] tests pass wave 2, adde d vendor method and item attribute. --- swap_meet/item.py | 5 ++++- swap_meet/vendor.py | 9 +++++++-- tests/unit_tests/test_wave_02.py | 9 +++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 560d759c2..284c48771 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,5 @@ class Item: - pass \ No newline at end of file + + def __init__(self, category=""): + self.category = category + diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 1693391e8..07b2c6adc 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -14,5 +14,10 @@ def remove(self, item): else: return False - - + def get_by_category(self, category=""): + items = [] + for item in self.inventory: + if item.category == category: + items.append(item) + + return items \ No newline at end of file diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index 3d7060d7c..348997b24 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -2,12 +2,12 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +# @pytest.mark.skip def test_items_have_blank_default_category(): item = Item() assert item.category == "" -@pytest.mark.skip +# @pytest.mark.skip def test_get_items_by_category(): item_a = Item(category="clothing") item_b = Item(category="electronics") @@ -23,7 +23,7 @@ def test_get_items_by_category(): assert item_c in items assert item_b not in items -@pytest.mark.skip +# @pytest.mark.skip def test_get_no_matching_items_by_category(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -34,7 +34,8 @@ def test_get_no_matching_items_by_category(): items = vendor.get_by_category("electronics") - raise Exception("Complete this test according to comments below.") + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* + assert len(items) == 0 \ No newline at end of file From c484fb5e688408790b2d9725334f9e013569df5c Mon Sep 17 00:00:00 2001 From: Anaiq <> Date: Tue, 4 Oct 2022 11:17:36 -0500 Subject: [PATCH 05/17] item and test_wave 2 changes --- swap_meet/item.py | 7 ++++++- tests/unit_tests/test_wave_02.py | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 560d759c2..c0e8fcb20 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,7 @@ class Item: - pass \ No newline at end of file + + def __init__(self, category=""): + self.category = category + + def __str__(self): + return f"Hello World!" \ No newline at end of file diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index 3d7060d7c..c3122e8da 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -2,12 +2,12 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +# pytest.mark.skip def test_items_have_blank_default_category(): item = Item() assert item.category == "" -@pytest.mark.skip +# @pytest.mark.skip def test_get_items_by_category(): item_a = Item(category="clothing") item_b = Item(category="electronics") @@ -23,7 +23,7 @@ def test_get_items_by_category(): assert item_c in items assert item_b not in items -@pytest.mark.skip +# @pytest.mark.skip def test_get_no_matching_items_by_category(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -34,7 +34,11 @@ def test_get_no_matching_items_by_category(): items = vendor.get_by_category("electronics") - raise Exception("Complete this test according to comments below.") + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* + assert len(items) == 0 + assert item_a not in items + assert item_c not in items + assert item_b not in items \ No newline at end of file From 9a67a4b2ed87383543f6f548090ff4d0d332ef33 Mon Sep 17 00:00:00 2001 From: Melley Gebretatios Date: Tue, 4 Oct 2022 15:50:22 -0400 Subject: [PATCH 06/17] Wave 3 all tests pass and added swap items to vendor.py and stringify. --- swap_meet/item.py | 3 +++ swap_meet/vendor.py | 15 ++++++++++++++- tests/unit_tests/test_wave_03.py | 12 ++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 284c48771..0ce86a072 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -3,3 +3,6 @@ class Item: def __init__(self, category=""): self.category = category + def __str__(self): + return f"Hello World!" + \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 07b2c6adc..849ab30c9 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -20,4 +20,17 @@ def get_by_category(self, category=""): if item.category == category: items.append(item) - return items \ No newline at end of file + return items + + + def swap_items(self, vendor_friend, my_item, their_item): + if my_item not in self.inventory or their_item not in vendor_friend.inventory: + return False + + self.inventory.remove(my_item) + vendor_friend.inventory.append(my_item) + + vendor_friend.inventory.remove(their_item) + self.inventory.append(their_item) + return True + diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 0300b638f..720879a7c 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -2,7 +2,7 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +#@pytest.mark.skip def test_item_overrides_to_string(): item = Item() @@ -10,7 +10,7 @@ def test_item_overrides_to_string(): assert stringified_item == "Hello World!" -@pytest.mark.skip +#@pytest.mark.skip def test_swap_items_returns_true(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -38,7 +38,7 @@ def test_swap_items_returns_true(): assert item_b in jolie.inventory assert result -@pytest.mark.skip +#@pytest.mark.skip def test_swap_items_when_my_item_is_missing_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -65,7 +65,7 @@ def test_swap_items_when_my_item_is_missing_returns_false(): assert item_e in jolie.inventory assert not result -@pytest.mark.skip +#@pytest.mark.skip def test_swap_items_when_their_item_is_missing_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -92,7 +92,7 @@ def test_swap_items_when_their_item_is_missing_returns_false(): assert item_e in jolie.inventory assert not result -@pytest.mark.skip +#@pytest.mark.skip def test_swap_items_from_my_empty_returns_false(): fatimah = Vendor( inventory=[] @@ -112,7 +112,7 @@ def test_swap_items_from_my_empty_returns_false(): assert len(jolie.inventory) == 2 assert not result -@pytest.mark.skip +#@pytest.mark.skip def test_swap_items_from_their_empty_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") From 1f52e523f1823e25efe2ef5b8bd9f6cc77ca8649 Mon Sep 17 00:00:00 2001 From: Anaiq <> Date: Tue, 4 Oct 2022 14:53:00 -0500 Subject: [PATCH 07/17] updated wave_3 --- tests/unit_tests/test_wave_03.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 0300b638f..2d573fa52 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -2,7 +2,7 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +# @pytest.mark.skip def test_item_overrides_to_string(): item = Item() @@ -10,7 +10,7 @@ def test_item_overrides_to_string(): assert stringified_item == "Hello World!" -@pytest.mark.skip +# @pytest.mark.skip def test_swap_items_returns_true(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -38,7 +38,7 @@ def test_swap_items_returns_true(): assert item_b in jolie.inventory assert result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_items_when_my_item_is_missing_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -65,7 +65,7 @@ def test_swap_items_when_my_item_is_missing_returns_false(): assert item_e in jolie.inventory assert not result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_items_when_their_item_is_missing_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -92,7 +92,7 @@ def test_swap_items_when_their_item_is_missing_returns_false(): assert item_e in jolie.inventory assert not result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_items_from_my_empty_returns_false(): fatimah = Vendor( inventory=[] @@ -112,7 +112,7 @@ def test_swap_items_from_my_empty_returns_false(): assert len(jolie.inventory) == 2 assert not result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_items_from_their_empty_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") From f0fe840f754dbe7b6deb00dbbc9b9050da281f16 Mon Sep 17 00:00:00 2001 From: Melley Gebretatios Date: Tue, 4 Oct 2022 16:27:55 -0400 Subject: [PATCH 08/17] Test wave 4 pass addedd first swap item. --- swap_meet/vendor.py | 14 ++++++++++++++ tests/unit_tests/test_wave_04.py | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 849ab30c9..fdd35bd0c 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -34,3 +34,17 @@ def swap_items(self, vendor_friend, my_item, their_item): self.inventory.append(their_item) return True + def swap_first_item(self, vendor_friend): + if self.inventory == [] or vendor_friend.inventory == []: + return False + + my_first_item = self.inventory[0] + their_first_item = vendor_friend.inventory[0] + + self.inventory.remove(my_first_item) + self.inventory.append(their_first_item) + + vendor_friend.inventory.remove(their_first_item) + vendor_friend.inventory.append(my_first_item) + + return True \ No newline at end of file diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index 8190a4ebb..4ef21ff8e 100644 --- a/tests/unit_tests/test_wave_04.py +++ b/tests/unit_tests/test_wave_04.py @@ -2,7 +2,7 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +# @pytest.mark.skip def test_swap_first_item_returns_true(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -30,7 +30,7 @@ def test_swap_first_item_returns_true(): assert item_a in jolie.inventory assert result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_first_item_from_my_empty_returns_false(): fatimah = Vendor( inventory=[] @@ -48,7 +48,7 @@ def test_swap_first_item_from_my_empty_returns_false(): assert len(jolie.inventory) == 2 assert not result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_first_item_from_their_empty_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") From 19209653142fee5934816c1ea8641b6546c29e02 Mon Sep 17 00:00:00 2001 From: Anaiq <> Date: Tue, 4 Oct 2022 15:30:54 -0500 Subject: [PATCH 09/17] modified wave_4 --- tests/unit_tests/test_wave_04.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index 8190a4ebb..4ef21ff8e 100644 --- a/tests/unit_tests/test_wave_04.py +++ b/tests/unit_tests/test_wave_04.py @@ -2,7 +2,7 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +# @pytest.mark.skip def test_swap_first_item_returns_true(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -30,7 +30,7 @@ def test_swap_first_item_returns_true(): assert item_a in jolie.inventory assert result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_first_item_from_my_empty_returns_false(): fatimah = Vendor( inventory=[] @@ -48,7 +48,7 @@ def test_swap_first_item_from_my_empty_returns_false(): assert len(jolie.inventory) == 2 assert not result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_first_item_from_their_empty_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") From be3ef090d896c05e22885028095899a982c18883 Mon Sep 17 00:00:00 2001 From: Anaiq <> Date: Wed, 5 Oct 2022 11:26:23 -0500 Subject: [PATCH 10/17] completed clothing, decor, elecronics, item, integration tests 1-3 pass, wave 5 all pass, add assert back to wave 1- all pass --- swap_meet/clothing.py | 11 +++++++++-- swap_meet/decor.py | 11 +++++++++-- swap_meet/electronics.py | 11 +++++++++-- swap_meet/item.py | 17 ++++++++++++++--- tests/integration_tests/test_wave_01_02_03.py | 2 +- tests/unit_tests/test_wave_01.py | 3 ++- tests/unit_tests/test_wave_05.py | 10 +++++----- 7 files changed, 49 insertions(+), 16 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..1729c471a 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,9 @@ -class Clothing: - pass \ No newline at end of file +from swap_meet.item import Item + +class Clothing(Item): + + def __init__(self, condition =0): + super().__init__(category="Clothing", condition=condition) + + def __str__(self): + return f"The finest clothing you could wear." diff --git a/swap_meet/decor.py b/swap_meet/decor.py index eab7a9dbe..cc0cd6581 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,9 @@ -class Decor: - pass \ No newline at end of file +from swap_meet.item import Item + +class Decor(Item): + + def __init__(self, condition=0): + super().__init__(category="Decor", condition=condition) + + def __str__(self): + return f'Something to decorate your space.' diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2f9dff68a..820c81727 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,9 @@ -class Electronics: - pass +from swap_meet.item import Item + +class Electronics(Item): + + def __init__(self,condition=0): + super().__init__(category="Electronics", condition=condition) + + def __str__(self): + return f"A gadget full of buttons and secrets." diff --git a/swap_meet/item.py b/swap_meet/item.py index 2e3b3fe0f..526dfcfcb 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,8 +1,19 @@ class Item: - def __init__(self, category=""): + def __init__(self, category="", condition=0): self.category = category - + self.condition = condition + def __str__(self): return f"Hello World!" - + + def condition_description(self): + conditions = { + 0: "You don't want this.", + 1: "Anything is cheap enough.", + 2: "It's OK.", + 3: "No major issues.", + 4: "Hardly worn and well taken care of.", + 5: "Gonna go fast!" + } + return f"{conditions[self.condition]}" \ No newline at end of file diff --git a/tests/integration_tests/test_wave_01_02_03.py b/tests/integration_tests/test_wave_01_02_03.py index 9912414da..25707d998 100644 --- a/tests/integration_tests/test_wave_01_02_03.py +++ b/tests/integration_tests/test_wave_01_02_03.py @@ -2,7 +2,7 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +# @pytest.mark.skip @pytest.mark.integration_test def test_integration_wave_01_02_03(): # make a vendor diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index 682c845bb..41c5d66d3 100644 --- a/tests/unit_tests/test_wave_01.py +++ b/tests/unit_tests/test_wave_01.py @@ -49,7 +49,8 @@ def test_removing_not_found_is_false(): result = vendor.remove(item) - raise Exception("Complete this test according to comments below.") + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* + assert not result \ No newline at end of file diff --git a/tests/unit_tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py index 7abea06cd..fdeb063a9 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -3,25 +3,25 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip +# @pytest.mark.skip def test_clothing_has_default_category_and_to_str(): cloth = Clothing() assert cloth.category == "Clothing" assert str(cloth) == "The finest clothing you could wear." -@pytest.mark.skip +# @pytest.mark.skip def test_decor_has_default_category_and_to_str(): decor = Decor() assert decor.category == "Decor" assert str(decor) == "Something to decorate your space." -@pytest.mark.skip +# @pytest.mark.skip def test_electronics_has_default_category_and_to_str(): electronics = Electronics() assert electronics.category == "Electronics" assert str(electronics) == "A gadget full of buttons and secrets." -@pytest.mark.skip +# @pytest.mark.skip def test_items_have_condition_as_float(): items = [ Clothing(condition=3.5), @@ -31,7 +31,7 @@ def test_items_have_condition_as_float(): for item in items: assert item.condition == pytest.approx(3.5) -@pytest.mark.skip +# @pytest.mark.skip def test_items_have_condition_descriptions_that_are_the_same_regardless_of_type(): items = [ Clothing(condition=5), From 9cddf46d2bc1b041b229901842e99f97e430c842 Mon Sep 17 00:00:00 2001 From: Anaiq <> Date: Wed, 5 Oct 2022 16:50:58 -0500 Subject: [PATCH 11/17] started wave_6 for vendor.py --- swap_meet/vendor.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index fdd35bd0c..9a48cac78 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -47,4 +47,28 @@ def swap_first_item(self, vendor_friend): vendor_friend.inventory.remove(their_first_item) vendor_friend.inventory.append(my_first_item) - return True \ No newline at end of file + return True + +# # WAVE 6 +# def get_by_category(self,category=""): +# ... +# list_of_items = [] +# if True: +# for item in self.inventory: +# self.inventory.remove(item) +# else: +# return False +# return True + +# def get_best_category(self): +# ... + # list = get_by_category() + # create a variable to hold the item with the best condition using max function(in the list, key=condition) + # acces each items? + + + +# ***helper function*** +def find_best_item(): + ... + \ No newline at end of file From 32f10f849b9d86a44be3cea5dc87c5a8d395eb73 Mon Sep 17 00:00:00 2001 From: Melley Gebretatios Date: Wed, 5 Oct 2022 17:52:27 -0400 Subject: [PATCH 12/17] All tests pass in wave 5. --- swap_meet/clothing.py | 13 ++++++++++-- swap_meet/decor.py | 13 ++++++++++-- swap_meet/electronics.py | 12 +++++++++-- swap_meet/item.py | 21 ++++++++++++++++++- swap_meet/vendor.py | 4 +++- tests/integration_tests/test_wave_01_02_03.py | 2 +- tests/unit_tests/test_wave_03.py | 1 + tests/unit_tests/test_wave_05.py | 10 ++++----- 8 files changed, 62 insertions(+), 14 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..cb6b9f2b3 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,11 @@ -class Clothing: - pass \ No newline at end of file +from swap_meet.item import Item +class Clothing(Item): + + # instantiate a class: this is where __init__ and attributes go + def __init__(self, condition=0): + super().__init__(category="Clothing", condition=condition) + + def __str__(self): + return f"The finest clothing you could wear." + + diff --git a/swap_meet/decor.py b/swap_meet/decor.py index eab7a9dbe..26cef0639 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,11 @@ -class Decor: - pass \ No newline at end of file +from swap_meet.item import Item +class Decor(Item): + + def __init__(self, condition=0): + super().__init__(category="Decor", condition=condition) + + def __str__(self): + return f"Something to decorate your space." + + + \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2f9dff68a..34f6efdb6 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,10 @@ -class Electronics: - pass +from swap_meet.item import Item +class Electronics(Item): + + def __init__(self, condition=0): + super().__init__(category="Electronics", condition=condition) + + def __str__(self): + return f"A gadget full of buttons and secrets." + + diff --git a/swap_meet/item.py b/swap_meet/item.py index 0ce86a072..457aea08b 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,8 +1,27 @@ class Item: - def __init__(self, category=""): + def __init__(self, category="", condition=0): self.category = category + self.condition = condition def __str__(self): return f"Hello World!" + + def condition_description(self): + conditions = { + 0: "You don't want this.", + 1: "Anything is cheap enough.", + 2: "It's OK", + 3: "No major issues", + 4: "Hardly worn and well taken care of.", + 5: "Gonna go fast!" + } + + return f"{conditions[self.condition]}" + + + + + + \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index fdd35bd0c..ba370d02a 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -47,4 +47,6 @@ def swap_first_item(self, vendor_friend): vendor_friend.inventory.remove(their_first_item) vendor_friend.inventory.append(my_first_item) - return True \ No newline at end of file + return True + + \ No newline at end of file diff --git a/tests/integration_tests/test_wave_01_02_03.py b/tests/integration_tests/test_wave_01_02_03.py index 9912414da..25707d998 100644 --- a/tests/integration_tests/test_wave_01_02_03.py +++ b/tests/integration_tests/test_wave_01_02_03.py @@ -2,7 +2,7 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +# @pytest.mark.skip @pytest.mark.integration_test def test_integration_wave_01_02_03(): # make a vendor diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 720879a7c..7977629c2 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -1,3 +1,4 @@ +from unicodedata import category import pytest from swap_meet.vendor import Vendor from swap_meet.item import Item diff --git a/tests/unit_tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py index 7abea06cd..fdeb063a9 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -3,25 +3,25 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip +# @pytest.mark.skip def test_clothing_has_default_category_and_to_str(): cloth = Clothing() assert cloth.category == "Clothing" assert str(cloth) == "The finest clothing you could wear." -@pytest.mark.skip +# @pytest.mark.skip def test_decor_has_default_category_and_to_str(): decor = Decor() assert decor.category == "Decor" assert str(decor) == "Something to decorate your space." -@pytest.mark.skip +# @pytest.mark.skip def test_electronics_has_default_category_and_to_str(): electronics = Electronics() assert electronics.category == "Electronics" assert str(electronics) == "A gadget full of buttons and secrets." -@pytest.mark.skip +# @pytest.mark.skip def test_items_have_condition_as_float(): items = [ Clothing(condition=3.5), @@ -31,7 +31,7 @@ def test_items_have_condition_as_float(): for item in items: assert item.condition == pytest.approx(3.5) -@pytest.mark.skip +# @pytest.mark.skip def test_items_have_condition_descriptions_that_are_the_same_regardless_of_type(): items = [ Clothing(condition=5), From 0378b2240b5de56941f540786db08c84dd2977c5 Mon Sep 17 00:00:00 2001 From: Anaiq <> Date: Wed, 5 Oct 2022 19:04:20 -0500 Subject: [PATCH 13/17] pseudocode for both wave_6 methods, created helper_method to get best_item, implemented get_best_by_category, no tests passing --- swap_meet/vendor.py | 64 +++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index d4abd6589..48e31d124 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -50,26 +50,56 @@ def swap_first_item(self, vendor_friend): return True # # WAVE 6 -# def get_by_category(self,category=""): -# ... -# list_of_items = [] -# if True: -# for item in self.inventory: -# self.inventory.remove(item) -# else: -# return False -# return True +# + def get_best_by_category(self, category=""): + # if no items in self.inventory that matches: return None + if len(self.inventory) == 0: + return None + + list_of_category_items = self.get_by_category(self, category=category) #BUG HERE + + # get the item with the best condition in a certain category (the most most appearing category) + # 1. i.e. find best condition + # 2. make sure it's a certain category + best_item_in_category_list = self.find_best_item(list_of_category_items) + + # loop through self.inventory list to find the item with best condition AND matching category + for item in self.inventory: + if item == best_item_in_category_list: + return item + + return None + -# def get_best_category(self): -# ... - # list = get_by_category() - # create a variable to hold the item with the best condition using max function(in the list, key=condition) - # acces each items? + def swap_best_by_category(self, other, my_priority, their_priority):#swaps the best item of certain categories with other_vendor + """ + other, which represents another Vendor instance to trade with + my_priority, which represents a category that the Vendor wants to receive + their_priority, which represents a category that other wants to receive + """ + + # best item in self.inventory that matches their_priority is SWAPPED with the best item in other_vendor inventory that matches my_priority + # 1.my_priority + # 2.their_priority + # 3.find the best item in self.inventory that matches their_priority **can call get_best_by_category here** + # 3b. if no match:returns False + # 4.find the best item in other_vendor.inventory that matches their_priority **can call get_best_by_category here** + # 4.b. if no match:returns False + # 5. swap the best items + # : can we call swap_items(): here so that swap_best_by_category and swap_first_item can use it??? + # return True + ... + # ***helper functions*** + def find_best_item(self, category_or_invetory_list): #??? + if len(category_or_invetory_list) == 0: + return None -# ***helper function*** -def find_best_item(): - ... + best_item = category_or_invetory_list[0] + for item in category_or_invetory_list: + if item.condition > best_item.condition: + best_item.condition = item.condition + return best_item \ No newline at end of file From a63fd96861a44fbcd8aa3b4054be2fa29f2d340b Mon Sep 17 00:00:00 2001 From: Anaiq <> Date: Wed, 5 Oct 2022 23:36:51 -0500 Subject: [PATCH 14/17] changed item condition dict to list, started wave6, unskipped tests wave 6 --- swap_meet/item.py | 27 +++++++---- swap_meet/vendor.py | 79 ++++++++++++-------------------- tests/unit_tests/test_wave_06.py | 2 +- 3 files changed, 50 insertions(+), 58 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index e6b236626..812454b87 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -8,12 +8,23 @@ def __str__(self): return f"Hello World!" def condition_description(self): - conditions = { - 0: "You don't want this.", - 1: "Anything is cheap enough.", - 2: "It's OK.", - 3: "No major issues.", - 4: "Hardly worn and well taken care of.", - 5: "Gonna go fast!" - } + # conditions = { + # 0: "You don't want this.", + # 1: "Anything is cheap enough.", + # 2: "It's OK.", + # 3: "No major issues.", + # 4: "Hardly worn and well taken care of.", + # 5: "Gonna go fast!" + # } + # return f"{conditions[self.condition]}" + + conditions = [ + "You don't want this.", + "Anything is cheap enough.", + "It's OK.", + "No major issues.", + "Hardly worn and well taken care of.", + "Gonna go fast!" + ] + return f"{conditions[self.condition]}" diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 48e31d124..5215559b1 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -49,57 +49,38 @@ def swap_first_item(self, vendor_friend): return True -# # WAVE 6 -# - def get_best_by_category(self, category=""): - # if no items in self.inventory that matches: return None - if len(self.inventory) == 0: - return None +# WAVE 6 + def get_best_by_category(self, category): + print(self.inventory) + # search self.inventory for list of items with specific category + list_of_items = self.get_by_category(category) + print(list_of_items) - list_of_category_items = self.get_by_category(self, category=category) #BUG HERE + # search list of items for highest condition + best_condition = list_of_items[0] + for item in list_of_items: + ... - # get the item with the best condition in a certain category (the most most appearing category) - # 1. i.e. find best condition - # 2. make sure it's a certain category - best_item_in_category_list = self.find_best_item(list_of_category_items) - - # loop through self.inventory list to find the item with best condition AND matching category - for item in self.inventory: - if item == best_item_in_category_list: - return item - - return None + # if item found, return item + # if item not found, return None - def swap_best_by_category(self, other, my_priority, their_priority):#swaps the best item of certain categories with other_vendor - """ - other, which represents another Vendor instance to trade with - my_priority, which represents a category that the Vendor wants to receive - their_priority, which represents a category that other wants to receive - """ +# def swap_best_by_category(self, other, my_priority, their_priority):#swaps the best item of certain categories with other_vendor +# """ +# other, which represents another Vendor instance to trade with +# my_priority, which represents a category that the Vendor wants to receive +# their_priority, which represents a category that other wants to receive +# """ - # best item in self.inventory that matches their_priority is SWAPPED with the best item in other_vendor inventory that matches my_priority - # 1.my_priority - # 2.their_priority - # 3.find the best item in self.inventory that matches their_priority **can call get_best_by_category here** - # 3b. if no match:returns False - # 4.find the best item in other_vendor.inventory that matches their_priority **can call get_best_by_category here** - # 4.b. if no match:returns False - # 5. swap the best items - # : can we call swap_items(): here so that swap_best_by_category and swap_first_item can use it??? - - # return True - ... - - # ***helper functions*** - def find_best_item(self, category_or_invetory_list): #??? - if len(category_or_invetory_list) == 0: - return None - - best_item = category_or_invetory_list[0] - for item in category_or_invetory_list: - if item.condition > best_item.condition: - best_item.condition = item.condition - - return best_item - \ No newline at end of file +# # best item in self.inventory that matches their_priority is SWAPPED with the best item in other_vendor inventory that matches my_priority +# # 1.my_priority +# # 2.their_priority +# # 3.find the best item in self.inventory that matches their_priority **can call get_best_by_category here** +# # 3b. if no match:returns False +# # 4.find the best item in other_vendor.inventory that matches their_priority **can call get_best_by_category here** +# # 4.b. if no match:returns False +# # 5. swap the best items +# # : can we call swap_items(): here so that swap_best_by_category and swap_first_item can use it??? + +# # return True +# ... \ No newline at end of file diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 1f7065ab4..b7ce084d2 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -4,7 +4,7 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip +# @pytest.mark.skip def test_best_by_category(): item_a = Clothing(condition=2.0) item_b = Decor(condition=2.0) From 3ab563f82d9b7242c806e69b3c61cd60a03820bb Mon Sep 17 00:00:00 2001 From: Anaiq <> Date: Thu, 6 Oct 2022 08:47:42 -0500 Subject: [PATCH 15/17] completed get_best_by_category wave 6, updated item.py, unskipped tests test_wave_06 --- swap_meet/item.py | 27 ++++++------------ swap_meet/vendor.py | 48 +++++++++++++++++++++----------- tests/unit_tests/test_wave_06.py | 19 ++++++++++--- 3 files changed, 54 insertions(+), 40 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 812454b87..e6b236626 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -8,23 +8,12 @@ def __str__(self): return f"Hello World!" def condition_description(self): - # conditions = { - # 0: "You don't want this.", - # 1: "Anything is cheap enough.", - # 2: "It's OK.", - # 3: "No major issues.", - # 4: "Hardly worn and well taken care of.", - # 5: "Gonna go fast!" - # } - # return f"{conditions[self.condition]}" - - conditions = [ - "You don't want this.", - "Anything is cheap enough.", - "It's OK.", - "No major issues.", - "Hardly worn and well taken care of.", - "Gonna go fast!" - ] - + conditions = { + 0: "You don't want this.", + 1: "Anything is cheap enough.", + 2: "It's OK.", + 3: "No major issues.", + 4: "Hardly worn and well taken care of.", + 5: "Gonna go fast!" + } return f"{conditions[self.condition]}" diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 5215559b1..fe3b12d2a 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -51,26 +51,28 @@ def swap_first_item(self, vendor_friend): # WAVE 6 def get_best_by_category(self, category): - print(self.inventory) - # search self.inventory for list of items with specific category list_of_items = self.get_by_category(category) - print(list_of_items) + if not list_of_items: + return None + else: + best_item = max(list_of_items, key = lambda item: item.condition) - # search list of items for highest condition - best_condition = list_of_items[0] - for item in list_of_items: - ... + return best_item - # if item found, return item - # if item not found, return None + def swap_best_by_category(self, other, my_priority, their_priority):#swaps the best item of certain categories with other_vendor + + # if their_priority not in self.inventory or my_priority not in other.inventory: + # return False + + best_item = max(self.inventory, key = lambda item: item.condition) + print(f"best item: {best_item}") + # self.inventory.remove(my_item) + # vendor_friend.inventory.append(my_item) -# def swap_best_by_category(self, other, my_priority, their_priority):#swaps the best item of certain categories with other_vendor -# """ -# other, which represents another Vendor instance to trade with -# my_priority, which represents a category that the Vendor wants to receive -# their_priority, which represents a category that other wants to receive -# """ + # vendor_friend.inventory.remove(their_item) + # self.inventory.append(their_item) + # return True # # best item in self.inventory that matches their_priority is SWAPPED with the best item in other_vendor inventory that matches my_priority # # 1.my_priority @@ -81,6 +83,18 @@ def get_best_by_category(self, category): # # 4.b. if no match:returns False # # 5. swap the best items # # : can we call swap_items(): here so that swap_best_by_category and swap_first_item can use it??? + +# ... + + # # helper_function + # def get_best_item(self, list_of_items): + # if not list_of_items: + # return None + + # best_item = list_of_items[0] + + # for item in list_of_items: + # if item.condition > best_item.condition: + # best_item = item -# # return True -# ... \ No newline at end of file + # return best_item diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index b7ce084d2..07a9c480a 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -20,7 +20,7 @@ def test_best_by_category(): assert best_item.category == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip +# @pytest.mark.skip def test_best_by_category_no_matches_is_none(): item_a = Decor(condition=2.0) item_b = Decor(condition=2.0) @@ -33,7 +33,7 @@ def test_best_by_category_no_matches_is_none(): assert best_item is None -@pytest.mark.skip +# @pytest.mark.skip def test_best_by_category_with_duplicates(): # Arrange item_a = Clothing(condition=2.0) @@ -50,7 +50,7 @@ def test_best_by_category_with_duplicates(): assert best_item.category == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category(): # Arrange # me @@ -76,14 +76,25 @@ def test_swap_best_by_category(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* # Assertions should check: # - That the results is truthy + assert result # - That tai and jesse's inventories are the correct length + assert len(tai.inventory) == 3 + assert len(tai.inventory) == 3 + # - That all the correct items are in tai and jesse's inventories, including the items which were swapped from one vendor to the other + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_f in tai.inventory + assert item_e in jesse.inventory + assert item_d in jesse.inventory + assert item_c in jesse.inventory + @pytest.mark.skip def test_swap_best_by_category_reordered(): From 825392ce663a092a9928957f3fcde017b63dbffc Mon Sep 17 00:00:00 2001 From: Melley Gebretatios Date: Thu, 6 Oct 2022 10:06:38 -0400 Subject: [PATCH 16/17] Part of wave 6 done --- swap_meet/vendor.py | 94 +++++++++++++++++++++++++------- tests/unit_tests/test_wave_06.py | 26 ++++----- 2 files changed, 86 insertions(+), 34 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index d4abd6589..4ce516492 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,3 +1,6 @@ +from nis import cat + + class Vendor: def __init__(self, inventory=None): inventory = inventory if inventory is not None else [] @@ -50,26 +53,75 @@ def swap_first_item(self, vendor_friend): return True # # WAVE 6 -# def get_by_category(self,category=""): -# ... -# list_of_items = [] -# if True: -# for item in self.inventory: -# self.inventory.remove(item) -# else: -# return False -# return True - -# def get_best_category(self): -# ... - # list = get_by_category() - # create a variable to hold the item with the best condition using max function(in the list, key=condition) - # acces each items? - - - -# ***helper function*** -def find_best_item(): - ... +# + def get_best_by_category(self, category): # we need to put only category since they have passed 'clothing' in the test + # if no items in self.inventory that matches: return None + # if len(self.inventory) == 0: + # return None + + #list_of_category_items = self.get_by_category(self, category=category) #BUG HERE + + # get the item with the best condition in a certain category (the most most appearing category) + # 1. i.e. find best condition + # 2. make sure it's a certain category + #best_item_in_category_list = self.find_best_item(list_of_category_items) + + # create a new list, check if category is in the inventory or not + # if yes, append item + # if the created list is empty, return None + # loop through self.inventory list to find the item with best condition AND matching category + # for item in self.inventory: + # if item == best_item_in_category_list: + # return item + + # return None + + category_list = [] + for item in self.inventory: + if item.category == category: + category_list.append(item) + if category_list == []: + return None + return max(category_list, key=lambda item: item.condition) + + #best_item_in_category_list = self.find_best_item(list_of_category_items) + + def swap_best_by_category(self, other, my_priority, their_priority):#swaps the best item of certain categories with other_vendor + + their_priority_item = other.get_best_by_category(my_priority) + my_priority_item = self.get_best_by_category(their_priority) + return self.swap_items(other, my_priority_item, their_priority_item) + """ + other, which represents another Vendor instance to trade with + my_priority, which represents a category that the Vendor wants to receive + their_priority, which represents a category that other wants to receive + """ + + # best item in self.inventory that matches their_priority is SWAPPED with the best item in other_vendor inventory that matches my_priority + # 1.my_priority + # 2.their_priority + # 3.find the best item in self.inventory that matches their_priority **can call get_best_by_category here** + # 3b. if no match:returns False + # 4.find the best item in other_vendor.inventory that matches their_priority **can call get_best_by_category here** + # 4.b. if no match:returns False + # 5. swap the best items + # : can we call swap_items(): here so that swap_best_by_category and swap_first_item can use it??? + + # return True + ... + + # ***helper functions*** + # def find_best_item(self, category_or_invetory_list): #??? + # if len(category_or_invetory_list) == 0: + # return None + + # best_item = category_or_invetory_list[0] + # for item in category_or_invetory_list: + # if item.condition > best_item.condition: + # best_item.condition = item.condition + + # return best_item + + \ No newline at end of file diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 1f7065ab4..3e0b4ba64 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -4,7 +4,7 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip +# @pytest.mark.skip def test_best_by_category(): item_a = Clothing(condition=2.0) item_b = Decor(condition=2.0) @@ -20,7 +20,7 @@ def test_best_by_category(): assert best_item.category == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip +# @pytest.mark.skip def test_best_by_category_no_matches_is_none(): item_a = Decor(condition=2.0) item_b = Decor(condition=2.0) @@ -33,7 +33,7 @@ def test_best_by_category_no_matches_is_none(): assert best_item is None -@pytest.mark.skip +# @pytest.mark.skip def test_best_by_category_with_duplicates(): # Arrange item_a = Clothing(condition=2.0) @@ -50,7 +50,7 @@ def test_best_by_category_with_duplicates(): assert best_item.category == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category(): # Arrange # me @@ -76,7 +76,7 @@ def test_swap_best_by_category(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -85,7 +85,7 @@ def test_swap_best_by_category(): # - That tai and jesse's inventories are the correct length # - That all the correct items are in tai and jesse's inventories, including the items which were swapped from one vendor to the other -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_reordered(): # Arrange item_a = Decor(condition=2.0) @@ -109,7 +109,7 @@ def test_swap_best_by_category_reordered(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -118,7 +118,7 @@ def test_swap_best_by_category_reordered(): # - That tai and jesse's inventories are the correct length # - That all the correct items are in tai and jesse's inventories, and that the items that were swapped are not there -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_inventory_is_false(): tai = Vendor( inventory=[] @@ -144,7 +144,7 @@ def test_swap_best_by_category_no_inventory_is_false(): assert item_b in jesse.inventory assert item_c in jesse.inventory -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_other_inventory_is_false(): item_a = Clothing(condition=2.0) item_b = Decor(condition=4.0) @@ -170,7 +170,7 @@ def test_swap_best_by_category_no_other_inventory_is_false(): assert item_b in tai.inventory assert item_c in tai.inventory -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -194,7 +194,7 @@ def test_swap_best_by_category_no_match_is_false(): their_priority="Clothing" ) - raise Exception("Complete this test according to comments below.") + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -203,7 +203,7 @@ def test_swap_best_by_category_no_match_is_false(): # - That tai and jesse's inventories are the correct length # - That all the correct items are in tai and jesse's inventories -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -227,7 +227,7 @@ def test_swap_best_by_category_no_other_match_is_false(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* From c90149af6376cc9fa27e24313b2f0a64b2d7efe9 Mon Sep 17 00:00:00 2001 From: Anaiq <> Date: Thu, 6 Oct 2022 09:50:40 -0500 Subject: [PATCH 17/17] all unit tests and integration tests completed and pass, finished vendor.py wave 6 --- swap_meet/vendor.py | 44 ++++---------- tests/integration_tests/test_wave_04_05_06.py | 2 +- tests/unit_tests/test_wave_06.py | 59 ++++++++++++------- 3 files changed, 49 insertions(+), 56 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 579c0eb5c..7721a1e1e 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -62,40 +62,16 @@ def get_best_by_category(self, category): return best_item - def swap_best_by_category(self, other, my_priority, their_priority):#swaps the best item of certain categories with other_vendor - + def swap_best_by_category(self, other, my_priority, their_priority): + if not self.inventory or not other.inventory: + return False + their_priority_item = other.get_best_by_category(my_priority) - my_priority_item = self.get_best_by_category(their_priority) - return self.swap_items(other, my_priority_item, their_priority_item) - """ - other, which represents another Vendor instance to trade with - my_priority, which represents a category that the Vendor wants to receive - their_priority, which represents a category that other wants to receive - """ - - # best item in self.inventory that matches their_priority is SWAPPED with the best item in other_vendor inventory that matches my_priority - # 1.my_priority - # 2.their_priority - # 3.find the best item in self.inventory that matches their_priority **can call get_best_by_category here** - # 3b. if no match:returns False - # 4.find the best item in other_vendor.inventory that matches their_priority **can call get_best_by_category here** - # 4.b. if no match:returns False - # 5. swap the best items - # : can we call swap_items(): here so that swap_best_by_category and swap_first_item can use it??? - - # return True - ... - - - # # helper_function - # def get_best_item(self, list_of_items): - # if not list_of_items: - # return None - - # best_item = list_of_items[0] + if not their_priority_item: + return False - # for item in list_of_items: - # if item.condition > best_item.condition: - # best_item = item + my_priority_item = self.get_best_by_category(their_priority) + if not my_priority_item: + return False - # return best_item + return self.swap_items(other, my_priority_item, their_priority_item) diff --git a/tests/integration_tests/test_wave_04_05_06.py b/tests/integration_tests/test_wave_04_05_06.py index 4d0be9909..91b1362b6 100644 --- a/tests/integration_tests/test_wave_04_05_06.py +++ b/tests/integration_tests/test_wave_04_05_06.py @@ -4,7 +4,7 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip +# @pytest.mark.skip @pytest.mark.integration_test def test_integration_wave_04_05_06(): camila = Vendor() diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index be227f79c..123ed01ec 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -96,7 +96,7 @@ def test_swap_best_by_category(): assert item_c in jesse.inventory -#@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category_reordered(): # Arrange item_a = Decor(condition=2.0) @@ -126,10 +126,19 @@ def test_swap_best_by_category_reordered(): # ********************************************************************* # Assertions should check: # - That result is truthy + assert result # - That tai and jesse's inventories are the correct length + assert len(tai.inventory) == 3 + assert len(tai.inventory) == 3 # - That all the correct items are in tai and jesse's inventories, and that the items that were swapped are not there + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_f in tai.inventory + assert item_e in jesse.inventory + assert item_d in jesse.inventory + assert item_c in jesse.inventory -#@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category_no_inventory_is_false(): tai = Vendor( inventory=[] @@ -155,7 +164,7 @@ def test_swap_best_by_category_no_inventory_is_false(): assert item_b in jesse.inventory assert item_c in jesse.inventory -#@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category_no_other_inventory_is_false(): item_a = Clothing(condition=2.0) item_b = Decor(condition=4.0) @@ -181,7 +190,7 @@ def test_swap_best_by_category_no_other_inventory_is_false(): assert item_b in tai.inventory assert item_c in tai.inventory -#@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category_no_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -205,16 +214,20 @@ def test_swap_best_by_category_no_match_is_false(): their_priority="Clothing" ) - #raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* - # Assertions should check: - # - That result is falsy - # - That tai and jesse's inventories are the correct length - # - That all the correct items are in tai and jesse's inventories + assert not result -#@pytest.mark.skip + assert len(tai.inventory) == 3 + assert len(tai.inventory) == 3 + + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + assert item_f in jesse.inventory + assert item_e in jesse.inventory + assert item_d in jesse.inventory + + +# @pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -238,11 +251,15 @@ def test_swap_best_by_category_no_other_match_is_false(): their_priority="Decor" ) - #raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* - # Assertions should check: - # - That result is falsy - # - That tai and jesse's inventories are the correct length - # - That all the correct items are in tai and jesse's inventories + assert not result + + assert len(tai.inventory) == 3 + assert len(tai.inventory) == 3 + + + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + assert item_f in jesse.inventory + assert item_e in jesse.inventory + assert item_d in jesse.inventory