From fa75748564bd6377ce5284e62df5cb1fc73e35a8 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Mon, 4 Apr 2022 16:06:07 -0400 Subject: [PATCH 01/17] passed wave 1 unit tests --- swap_meet/item.py | 7 ++++++- swap_meet/vendor.py | 17 ++++++++++++++++- tests/unit_tests/test_wave_01.py | 15 +++++++++------ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 560d759c2..3c6902da5 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=None): + if not category: + category = [] + + def get_by_category(self): + pass \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..dcac63456 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,17 @@ class Vendor: - pass \ No newline at end of file + def __init__(self, inventory=None): + if not inventory: + inventory = [] + 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 + return False \ No newline at end of file diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index 58478ccf9..df16b991f 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( @@ -49,7 +49,10 @@ 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 len(vendor.inventory) == 3 + assert item not in vendor.inventory + assert result == False \ No newline at end of file From 6e8bfbcf2475f972fb49f2bdb5499aa854bbaf81 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Mon, 4 Apr 2022 22:50:08 -0400 Subject: [PATCH 02/17] passed wave 2 unit tests --- swap_meet/item.py | 8 ++------ swap_meet/vendor.py | 11 ++++++++--- tests/unit_tests/test_wave_02.py | 12 ++++++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 3c6902da5..a330f6f9e 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,7 +1,3 @@ class Item: - def __init__(self, category=None): - if not category: - category = [] - - def get_by_category(self): - pass \ No newline at end of file + def __init__(self, category=""): + self.category = category \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index dcac63456..fb0555806 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -3,15 +3,20 @@ def __init__(self, inventory=None): if not inventory: inventory = [] 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 - return False \ No newline at end of file + return False + + def get_by_category(self, specific_category): + category_matches = [] + for item in self.inventory: + if item.category == specific_category: + category_matches.append(item) + return category_matches \ 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..726837d96 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_b not in items + assert item_c not in items \ No newline at end of file From 6a3367784d48706ee664ac9f6ed9a73f34e522aa Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Tue, 5 Apr 2022 23:19:35 -0400 Subject: [PATCH 03/17] finished first test in wave 3 --- swap_meet/item.py | 5 ++++- tests/unit_tests/test_wave_03.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index a330f6f9e..4f1f6935e 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,3 +1,6 @@ class Item: def __init__(self, category=""): - self.category = category \ No newline at end of file + self.category = category + + def __str__(self): + return "Hello World!" \ No newline at end of file diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 0300b638f..0af1098e8 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") From a928b5e985b70ddad683e8cc2f5e252d60a9923b Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Wed, 6 Apr 2022 02:23:35 -0400 Subject: [PATCH 04/17] passed wave 3 unit tests --- swap_meet/vendor.py | 11 ++++++++++- tests/unit_tests/test_wave_03.py | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index fb0555806..6198c5b6c 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -19,4 +19,13 @@ def get_by_category(self, specific_category): for item in self.inventory: if item.category == specific_category: category_matches.append(item) - return category_matches \ No newline at end of file + return category_matches + + def swap_items(self, friend, my_item, their_item): + if my_item in self.inventory and their_item in friend.inventory: + friend.inventory.append(my_item) + self.inventory.remove(my_item) + self.inventory.append(their_item) + friend.inventory.remove(their_item) + return True + return False \ No newline at end of file diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 0af1098e8..2d573fa52 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -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 8e4a74debf6c70f451168680e0cfec647bbd81b0 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Wed, 6 Apr 2022 14:01:37 -0400 Subject: [PATCH 05/17] added main.py --- main.py | 3 +++ tests/integration_tests/test_wave_01_02_03.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 000000000..1ab51360e --- /dev/null +++ b/main.py @@ -0,0 +1,3 @@ +from swap_meet.item import Item +from swap_meet.vendor import Vendor + diff --git a/tests/integration_tests/test_wave_01_02_03.py b/tests/integration_tests/test_wave_01_02_03.py index 9912414da..34d042fdd 100644 --- a/tests/integration_tests/test_wave_01_02_03.py +++ b/tests/integration_tests/test_wave_01_02_03.py @@ -2,8 +2,8 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip -@pytest.mark.integration_test +# @pytest.mark.skip +# @pytest.mark.integration_test def test_integration_wave_01_02_03(): # make a vendor vendor = Vendor() From 12a0b1b55dbe24d03fcf980ba0359a2fac387ef1 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Wed, 6 Apr 2022 15:00:41 -0400 Subject: [PATCH 06/17] passed wave 4 unit tests --- swap_meet/vendor.py | 17 +++++++++++++++++ tests/unit_tests/test_wave_04.py | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 6198c5b6c..b01435279 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -25,7 +25,24 @@ def swap_items(self, friend, my_item, their_item): if my_item in self.inventory and their_item in friend.inventory: friend.inventory.append(my_item) self.inventory.remove(my_item) + self.inventory.append(their_item) friend.inventory.remove(their_item) return True + return False + + def swap_first_item(self, friend): + ''' + 1) Adds the first item from Jolie's (friend's) inventory. + 2) Removes first item from Fatimah's (self's) inventory. + 3) Adds the instances first item + 4) Remove the first item from Jolie's inventory + ''' + if self.inventory and friend.inventory: + friend.inventory.append(self.inventory[0]) + self.inventory.remove(self.inventory[0]) + + self.inventory.append(friend.inventory[0]) + friend.inventory.remove(friend.inventory[0]) + return True return False \ 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 98c1c35094e6748d7e138dc0b8c960634f8709ce Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Wed, 6 Apr 2022 16:59:52 -0400 Subject: [PATCH 07/17] passed 4/5 wave 5 unit tests --- swap_meet/clothing.py | 10 +++++++++- swap_meet/decor.py | 10 +++++++++- swap_meet/electronics.py | 10 +++++++++- swap_meet/item.py | 8 ++++++-- tests/unit_tests/test_wave_05.py | 10 +++++----- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..6ce0aec9f 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,10 @@ class Clothing: - pass \ No newline at end of file + def __init__(self, category="Clothing", condition=0): + self.category = category + self.condition = condition + + def __str__(self): + return "The finest clothing you could wear." + + def condition_description(self): + pass \ No newline at end of file diff --git a/swap_meet/decor.py b/swap_meet/decor.py index eab7a9dbe..25669bebf 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,10 @@ class Decor: - pass \ No newline at end of file + def __init__(self, category="Decor", condition=0): + self.category = category + self.condition = condition + + def __str__(self): + return "Something to decorate your space." + + def condition_description(self): + pass \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2f9dff68a..2e944d42b 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,10 @@ class Electronics: - pass + def __init__(self, category="Electronics", condition=0): + self.category = category + self.condition = condition + + def __str__(self): + return "A gadget full of buttons and secrets." + + def condition_description(self): + pass diff --git a/swap_meet/item.py b/swap_meet/item.py index 4f1f6935e..17eadf3a2 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,6 +1,10 @@ class Item: - def __init__(self, category=""): + def __init__(self, category="", condition=0): self.category = category + self.condition = condition def __str__(self): - return "Hello World!" \ No newline at end of file + return "Hello World!" + + def condition_description(self): + pass \ 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 5efb5dfcca7ccba30a9d43143a6df9bbb83b0acb Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Wed, 6 Apr 2022 18:17:26 -0400 Subject: [PATCH 08/17] passed wave 5 unit tests --- swap_meet/clothing.py | 6 ++++-- swap_meet/decor.py | 6 ++++-- swap_meet/electronics.py | 7 +++---- swap_meet/item.py | 13 ++++++++++++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 6ce0aec9f..051bbdffb 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,4 +1,6 @@ -class Clothing: +from .item import Item + +class Clothing(Item): def __init__(self, category="Clothing", condition=0): self.category = category self.condition = condition @@ -6,5 +8,5 @@ def __init__(self, category="Clothing", condition=0): def __str__(self): return "The finest clothing you could wear." - def condition_description(self): + # def condition_description(self): pass \ No newline at end of file diff --git a/swap_meet/decor.py b/swap_meet/decor.py index 25669bebf..09964ebfa 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,4 +1,6 @@ -class Decor: +from .item import Item + +class Decor(Item): def __init__(self, category="Decor", condition=0): self.category = category self.condition = condition @@ -6,5 +8,5 @@ def __init__(self, category="Decor", condition=0): def __str__(self): return "Something to decorate your space." - def condition_description(self): + # def condition_description(self): pass \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2e944d42b..39edbdcb9 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,10 +1,9 @@ -class Electronics: +from .item import Item + +class Electronics(Item): def __init__(self, category="Electronics", condition=0): self.category = category self.condition = condition def __str__(self): return "A gadget full of buttons and secrets." - - def condition_description(self): - pass diff --git a/swap_meet/item.py b/swap_meet/item.py index 17eadf3a2..403a6d754 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -7,4 +7,15 @@ def __str__(self): return "Hello World!" def condition_description(self): - pass \ No newline at end of file + if not self.condition: + return "This item has been heavily used." + elif self.condition == 1: + return "This item has been moderately used." + elif self.condition == 2: + return "This item has been partially used." + elif self.condition == 3: + return "This item is in good condition." + elif self.condition == 4: + return "This item is in great condtion." + elif self.condition == 5: + return "This item is brand new!" \ No newline at end of file From b18eae727fb43e5d58a0d1ac789b2ecaef0c1489 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Wed, 6 Apr 2022 19:51:04 -0400 Subject: [PATCH 09/17] passed first three wave 6 tests --- swap_meet/vendor.py | 38 +++++++++++++++++++++++++++++++- tests/unit_tests/test_wave_06.py | 10 +++++---- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index b01435279..175cb9252 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,3 +1,6 @@ +from multiprocessing.sharedctypes import Value + + class Vendor: def __init__(self, inventory=None): if not inventory: @@ -45,4 +48,37 @@ def swap_first_item(self, friend): self.inventory.append(friend.inventory[0]) friend.inventory.remove(friend.inventory[0]) return True - return False \ No newline at end of file + return False + + def get_best_by_category(self, specific_category): + ''' + 1) create a highest condition variable set 0 + 2) iterate over the vendor's inventory + 3) check if the specific category is clothing + 4) if the condition is greater than the highest condtion, reassign highest condition + 5) return the highest condtion + 6) otherwise none + ''' + # highest_condition = 0 + + # for item in self.inventory: + # if specific_category == item.category and item.condition > highest_condition: + # highest_condition = item.condition + # return item + # return None + try: + categories = {} + # {2.0: 'Clothing', 4.0: 'Clothing', 3.0: 'Clothing'} + for item in self.inventory: + if specific_category == item.category: + categories[item.condition] = item.category + + highest_condition = max(categories.keys()) + # 4.0 + for item in self.inventory: + if item.category == specific_category and item.condition == highest_condition: + return item + except ValueError: + return None + + diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 1f7065ab4..ab089801f 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 @@ -82,7 +82,9 @@ def test_swap_best_by_category(): # ********************************************************************* # Assertions should check: # - That the results is truthy + assert result # - 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 From 6e6568806ca0b1a52ee9850d40976993090cd550 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Wed, 6 Apr 2022 21:21:41 -0400 Subject: [PATCH 10/17] added some wave 6 assertions --- swap_meet/clothing.py | 5 +---- swap_meet/decor.py | 5 +---- swap_meet/electronics.py | 2 +- swap_meet/item.py | 2 +- swap_meet/vendor.py | 13 +++++++++---- tests/unit_tests/test_wave_06.py | 17 +++++++++++++++-- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 051bbdffb..0fb968b1c 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -6,7 +6,4 @@ def __init__(self, category="Clothing", condition=0): self.condition = condition def __str__(self): - return "The finest clothing you could wear." - - # def condition_description(self): - pass \ No newline at end of file + return "The finest clothing you could wear." \ No newline at end of file diff --git a/swap_meet/decor.py b/swap_meet/decor.py index 09964ebfa..e9510dbd1 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -6,7 +6,4 @@ def __init__(self, category="Decor", condition=0): self.condition = condition def __str__(self): - return "Something to decorate your space." - - # def condition_description(self): - pass \ No newline at end of file + return "Something to decorate your space." \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 39edbdcb9..8eddc1112 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -6,4 +6,4 @@ def __init__(self, category="Electronics", condition=0): self.condition = condition def __str__(self): - return "A gadget full of buttons and secrets." + return "A gadget full of buttons and secrets." \ No newline at end of file diff --git a/swap_meet/item.py b/swap_meet/item.py index 403a6d754..8b5e4ba55 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -16,6 +16,6 @@ def condition_description(self): elif self.condition == 3: return "This item is in good condition." elif self.condition == 4: - return "This item is in great condtion." + return "This item is in great condition." elif self.condition == 5: return "This item is brand new!" \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 175cb9252..db664a311 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,6 +1,3 @@ -from multiprocessing.sharedctypes import Value - - class Vendor: def __init__(self, inventory=None): if not inventory: @@ -81,4 +78,12 @@ def get_best_by_category(self, specific_category): except ValueError: return None - + def swap_best_by_category(self, other, my_priority, their_priority): + ''' + 1) The best item in my inventory that matches `their_priority` category is swapped with the best item in `other`'s inventory that matches + It returns `True` + 2) If the `Vendor` has no item that matches `their_priority` category, swapping does not happen, and it returns `False` + 3) If `other` has no item that matches `my_priority` category, swapping does not happen, and it returns `False ` + ''' + if my_priority in other.inventory + pass \ 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 ab089801f..748f439b0 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -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 ********** # ********************************************************************* @@ -84,8 +84,18 @@ def test_swap_best_by_category(): # - That the results is truthy assert result # - That tai and jesse's inventories are the correct length - + assert len(tai.inventory) == 3 + assert len(jesse.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_c not in tai.inventory + + assert item_c in jesse.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_f not in jesse.inventory @pytest.mark.skip def test_swap_best_by_category_reordered(): @@ -117,6 +127,7 @@ 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 # - That all the correct items are in tai and jesse's inventories, and that the items that were swapped are not there @@ -202,6 +213,7 @@ def test_swap_best_by_category_no_match_is_false(): # ********************************************************************* # Assertions should check: # - That result is falsy + assert not result # - That tai and jesse's inventories are the correct length # - That all the correct items are in tai and jesse's inventories @@ -235,5 +247,6 @@ def test_swap_best_by_category_no_other_match_is_false(): # ********************************************************************* # Assertions should check: # - That result is falsy + assert not result # - That tai and jesse's inventories are the correct length # - That all the correct items are in tai and jesse's inventories From f95379f7d34bf21ba4f916957cd3f3418f12d33c Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Wed, 6 Apr 2022 22:01:55 -0400 Subject: [PATCH 11/17] fixed some class inheritance issues --- swap_meet/clothing.py | 5 ++--- swap_meet/decor.py | 5 ++--- swap_meet/electronics.py | 5 ++--- swap_meet/vendor.py | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 0fb968b1c..755d09a93 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,9 +1,8 @@ from .item import Item class Clothing(Item): - def __init__(self, category="Clothing", condition=0): - self.category = category - self.condition = condition + def __init__(self, category="", condition=0): + super().__init__("Clothing", condition) def __str__(self): return "The finest clothing you could wear." \ No newline at end of file diff --git a/swap_meet/decor.py b/swap_meet/decor.py index e9510dbd1..634aee01c 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,9 +1,8 @@ from .item import Item class Decor(Item): - def __init__(self, category="Decor", condition=0): - self.category = category - self.condition = condition + def __init__(self, category="", condition=0): + super().__init__(category="Decor", condition=condition) def __str__(self): return "Something to decorate your space." \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 8eddc1112..7a24e7bcc 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,9 +1,8 @@ from .item import Item class Electronics(Item): - def __init__(self, category="Electronics", condition=0): - self.category = category - self.condition = condition + def __init__(self, category="", condition=0): + super().__init__(category="Electronics", condition=condition) def __str__(self): return "A gadget full of buttons and secrets." \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index db664a311..876ae26a2 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -85,5 +85,5 @@ def swap_best_by_category(self, other, my_priority, their_priority): 2) If the `Vendor` has no item that matches `their_priority` category, swapping does not happen, and it returns `False` 3) If `other` has no item that matches `my_priority` category, swapping does not happen, and it returns `False ` ''' - if my_priority in other.inventory + # if my_priority in other.inventory pass \ No newline at end of file From ed3141df4d46c7e1086d7eec95835483d21d5934 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Thu, 7 Apr 2022 17:09:47 -0400 Subject: [PATCH 12/17] refactored tests 1-3 in wave 6 --- swap_meet/decor.py | 2 +- swap_meet/electronics.py | 2 +- swap_meet/vendor.py | 52 +++++++++++++++----------------- tests/unit_tests/test_wave_06.py | 13 +++++++- 4 files changed, 38 insertions(+), 31 deletions(-) diff --git a/swap_meet/decor.py b/swap_meet/decor.py index 634aee01c..68747c7e2 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -2,7 +2,7 @@ class Decor(Item): def __init__(self, category="", condition=0): - super().__init__(category="Decor", condition=condition) + super().__init__("Decor", condition) def __str__(self): return "Something to decorate your space." \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 7a24e7bcc..2125dc6f6 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -2,7 +2,7 @@ class Electronics(Item): def __init__(self, category="", condition=0): - super().__init__(category="Electronics", condition=condition) + super().__init__("Electronics", condition) def __str__(self): return "A gadget full of buttons and secrets." \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 876ae26a2..c6dd0b6cb 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -48,35 +48,15 @@ def swap_first_item(self, friend): return False def get_best_by_category(self, specific_category): - ''' - 1) create a highest condition variable set 0 - 2) iterate over the vendor's inventory - 3) check if the specific category is clothing - 4) if the condition is greater than the highest condtion, reassign highest condition - 5) return the highest condtion - 6) otherwise none - ''' - # highest_condition = 0 + best_by_category = None + highest_condition = 0 - # for item in self.inventory: - # if specific_category == item.category and item.condition > highest_condition: - # highest_condition = item.condition - # return item - # return None - try: - categories = {} - # {2.0: 'Clothing', 4.0: 'Clothing', 3.0: 'Clothing'} - for item in self.inventory: - if specific_category == item.category: - categories[item.condition] = item.category + for item in self.inventory: + if item.category == specific_category and item.condition > highest_condition: + best_by_category = item + highest_condition = item.condition - highest_condition = max(categories.keys()) - # 4.0 - for item in self.inventory: - if item.category == specific_category and item.condition == highest_condition: - return item - except ValueError: - return None + return best_by_category def swap_best_by_category(self, other, my_priority, their_priority): ''' @@ -86,4 +66,20 @@ def swap_best_by_category(self, other, my_priority, their_priority): 3) If `other` has no item that matches `my_priority` category, swapping does not happen, and it returns `False ` ''' # if my_priority in other.inventory - pass \ No newline at end of file + test = 0 + my_best_item = None + for item in other.inventory: + if item.category == my_priority and item.condition > test: + test = item.condition + my_best_item = item + + test2 = 0 + their_best_item = None + for item in self.inventory: + if item.category == their_priority and item.condition > test: + test_2 = item.condition + their_best_item = item + + # if best_item: + # return True + # return False \ 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 748f439b0..8a0339323 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -121,7 +121,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 ********** # ********************************************************************* @@ -129,7 +129,18 @@ def test_swap_best_by_category_reordered(): # - That result is truthy assert result # - That tai and jesse's inventories are the correct length + assert len(tai.inventory) == 3 + assert len(jesse.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_c not in tai.inventory + + assert item_c in jesse.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_f not in jesse.inventory @pytest.mark.skip def test_swap_best_by_category_no_inventory_is_false(): From d90cb234ca9a889216ed15c1d4abaa6c70a4cdd6 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Thu, 7 Apr 2022 19:21:13 -0400 Subject: [PATCH 13/17] passed more 4/8 wave 6 tests --- swap_meet/vendor.py | 36 ++++++-------------------------- tests/unit_tests/test_wave_06.py | 4 ++-- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index c6dd0b6cb..2c3e095a2 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -32,12 +32,6 @@ def swap_items(self, friend, my_item, their_item): return False def swap_first_item(self, friend): - ''' - 1) Adds the first item from Jolie's (friend's) inventory. - 2) Removes first item from Fatimah's (self's) inventory. - 3) Adds the instances first item - 4) Remove the first item from Jolie's inventory - ''' if self.inventory and friend.inventory: friend.inventory.append(self.inventory[0]) self.inventory.remove(self.inventory[0]) @@ -59,27 +53,9 @@ def get_best_by_category(self, specific_category): return best_by_category def swap_best_by_category(self, other, my_priority, their_priority): - ''' - 1) The best item in my inventory that matches `their_priority` category is swapped with the best item in `other`'s inventory that matches - It returns `True` - 2) If the `Vendor` has no item that matches `their_priority` category, swapping does not happen, and it returns `False` - 3) If `other` has no item that matches `my_priority` category, swapping does not happen, and it returns `False ` - ''' - # if my_priority in other.inventory - test = 0 - my_best_item = None - for item in other.inventory: - if item.category == my_priority and item.condition > test: - test = item.condition - my_best_item = item - - test2 = 0 - their_best_item = None - for item in self.inventory: - if item.category == their_priority and item.condition > test: - test_2 = item.condition - their_best_item = item - - # if best_item: - # return True - # return False \ No newline at end of file + their_best_category = self.get_best_by_category(their_priority) + my_best_category = other.get_best_by_category(my_priority) + + if my_best_category and their_best_category: + swapped = self.swap_items(other, their_best_category, my_best_category) + return swapped \ 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 8a0339323..d93c59d4e 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -97,7 +97,7 @@ def test_swap_best_by_category(): assert item_e in jesse.inventory assert item_f not in jesse.inventory -@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category_reordered(): # Arrange item_a = Decor(condition=2.0) @@ -142,7 +142,7 @@ def test_swap_best_by_category_reordered(): assert item_e in jesse.inventory assert item_f not in jesse.inventory -@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category_no_inventory_is_false(): tai = Vendor( inventory=[] From 5439fd71a7609beca1595bfc2640b46938b079f7 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Thu, 7 Apr 2022 19:42:51 -0400 Subject: [PATCH 14/17] passed all tests --- swap_meet/vendor.py | 8 ++++---- tests/integration_tests/test_wave_04_05_06.py | 4 ++-- tests/unit_tests/test_wave_06.py | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 2c3e095a2..b6745df8f 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -53,9 +53,9 @@ def get_best_by_category(self, specific_category): return best_by_category def swap_best_by_category(self, other, my_priority, their_priority): - their_best_category = self.get_best_by_category(their_priority) - my_best_category = other.get_best_by_category(my_priority) + their_best_item = self.get_best_by_category(their_priority) + my_best_item = other.get_best_by_category(my_priority) - if my_best_category and their_best_category: - swapped = self.swap_items(other, their_best_category, my_best_category) + if my_best_item and their_best_item: + swapped = self.swap_items(other, their_best_item, my_best_item) return swapped \ No newline at end of file diff --git a/tests/integration_tests/test_wave_04_05_06.py b/tests/integration_tests/test_wave_04_05_06.py index 4d0be9909..cb3b346a2 100644 --- a/tests/integration_tests/test_wave_04_05_06.py +++ b/tests/integration_tests/test_wave_04_05_06.py @@ -4,8 +4,8 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip -@pytest.mark.integration_test +# @pytest.mark.skip +# @pytest.mark.integration_test def test_integration_wave_04_05_06(): camila = Vendor() valentina = Vendor() diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index d93c59d4e..9b4583c0a 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -168,7 +168,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) @@ -194,7 +194,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) @@ -218,7 +218,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 ********** # ********************************************************************* @@ -226,9 +226,13 @@ def test_swap_best_by_category_no_match_is_false(): # - That result is falsy assert not result # - That tai and jesse's inventories are the correct length + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 # - That all the correct items are in tai and jesse's inventories + assert tai.inventory == [item_a, item_b, item_c] + assert jesse.inventory == [item_d, item_e, item_f] -@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -252,7 +256,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 ********** # ********************************************************************* @@ -260,4 +264,8 @@ def test_swap_best_by_category_no_other_match_is_false(): # - That result is falsy assert not result # - That tai and jesse's inventories are the correct length + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 # - That all the correct items are in tai and jesse's inventories + assert tai.inventory == [item_c, item_b, item_a] + assert jesse.inventory == [item_f, item_e, item_d] \ No newline at end of file From 36128719208bc4c88b93136eab72eb5825191f32 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Thu, 7 Apr 2022 20:09:46 -0400 Subject: [PATCH 15/17] refactored swap_best_by_category --- swap_meet/vendor.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index b6745df8f..84e9ab13f 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -53,9 +53,12 @@ def get_best_by_category(self, specific_category): return best_by_category def swap_best_by_category(self, other, my_priority, their_priority): + their_best_item = self.get_best_by_category(their_priority) my_best_item = other.get_best_by_category(my_priority) - if my_best_item and their_best_item: - swapped = self.swap_items(other, their_best_item, my_best_item) - return swapped \ No newline at end of file + if not their_best_item or not my_best_item: + return False + + swapped_items = self.swap_items(other, their_best_item, my_best_item) + return swapped_items \ No newline at end of file From c81345783aeca0b2c20e8b3a1acf15a8d3bd6666 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Fri, 8 Apr 2022 12:28:10 -0400 Subject: [PATCH 16/17] added docstrings --- swap_meet/vendor.py | 63 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 84e9ab13f..b9fd55115 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -5,16 +5,37 @@ def __init__(self, inventory=None): self.inventory = inventory def add(self, item): + """Adds an item to the instance's inventory and returns it.""" self.inventory.append(item) return item def remove(self, item): + """ + Removes items from the instance's inventory. + + Parameter: + item (str): Inventory item to be removed. + + Returns: + bool: True if item is inventory, False otherwise. + """ + if item in self.inventory: self.inventory.remove(item) return item return False def get_by_category(self, specific_category): + """ + Adds the items in the instance's inventory that are of a specific category. + + Parameters: + specific_category (str): A category. + + Returns: + category_matches (list): Items in the inventory matching the category. + """ + category_matches = [] for item in self.inventory: if item.category == specific_category: @@ -22,6 +43,18 @@ def get_by_category(self, specific_category): return category_matches def swap_items(self, friend, my_item, their_item): + """ + Swaps items in vendor's inventory and friend's inventory. + + Parameters: + friend (class): Vendor instance of friend. + my_item (str): Category the vendor wants to receive. + their_item (str): Category friends wants to receive. + + Returns: + (bool): True if swapping occurs, False if not. + """ + if my_item in self.inventory and their_item in friend.inventory: friend.inventory.append(my_item) self.inventory.remove(my_item) @@ -32,6 +65,15 @@ def swap_items(self, friend, my_item, their_item): return False def swap_first_item(self, friend): + ''' + Removes first item from a vendor's inventory and a friend's inventory. + + Parameter: + friend (class): An instance of another Vendor. + + Returns: + (bool): True is first items the Vendor and the friend swap items, False otherwise. + ''' if self.inventory and friend.inventory: friend.inventory.append(self.inventory[0]) self.inventory.remove(self.inventory[0]) @@ -42,6 +84,15 @@ def swap_first_item(self, friend): return False def get_best_by_category(self, specific_category): + ''' + Returns the item with the best condition in a specific category. + + Parameters: + specific_category (str): Category. + + Returns: + (instance or bool): Returns instance of an item in a specfic category's best condition or None if not found. + ''' best_by_category = None highest_condition = 0 @@ -49,10 +100,20 @@ def get_best_by_category(self, specific_category): if item.category == specific_category and item.condition > highest_condition: best_by_category = item highest_condition = item.condition - return best_by_category def swap_best_by_category(self, other, my_priority, their_priority): + ''' + Determines if vendor's item priority and other's item priority exists and swaps items. + + Parameters: + other (class): The other Vendor instance. + my_priority (str): The category that the Vendor wants to receive. + their_priority (str): The category that the other party wants to receive. + + Returns: + (bool): True if items are swapped, False is not. + ''' their_best_item = self.get_best_by_category(their_priority) my_best_item = other.get_best_by_category(my_priority) From 7d074af567f205a230252c0bce0ba8f3f244947d Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Thu, 14 Apr 2022 20:58:54 -0400 Subject: [PATCH 17/17] refactored based on instructor feedback --- swap_meet/clothing.py | 2 +- swap_meet/decor.py | 2 +- swap_meet/electronics.py | 2 +- swap_meet/item.py | 22 +++-- swap_meet/vendor.py | 80 ++++++++++--------- tests/integration_tests/test_wave_01_02_03.py | 6 +- tests/integration_tests/test_wave_04_05_06.py | 2 +- tests/unit_tests/test_wave_02.py | 6 +- tests/unit_tests/test_wave_03.py | 2 +- tests/unit_tests/test_wave_05.py | 2 +- tests/unit_tests/test_wave_06.py | 2 + 11 files changed, 63 insertions(+), 65 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 755d09a93..f1f5a97e1 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,7 +1,7 @@ from .item import Item class Clothing(Item): - def __init__(self, category="", condition=0): + def __init__(self, condition=0): super().__init__("Clothing", condition) def __str__(self): diff --git a/swap_meet/decor.py b/swap_meet/decor.py index 68747c7e2..6aa0ff0cc 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,7 +1,7 @@ from .item import Item class Decor(Item): - def __init__(self, category="", condition=0): + def __init__(self, condition=0): super().__init__("Decor", condition) def __str__(self): diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2125dc6f6..8d785470e 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,7 +1,7 @@ from .item import Item class Electronics(Item): - def __init__(self, category="", condition=0): + def __init__(self, condition=0): super().__init__("Electronics", condition) def __str__(self): diff --git a/swap_meet/item.py b/swap_meet/item.py index 8b5e4ba55..a337c3e13 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -7,15 +7,13 @@ def __str__(self): return "Hello World!" def condition_description(self): - if not self.condition: - return "This item has been heavily used." - elif self.condition == 1: - return "This item has been moderately used." - elif self.condition == 2: - return "This item has been partially used." - elif self.condition == 3: - return "This item is in good condition." - elif self.condition == 4: - return "This item is in great condition." - elif self.condition == 5: - return "This item is brand new!" \ No newline at end of file + condition_chart = { + 0: "This item has been heavily used.", + 1: "This item has been moderately used.", + 2: "This item has been partially used.", + 3: "This item is in good condition.", + 4: "This item is in great condition.", + 5: "This item is brand new" + } + + return condition_chart[self.condition] \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index b9fd55115..24561f852 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,8 +1,6 @@ class Vendor: def __init__(self, inventory=None): - if not inventory: - inventory = [] - self.inventory = inventory + self.inventory = [] if not inventory else inventory def add(self, item): """Adds an item to the instance's inventory and returns it.""" @@ -17,17 +15,20 @@ def remove(self, item): item (str): Inventory item to be removed. Returns: - bool: True if item is inventory, False otherwise. + Instance or bool: False if item is not in inventory, returns item + otherwise. """ - if item in self.inventory: - self.inventory.remove(item) - return item - return False + if item not in self.inventory: + return False + + self.inventory.remove(item) + return item def get_by_category(self, specific_category): """ - Adds the items in the instance's inventory that are of a specific category. + Collects the items in the instance's inventory that are of a specific + category. Parameters: specific_category (str): A category. @@ -36,11 +37,8 @@ def get_by_category(self, specific_category): category_matches (list): Items in the inventory matching the category. """ - category_matches = [] - for item in self.inventory: - if item.category == specific_category: - category_matches.append(item) - return category_matches + return [item for item in self.inventory + if item.category == specific_category] def swap_items(self, friend, my_item, their_item): """ @@ -52,64 +50,69 @@ def swap_items(self, friend, my_item, their_item): their_item (str): Category friends wants to receive. Returns: - (bool): True if swapping occurs, False if not. + (bool): False if swapping does not occurs, True otherwise. """ - if my_item in self.inventory and their_item in friend.inventory: - friend.inventory.append(my_item) - self.inventory.remove(my_item) + if my_item not in self.inventory or their_item not in friend.inventory: + return False + + friend.inventory.append(my_item) + self.inventory.remove(my_item) - self.inventory.append(their_item) - friend.inventory.remove(their_item) - return True - return False + self.inventory.append(their_item) + friend.inventory.remove(their_item) + return True def swap_first_item(self, friend): ''' - Removes first item from a vendor's inventory and a friend's inventory. + Swaps the first item from a vendor's inventory and a friend's inventory. Parameter: friend (class): An instance of another Vendor. Returns: - (bool): True is first items the Vendor and the friend swap items, False otherwise. + (bool): False if an item does not exist in the Vendor + or the friend's inventory, + True otherwise. ''' - if self.inventory and friend.inventory: - friend.inventory.append(self.inventory[0]) - self.inventory.remove(self.inventory[0]) - - self.inventory.append(friend.inventory[0]) - friend.inventory.remove(friend.inventory[0]) - return True - return False + if not self.inventory or not friend.inventory: + return False + + self.inventory[0], friend.inventory[0] = friend.inventory[0], self.inventory[0] + return True def get_best_by_category(self, specific_category): ''' Returns the item with the best condition in a specific category. Parameters: - specific_category (str): Category. + specific_category (str): Represents a category. Returns: - (instance or bool): Returns instance of an item in a specfic category's best condition or None if not found. + (instance or bool): Returns the vendor's instance of an item + in a specfic category's best condition or None if not found. ''' best_by_category = None highest_condition = 0 for item in self.inventory: - if item.category == specific_category and item.condition > highest_condition: + if (item.category == specific_category and + item.condition > highest_condition): best_by_category = item highest_condition = item.condition + return best_by_category def swap_best_by_category(self, other, my_priority, their_priority): ''' - Determines if vendor's item priority and other's item priority exists and swaps items. + Determines if vendor's item priority and other's item + priority exists and swaps items. Parameters: other (class): The other Vendor instance. my_priority (str): The category that the Vendor wants to receive. - their_priority (str): The category that the other party wants to receive. + their_priority (str): The category that the other party wants to + receive. Returns: (bool): True if items are swapped, False is not. @@ -121,5 +124,4 @@ def swap_best_by_category(self, other, my_priority, their_priority): if not their_best_item or not my_best_item: return False - swapped_items = self.swap_items(other, their_best_item, my_best_item) - return swapped_items \ No newline at end of file + return self.swap_items(other, their_best_item, my_best_item) \ 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 34d042fdd..b6c0f3bd8 100644 --- a/tests/integration_tests/test_wave_01_02_03.py +++ b/tests/integration_tests/test_wave_01_02_03.py @@ -3,7 +3,7 @@ from swap_meet.item import Item # @pytest.mark.skip -# @pytest.mark.integration_test +@pytest.mark.integration_test def test_integration_wave_01_02_03(): # make a vendor vendor = Vendor() @@ -49,6 +49,4 @@ def test_integration_wave_01_02_03(): assert len(vendor.inventory) == 1 assert len(other_vendor.inventory) == 1 assert item2 in other_vendor.inventory - assert item3 in vendor.inventory - - + assert item3 in vendor.inventory \ No newline at end of file diff --git a/tests/integration_tests/test_wave_04_05_06.py b/tests/integration_tests/test_wave_04_05_06.py index cb3b346a2..91b1362b6 100644 --- a/tests/integration_tests/test_wave_04_05_06.py +++ b/tests/integration_tests/test_wave_04_05_06.py @@ -5,7 +5,7 @@ from swap_meet.electronics import Electronics # @pytest.mark.skip -# @pytest.mark.integration_test +@pytest.mark.integration_test def test_integration_wave_04_05_06(): camila = Vendor() valentina = Vendor() diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index 726837d96..09bf49590 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -38,7 +38,5 @@ def test_get_no_matching_items_by_category(): # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* - assert len(items) == 0 - assert item_a not in items - assert item_b not in items - assert item_c not in items \ No newline at end of file + assert not len(items) + assert items == [] \ No newline at end of file diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 2d573fa52..3b66838b4 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -131,4 +131,4 @@ def test_swap_items_from_their_empty_returns_false(): assert len(fatimah.inventory) == 3 assert len(jolie.inventory) == 0 - assert not result + 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 fdeb063a9..eb61543a0 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -51,4 +51,4 @@ def test_items_have_condition_descriptions_that_are_the_same_regardless_of_type( item.condition = 1 assert item.condition_description() == one_condition_description - assert one_condition_description != five_condition_description + assert one_condition_description != five_condition_description \ 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 9b4583c0a..dfd50cf1a 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -225,6 +225,7 @@ def test_swap_best_by_category_no_match_is_false(): # Assertions should check: # - That result is falsy assert not result + assert result == False # - That tai and jesse's inventories are the correct length assert len(tai.inventory) == 3 assert len(jesse.inventory) == 3 @@ -263,6 +264,7 @@ def test_swap_best_by_category_no_other_match_is_false(): # Assertions should check: # - That result is falsy assert not result + assert result == False # - That tai and jesse's inventories are the correct length assert len(tai.inventory) == 3 assert len(jesse.inventory) == 3