From 36d55636241db516c107c1b8f6b588494fcabf94 Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Tue, 4 Oct 2022 16:50:22 -0700 Subject: [PATCH 01/28] Forgot to commit until now. Passed Wave 1 and 2. Passed 11th test of Wave 3. --- swap_meet/item.py | 9 ++++++- swap_meet/vendor.py | 41 +++++++++++++++++++++++++++++++- tests/unit_tests/test_wave_01.py | 13 +++++----- tests/unit_tests/test_wave_02.py | 9 +++---- tests/unit_tests/test_wave_03.py | 6 ++--- 5 files changed, 63 insertions(+), 15 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 560d759c2..ad8735b96 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,9 @@ class Item: - pass \ No newline at end of file + + def __init__(self, category = None): + if category is None: + category = "" + self.category = category + + def __str__(self): + return "Hello World!" \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..c196bf344 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,41 @@ +from operator import itemgetter + + class Vendor: - pass \ No newline at end of file + def __init__(self, inventory = None): + if inventory is None: + inventory = [] + self.inventory = inventory + + + def add(self, item): + self.inventory.append(item) + return item + + def remove(self, item): + if item not in self.inventory: + return False + self.inventory.remove(item) + return item + + def get_by_category(self, category): + items_list = [] + + for item in self.inventory: + if item.category == category: + items_list.append(item) + + if items_list == []: + return "Sorry, there are no items within that category." + + return items_list + + def swap_items(self, vendor, my_item, their_item): + if my_item not in self.inventory or their_item not in vendor.inventory: + return False + + self.add(their_item) + self.remove(my_item) + vendor.add(my_item) + vendor.remove(their_item) + return True \ 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..f7a23ea7e 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,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 result == False diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index 3d7060d7c..7a69823b1 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 items == "Sorry, there are no items within that category." diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 0300b638f..6a8c61c6f 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") From 92ef56ed5c4c284170ffdc8ad2f73b3a1804a1cf Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Tue, 4 Oct 2022 16:51:18 -0700 Subject: [PATCH 02/28] Passed 12th test of Wave 3. --- tests/unit_tests/test_wave_03.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 6a8c61c6f..014d7618e 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -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") From 17006343eb383d4d1c99d5962463dd733701baad Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Tue, 4 Oct 2022 16:52:01 -0700 Subject: [PATCH 03/28] Passed 13th test of Wave 3. --- tests/unit_tests/test_wave_03.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 014d7618e..68c045bac 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -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=[] From 8a44ef6db480dba4e11978da93f765328d930b9c Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Tue, 4 Oct 2022 16:52:28 -0700 Subject: [PATCH 04/28] passed test 14 of Wave 3. --- tests/unit_tests/test_wave_03.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 68c045bac..85cd02d23 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -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 638005f988d7d6a6f13e81b8d668665167932b7e Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Tue, 4 Oct 2022 17:01:32 -0700 Subject: [PATCH 05/28] passed first integration tests for waves 1, 2, and 3. Updated output for get_by_category from string to empty list. --- swap_meet/vendor.py | 2 +- tests/integration_tests/test_wave_01_02_03.py | 2 +- tests/unit_tests/test_wave_02.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index c196bf344..d848974dc 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -26,7 +26,7 @@ def get_by_category(self, category): items_list.append(item) if items_list == []: - return "Sorry, there are no items within that category." + return [] return items_list diff --git a/tests/integration_tests/test_wave_01_02_03.py b/tests/integration_tests/test_wave_01_02_03.py index 9912414da..715275460 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_02.py b/tests/unit_tests/test_wave_02.py index 7a69823b1..0e94706b8 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -38,4 +38,4 @@ def test_get_no_matching_items_by_category(): # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* - assert items == "Sorry, there are no items within that category." + assert items == [] From fe96f4819e0606ab32665ae2452b8e7b8fa0254c Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Wed, 5 Oct 2022 14:09:29 -0700 Subject: [PATCH 06/28] Created swap_first_item function from Wave 4. --- swap_meet/vendor.py | 12 ++++++++++++ tests/unit_tests/test_wave_04.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index d848974dc..4154a55db 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -38,4 +38,16 @@ def swap_items(self, vendor, my_item, their_item): self.remove(my_item) vendor.add(my_item) vendor.remove(their_item) + return True + + def swap_first_item(self, vendor): + if self.inventory == [] or vendor.inventory == []: + return False + + self.add(vendor.inventory[0]) + self.remove(self.inventory[0]) + vendor.add(self.inventory[0]) + vendor.remove(vendor.inventory[0]) + print(self.inventory) + print(vendor.inventory) 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..e79b51c1f 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") From 9d92db0f59f3f5212a49f07ad69135f7904a9a0f Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Wed, 5 Oct 2022 14:16:39 -0700 Subject: [PATCH 07/28] Passed test 16 in Wave 4. Moved vendor.add(self.inventory[0]) up one line to come before item from self inventory was removed. --- swap_meet/vendor.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 4154a55db..f67cd86a9 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -45,9 +45,7 @@ def swap_first_item(self, vendor): return False self.add(vendor.inventory[0]) - self.remove(self.inventory[0]) vendor.add(self.inventory[0]) + self.remove(self.inventory[0]) vendor.remove(vendor.inventory[0]) - print(self.inventory) - print(vendor.inventory) return True \ No newline at end of file From 82bb4001c5fe464b344b76c5083f9774cb8af98e Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Wed, 5 Oct 2022 14:17:41 -0700 Subject: [PATCH 08/28] passed test 17 of Wave 4. No edits to code needed, just uncommented test. --- tests/unit_tests/test_wave_04.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index e79b51c1f..74485e07f 100644 --- a/tests/unit_tests/test_wave_04.py +++ b/tests/unit_tests/test_wave_04.py @@ -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=[] From dd2a068ccb836ca48854c22e6f941d42a2edf5ff Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Wed, 5 Oct 2022 14:18:38 -0700 Subject: [PATCH 09/28] Passed test 18 of Wave 4. Uncommented test with no code changes needed to pass test. --- tests/unit_tests/test_wave_04.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index 74485e07f..f3c91e846 100644 --- a/tests/unit_tests/test_wave_04.py +++ b/tests/unit_tests/test_wave_04.py @@ -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 31e0e509496593ab407fa593a54abdcda28d35df Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Wed, 5 Oct 2022 14:23:04 -0700 Subject: [PATCH 10/28] Passed test 18 in Wave 5. Created dunder init in Clothing class as well as a stringify method. Uncomment first test of Wave 5. --- swap_meet/clothing.py | 6 +++++- tests/unit_tests/test_wave_05.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..266be3ca1 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,6 @@ class Clothing: - pass \ No newline at end of file + def __init__(self, category = "Clothing"): + self.category = category + + def __str__(self): + return "The finest clothing you could wear." \ 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..ba66f4d42 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -3,7 +3,7 @@ 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" From 0d557b3ffb728a85b2b080a049f97566b895cc2d Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Wed, 5 Oct 2022 14:25:41 -0700 Subject: [PATCH 11/28] Passed test 20 of Wave 5. Added dunder init constructor to Decor class as well as stringify method. --- swap_meet/decor.py | 7 ++++++- tests/unit_tests/test_wave_05.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/swap_meet/decor.py b/swap_meet/decor.py index eab7a9dbe..33ce958fb 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,7 @@ class Decor: - pass \ No newline at end of file + + def __init__(self, category = "Decor"): + self.category = category + + def __str__(self): + return "Something to decorate your space." \ 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 ba66f4d42..ac51d01bc 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -9,7 +9,7 @@ def test_clothing_has_default_category_and_to_str(): 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" From 64888fc2d00017f6c1521a9d8cb35e2939d23b68 Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Wed, 5 Oct 2022 14:28:29 -0700 Subject: [PATCH 12/28] Passed test 21 of Wave 5. Added dunder init to Electronics class in electronics.py. Also added stringify method to same lass. Uncommented test 21. --- swap_meet/electronics.py | 7 ++++++- tests/unit_tests/test_wave_05.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2f9dff68a..b1b4861bc 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,7 @@ class Electronics: - pass + + def __init__(self, category = "Electronics"): + self.category = category + + def __str__(self): + return "A gadget full of buttons and secrets." diff --git a/tests/unit_tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py index ac51d01bc..202fc6e0c 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -15,7 +15,7 @@ def test_decor_has_default_category_and_to_str(): 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" From 6dcc5167594d1b42cbe2e98f8e28dc3caac2e32b Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Wed, 5 Oct 2022 15:28:20 -0700 Subject: [PATCH 13/28] Passed test 22 in Wave 5. Tried importing test for a later test, but removed or commented out section to come back to it later. --- swap_meet/clothing.py | 7 +++++-- swap_meet/decor.py | 8 ++++++-- swap_meet/electronics.py | 8 ++++++-- swap_meet/item.py | 20 ++++++++++++++++++-- tests/unit_tests/test_wave_05.py | 2 +- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 266be3ca1..bb91f8e6f 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,6 +1,9 @@ -class Clothing: - def __init__(self, category = "Clothing"): +class Clothing(): + + def __init__(self, category = "Clothing", condition = 0): + #super().__init__(category = None, condition = 0) self.category = category + self.condition = 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 33ce958fb..deef79251 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,7 +1,11 @@ -class Decor: +#from item import Item + +class Decor(): - def __init__(self, category = "Decor"): + def __init__(self, category = "Decor", condition = 0): + #super().__init__(category = None, condition = 0) self.category = category + self.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 b1b4861bc..6b7263db6 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,7 +1,11 @@ -class Electronics: +#from item import Item + +class Electronics(): - def __init__(self, category = "Electronics"): + def __init__(self, category = "Electronics", condition = 0): + #super().__init__(category = None, condition = 0) self.category = category + self.condition = condition def __str__(self): return "A gadget full of buttons and secrets." diff --git a/swap_meet/item.py b/swap_meet/item.py index ad8735b96..22c5ab0f0 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,9 +1,25 @@ class Item: - def __init__(self, category = None): + def __init__(self, category = None, condition = 0): if category is None: category = "" 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, num): + if num >= 5: + return "Perfect in every way!" + elif num >= 4: + return "Not bad, not bad" + elif num >= 3: + return "I've seen worse" + elif num >= 2: + return "Well, at least it's free" + elif num >= 1: + return "Better than a poke in the eye with a sharp stick" + elif num > 0: + return "Oof" + \ 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 202fc6e0c..fac8abf7d 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -21,7 +21,7 @@ def test_electronics_has_default_category_and_to_str(): 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), From 18e7270474bcd7b8b786b32dab6146950891148d Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 07:35:26 -0700 Subject: [PATCH 14/28] Imported item to the Clothing, Decor, and Electronic classes. Also added super() to each dunder init of those classes. Wave 5. --- swap_meet/clothing.py | 6 ++++-- swap_meet/decor.py | 6 +++--- swap_meet/electronics.py | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index bb91f8e6f..1a38eece0 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,7 +1,9 @@ -class Clothing(): +from swap_meet.item import Item + +class Clothing(Item): def __init__(self, category = "Clothing", condition = 0): - #super().__init__(category = None, condition = 0) + super().__init__(category = None, condition = 0) self.category = category self.condition = condition diff --git a/swap_meet/decor.py b/swap_meet/decor.py index deef79251..d193429c2 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,9 +1,9 @@ -#from item import Item +from swap_meet.item import Item -class Decor(): +class Decor(Item): def __init__(self, category = "Decor", condition = 0): - #super().__init__(category = None, condition = 0) + super().__init__(category = None, condition = 0) self.category = category self.condition = condition diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 6b7263db6..38c6aa365 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,9 +1,9 @@ -#from item import Item +from swap_meet.item import Item -class Electronics(): +class Electronics(Item): def __init__(self, category = "Electronics", condition = 0): - #super().__init__(category = None, condition = 0) + super().__init__(category = None, condition = 0) self.category = category self.condition = condition From cce24a04100036556ba94eb4d16532e721147ba1 Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 07:41:32 -0700 Subject: [PATCH 15/28] Passed test 23 in Wave 5. Implemented Item as a parent class for Clothing, Decor, and Electronic classes to use the condition_description instance method within Item. --- swap_meet/item.py | 14 +++++++------- tests/unit_tests/test_wave_05.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 22c5ab0f0..b83a02c14 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -9,17 +9,17 @@ def __init__(self, category = None, condition = 0): def __str__(self): return "Hello World!" - def condition_description(self, num): - if num >= 5: + def condition_description(self): + if self.condition >= 5: return "Perfect in every way!" - elif num >= 4: + elif self.condition >= 4: return "Not bad, not bad" - elif num >= 3: + elif self.condition >= 3: return "I've seen worse" - elif num >= 2: + elif self.condition >= 2: return "Well, at least it's free" - elif num >= 1: + elif self.condition >= 1: return "Better than a poke in the eye with a sharp stick" - elif num > 0: + elif self.condition > 0: return "Oof" \ 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 fac8abf7d..8dedc9e28 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -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 fd4ad6600c82ef5ff22cd8aad7513e39d091e7c1 Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 07:51:35 -0700 Subject: [PATCH 16/28] Implemented list comprehension in my get_by_category instance method of my Vendor class. --- swap_meet/vendor.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index f67cd86a9..07f0ab88e 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -19,12 +19,8 @@ def remove(self, item): return item def get_by_category(self, category): - items_list = [] - - for item in self.inventory: - if item.category == category: - items_list.append(item) - + items_list = [item for item in self.inventory if item.category == category] + if items_list == []: return [] @@ -48,4 +44,7 @@ def swap_first_item(self, vendor): vendor.add(self.inventory[0]) self.remove(self.inventory[0]) vendor.remove(vendor.inventory[0]) - return True \ No newline at end of file + return True + + def get_best_by_category(self, category): + pass \ No newline at end of file From f23421aff0fd5fd7f8f332fced6488193df00b2c Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 12:43:17 -0700 Subject: [PATCH 17/28] Passed 24th test in Wave 6. Implemented best_by_category function using max() and lambda. --- swap_meet/vendor.py | 11 ++++++++--- tests/unit_tests/test_wave_06.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 07f0ab88e..5e98ea7ed 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,10 +1,12 @@ from operator import itemgetter +from swap_meet.item import Item -class Vendor: +class Vendor(Item): def __init__(self, inventory = None): if inventory is None: inventory = [] + super().__init__(category = None, condition = 0) self.inventory = inventory @@ -23,7 +25,6 @@ def get_by_category(self, category): if items_list == []: return [] - return items_list def swap_items(self, vendor, my_item, their_item): @@ -47,4 +48,8 @@ def swap_first_item(self, vendor): return True def get_best_by_category(self, category): - pass \ No newline at end of file + + best_item = max(self.get_by_category(category), key = lambda i : i.condition) + if best_item is None: + return None + 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..a26ce750e 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 c8fc03415f175ddeb5dae90430f154810712fe8a Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 12:46:33 -0700 Subject: [PATCH 18/28] Passed 25th test in Wave 6. Added docstring to get_best_by_category. Also added code if no item within category, return None. --- swap_meet/vendor.py | 9 ++++++--- tests/unit_tests/test_wave_06.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 5e98ea7ed..1ae9a6c41 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -48,8 +48,11 @@ def swap_first_item(self, vendor): return True def get_best_by_category(self, category): - - best_item = max(self.get_by_category(category), key = lambda i : i.condition) - if best_item is None: + ''' + Input: category of item + Output: item of best condition within that category + ''' + if self.get_by_category(category) == []: return None + best_item = max(self.get_by_category(category), key = lambda i : i.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 a26ce750e..d6d54aea2 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) From 23795d9ce51f0dff20587c8b419f66235d1988e0 Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 12:47:13 -0700 Subject: [PATCH 19/28] Passed test 26 of Wave 6. Uncommented test. --- tests/unit_tests/test_wave_06.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index d6d54aea2..eff08d4a6 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -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) From aba2f2e11c634919512de0f06e7fb07fe474d66d Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 13:12:33 -0700 Subject: [PATCH 20/28] Passed test 27 of Wave 6. Added assert statements to test_swap_best_by_category test. Implemented swap_best_by_category in Vendor class. --- swap_meet/vendor.py | 19 ++++++++++++++++++- tests/unit_tests/test_wave_06.py | 13 +++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 1ae9a6c41..ce1c90b79 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -55,4 +55,21 @@ def get_best_by_category(self, category): if self.get_by_category(category) == []: return None best_item = max(self.get_by_category(category), key = lambda i : i.condition) - return best_item \ No newline at end of file + return best_item + + def swap_best_by_category(self, other, my_priority, their_priority): + ''' + Input: other (for other vendor), my_priority (category vendor prefers), + and their_priority (category other vendor prefers) + Output: + - returns True if best item in Vendor inventory matches their_priority + and is swapped with the best item in other's inventory + - returns False if not matches + ''' + vendor_best_item = self.get_best_by_category(their_priority) + other_best_item = other.get_best_by_category(my_priority) + + if vendor_best_item is None or other_best_item is None: + return False + self.swap_items(other, vendor_best_item, other_best_item) + 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 eff08d4a6..45d27252e 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -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 ********** # ********************************************************************* @@ -84,6 +84,15 @@ def test_swap_best_by_category(): # - That the results is truthy # - 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 + assert result == True + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_f in tai.inventory + assert item_c in jesse.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory @pytest.mark.skip def test_swap_best_by_category_reordered(): From 3975c2f9c59db7d7c7b7245ce8fbf6a673621773 Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 13:18:32 -0700 Subject: [PATCH 21/28] Passed test 28 of Wave 6. Added assert statements, commented test skip decorator and raise exception decorator. --- tests/unit_tests/test_wave_06.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 45d27252e..a11daf426 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -94,7 +94,7 @@ def test_swap_best_by_category(): assert item_d in jesse.inventory assert item_e in jesse.inventory -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_reordered(): # Arrange item_a = Decor(condition=2.0) @@ -118,7 +118,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 ********** # ********************************************************************* @@ -126,6 +126,15 @@ def test_swap_best_by_category_reordered(): # - That result is truthy # - 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 + assert result == True + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_f in tai.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_c in jesse.inventory @pytest.mark.skip def test_swap_best_by_category_no_inventory_is_false(): From f055e10ec36225a6ec238cea13c9f6e81b7bb779 Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 13:19:25 -0700 Subject: [PATCH 22/28] Passed test 29 of Wave 6. Commented out test skip decorator. Passed without needing to update code. --- tests/unit_tests/test_wave_06.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index a11daf426..ea4838857 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -136,7 +136,7 @@ def test_swap_best_by_category_reordered(): assert item_e 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=[] From 2d644aa331e70f65ec58f7c99c690afda04115c3 Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 13:21:01 -0700 Subject: [PATCH 23/28] Passed test 30 of Wave 6. Commented test skip decorator. Passed without updating code. --- tests/unit_tests/test_wave_06.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index ea4838857..7b69957b0 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -162,7 +162,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) From 1af9f0f57f913f3b44a9b16d0a4084380a33461c Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 13:24:04 -0700 Subject: [PATCH 24/28] Passed test 31 of Wave 6. Added assert statements to test_swap_best_by_category_no_match_is_false. --- tests/unit_tests/test_wave_06.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 7b69957b0..f60164a00 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -188,7 +188,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) @@ -212,7 +212,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 ********** # ********************************************************************* @@ -220,6 +220,15 @@ def test_swap_best_by_category_no_match_is_false(): # - 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(jesse.inventory) == 3 + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_f in jesse.inventory @pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): From 4b3538d39323f6f9fd883a9d79a69de8e06e3e2f Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 13:25:31 -0700 Subject: [PATCH 25/28] Passed test 32 of Wave 6. Added assert statements to test. --- tests/unit_tests/test_wave_06.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index f60164a00..8a925c63e 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -230,7 +230,7 @@ def test_swap_best_by_category_no_match_is_false(): assert item_e in jesse.inventory assert item_f in jesse.inventory -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -254,7 +254,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 ********** # ********************************************************************* @@ -262,3 +262,13 @@ def test_swap_best_by_category_no_other_match_is_false(): # - 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(jesse.inventory) == 3 + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_c in tai.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_f in jesse.inventory + From 34ef29eda8a0f86d0f81918c52eceeca716379ad Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 13:26:33 -0700 Subject: [PATCH 26/28] Passed final integration test. Commented out integration test decorator. --- tests/integration_tests/test_wave_04_05_06.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tests/test_wave_04_05_06.py b/tests/integration_tests/test_wave_04_05_06.py index 4d0be9909..25f268c85 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() From 608628f8c4acc12f9ccb95d861122825cae9564d Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 13:58:15 -0700 Subject: [PATCH 27/28] Updated swap_first_item to DRY code. --- swap_meet/vendor.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index ce1c90b79..a4f24b96d 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -41,10 +41,7 @@ def swap_first_item(self, vendor): if self.inventory == [] or vendor.inventory == []: return False - self.add(vendor.inventory[0]) - vendor.add(self.inventory[0]) - self.remove(self.inventory[0]) - vendor.remove(vendor.inventory[0]) + self.swap_items(vendor, self.inventory[0], vendor.inventory[0]) return True def get_best_by_category(self, category): @@ -59,12 +56,8 @@ def get_best_by_category(self, category): def swap_best_by_category(self, other, my_priority, their_priority): ''' - Input: other (for other vendor), my_priority (category vendor prefers), - and their_priority (category other vendor prefers) - Output: - - returns True if best item in Vendor inventory matches their_priority - and is swapped with the best item in other's inventory - - returns False if not matches + Input: other (for other vendor), my_priority (category vendor prefers),and their_priority (category other vendor prefers) + Output: returns True if both Vendor and other Vendor have items in prioritized by their respective swappers ''' vendor_best_item = self.get_best_by_category(their_priority) other_best_item = other.get_best_by_category(my_priority) From ca0636e16c326c26cfa7371e39d9d4663af23192 Mon Sep 17 00:00:00 2001 From: Sarah Sanborn Date: Thu, 6 Oct 2022 19:11:16 -0700 Subject: [PATCH 28/28] Updated swap_first_item method so my conditional checks if inventory length is zero rather than an empty list. --- swap_meet/vendor.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index a4f24b96d..daefa356d 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -31,6 +31,8 @@ def swap_items(self, vendor, my_item, their_item): if my_item not in self.inventory or their_item not in vendor.inventory: return False + # I hard-coded this, but was curious about how this could be scaled-up. + # What would happen if this swap-meet went viral? self.add(their_item) self.remove(my_item) vendor.add(my_item) @@ -38,17 +40,13 @@ def swap_items(self, vendor, my_item, their_item): return True def swap_first_item(self, vendor): - if self.inventory == [] or vendor.inventory == []: + if len(self.inventory) == 0 or len(vendor.inventory) == 0: return False self.swap_items(vendor, self.inventory[0], vendor.inventory[0]) return True def get_best_by_category(self, category): - ''' - Input: category of item - Output: item of best condition within that category - ''' if self.get_by_category(category) == []: return None best_item = max(self.get_by_category(category), key = lambda i : i.condition) @@ -57,7 +55,7 @@ def get_best_by_category(self, category): def swap_best_by_category(self, other, my_priority, their_priority): ''' Input: other (for other vendor), my_priority (category vendor prefers),and their_priority (category other vendor prefers) - Output: returns True if both Vendor and other Vendor have items in prioritized by their respective swappers + Output: Returns True if swap is successful. Returns False if swap is unsuccessful ''' vendor_best_item = self.get_best_by_category(their_priority) other_best_item = other.get_best_by_category(my_priority)