From 9cb10dbd09c4a875a857028d722523bb2666ce91 Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 11:19:21 -0700 Subject: [PATCH 01/25] testing a small change --- swap_meet/vendor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..5225a2b41 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,3 @@ class Vendor: + #testing a small change for git hub pass \ No newline at end of file From a94fc8f0336ad6175ec9df83e18f3ebf63676b7f Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 11:29:11 -0700 Subject: [PATCH 02/25] passed the first 2 tests of wave 1 --- swap_meet/vendor.py | 8 +++++++- tests/unit_tests/test_wave_01.py | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 5225a2b41..addd2434e 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,3 +1,9 @@ class Vendor: #testing a small change for git hub - pass \ No newline at end of file + def __init__(self, inventory = None): + #if an inventory list is given, assign it to the attribute + if inventory: + self.inventory = inventory + #if no inventory list is given, initialize an empty list for inventory. + else: + self.inventory = [] \ 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..129d1395c 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) From 625834d312944d96ca5eb099ab0a06a441b33598 Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 11:34:13 -0700 Subject: [PATCH 03/25] passed test 3 of wave 1 --- swap_meet/vendor.py | 9 ++++++++- tests/unit_tests/test_wave_01.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index addd2434e..c2d594e7c 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -6,4 +6,11 @@ def __init__(self, inventory = None): self.inventory = inventory #if no inventory list is given, initialize an empty list for inventory. else: - self.inventory = [] \ No newline at end of file + self.inventory = [] + + def add(self, item): + #append the item to the inventory list. + self.inventory.append(item) + #return the new item + return item + \ 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 129d1395c..852e809a3 100644 --- a/tests/unit_tests/test_wave_01.py +++ b/tests/unit_tests/test_wave_01.py @@ -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" From a139785125997bdbf362565fd80bea4bbec8fe99 Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 11:42:00 -0700 Subject: [PATCH 04/25] passed test 4 of wave 1 --- swap_meet/vendor.py | 15 ++++++++++++--- tests/unit_tests/test_wave_01.py | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index c2d594e7c..31f3a0bfb 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,5 +1,6 @@ class Vendor: - #testing a small change for git hub + """The Vendor class has optional arguement inventory, + methods .add(item), .remove(item)""" def __init__(self, inventory = None): #if an inventory list is given, assign it to the attribute if inventory: @@ -9,8 +10,16 @@ def __init__(self, inventory = None): self.inventory = [] def add(self, item): - #append the item to the inventory list. + """appends the item to the inventory list and returns the item""" self.inventory.append(item) - #return the new item return item + + def remove(self, item): + """removes an item from the inventory list""" + #if item is in inventory, remove it + + self.inventory.remove(item) + + return item + \ 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 852e809a3..fc470e81c 100644 --- a/tests/unit_tests/test_wave_01.py +++ b/tests/unit_tests/test_wave_01.py @@ -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( From 5a0519077e51fa481f919aa60d5497f5a7f8054a Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 11:45:37 -0700 Subject: [PATCH 05/25] passed all of wave 1 --- swap_meet/vendor.py | 9 +++++---- tests/unit_tests/test_wave_01.py | 9 +++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 31f3a0bfb..610503765 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -17,9 +17,10 @@ def add(self, item): def remove(self, item): """removes an item from the inventory list""" #if item is in inventory, remove it - - self.inventory.remove(item) - - return item + if item in self.inventory: + self.inventory.remove(item) + return item + else: + 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 fc470e81c..a02a99754 100644 --- a/tests/unit_tests/test_wave_01.py +++ b/tests/unit_tests/test_wave_01.py @@ -40,7 +40,7 @@ def test_removing_from_inventory_returns_item(): assert item not in vendor.inventory assert result == item -@pytest.mark.skip +#@pytest.mark.skip def test_removing_not_found_is_false(): item = "item to remove" vendor = Vendor( @@ -48,8 +48,5 @@ def test_removing_not_found_is_false(): ) result = vendor.remove(item) - - raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* + #assert: + result == False From 81e696b1d0b6c5de58ee9e7a02a66346bf5a5699 Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 11:48:55 -0700 Subject: [PATCH 06/25] passed wave 2 test 1 --- swap_meet/item.py | 3 ++- tests/unit_tests/test_wave_02.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 560d759c2..63c996000 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,3 @@ class Item: - pass \ No newline at end of file + def __init__(self, category = ""): + self.category = category \ 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..5ecac69e5 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.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_items_have_blank_default_category(): item = Item() assert item.category == "" From bb647932267439dc70e870b3fd61ff158f134789 Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 11:55:31 -0700 Subject: [PATCH 07/25] passed test 2 of wave 2 - get_by_category() --- swap_meet/vendor.py | 12 ++++++++++-- tests/unit_tests/test_wave_02.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 610503765..bb4aeb5da 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,6 +1,6 @@ class Vendor: """The Vendor class has optional arguement inventory, - methods .add(item), .remove(item)""" + methods: .add(item), .remove(item), .get_by_category(category)""" def __init__(self, inventory = None): #if an inventory list is given, assign it to the attribute if inventory: @@ -23,4 +23,12 @@ def remove(self, item): else: return False - \ No newline at end of file + def get_by_category(self, category): + """given a category, return a list of all items in inventory + that have that as their attribute category.""" + items_in_category = [] + #iterate through inventory to append items with the given category + for item in self.inventory: + if item.category == category: + items_in_category.append(item) + return items_in_category \ 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 5ecac69e5..5e52069a1 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -7,7 +7,7 @@ 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") From 8629a03f113b0e47b114bf2d45fffe7bde646c9c Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 12:00:56 -0700 Subject: [PATCH 08/25] passed all wave 2 tests --- tests/unit_tests/test_wave_02.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index 5e52069a1..48891c339 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -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,7 @@ def test_get_no_matching_items_by_category(): items = vendor.get_by_category("electronics") - 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 From 4c8b79fb1da1cdd7a3a9322b4f88ebd3a67c7dc8 Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 12:06:10 -0700 Subject: [PATCH 09/25] passed wave 3 test 1 --- swap_meet/item.py | 4 +++- tests/unit_tests/test_wave_03.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 63c996000..6d94b6910 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,3 +1,5 @@ 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..5db37cf09 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() From 8b841404d0c0ca2fffd015779ff4758018e82775 Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 13:08:55 -0700 Subject: [PATCH 10/25] passed wave 3 test 2 --- swap_meet/vendor.py | 20 ++++++++++++++++++-- tests/unit_tests/test_wave_03.py | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index bb4aeb5da..b70325d20 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,6 +1,7 @@ class Vendor: """The Vendor class has optional arguement inventory, - methods: .add(item), .remove(item), .get_by_category(category)""" + methods: .add(item), .remove(item), .get_by_category(category), + swap_items(swapping_vendor, my_item, their_item)""" def __init__(self, inventory = None): #if an inventory list is given, assign it to the attribute if inventory: @@ -31,4 +32,19 @@ def get_by_category(self, category): for item in self.inventory: if item.category == category: items_in_category.append(item) - return items_in_category \ No newline at end of file + return items_in_category + + def swap_items(self, swapping_vendor, my_item, their_item): + """given another vendor, my_item to swap, their_item to receive, make that swap.""" + #if each item is in the right place, make the swap: + if my_item in self.inventory and their_item in swapping_vendor.inventory: + #make the swap + self.remove(my_item) + self.add(their_item) + swapping_vendor.add(my_item) + swapping_vendor.remove(their_item) + + return True + else: + return False + diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 5db37cf09..8567504bb 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -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 619f19e905db099b7059a2c788352ebc456fa4ea Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 13:43:54 -0700 Subject: [PATCH 11/25] passed all tests of wave 3 --- tests/unit_tests/test_wave_03.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 8567504bb..720879a7c 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 f92347889bfc4f8233ea1212c7f4b0d8b57dafcb Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 13:49:26 -0700 Subject: [PATCH 12/25] passed test 1 of wave 4 --- swap_meet/vendor.py | 6 ++++++ tests/unit_tests/test_wave_04.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index b70325d20..0d619d8db 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -48,3 +48,9 @@ def swap_items(self, swapping_vendor, my_item, their_item): else: return False + def swap_first_item(self, swapping_vendor): + """given another vendor, swap the first item + in each of your inventories.""" + #call swap_items, inputing the first item on each of your inventories: + result = self.swap_items(swapping_vendor, self.inventory[0], swapping_vendor.inventory[0]) + return result 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 5a714220ae3b0d499d7120d6aca03e2e0b1baa68 Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 15:41:19 -0700 Subject: [PATCH 13/25] passed through wave 5 test 1 --- swap_meet/clothing.py | 6 +++++- swap_meet/decor.py | 6 +++++- swap_meet/vendor.py | 10 +++++++--- tests/unit_tests/test_wave_04.py | 4 ++-- tests/unit_tests/test_wave_05.py | 4 ++-- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..f48e42422 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/swap_meet/decor.py b/swap_meet/decor.py index eab7a9dbe..22d244658 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,6 @@ 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/swap_meet/vendor.py b/swap_meet/vendor.py index 0d619d8db..6c9618455 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -51,6 +51,10 @@ def swap_items(self, swapping_vendor, my_item, their_item): def swap_first_item(self, swapping_vendor): """given another vendor, swap the first item in each of your inventories.""" - #call swap_items, inputing the first item on each of your inventories: - result = self.swap_items(swapping_vendor, self.inventory[0], swapping_vendor.inventory[0]) - return result + if self.inventory and swapping_vendor.inventory: + #call swap_items, inputing the first item on each of your inventories: + result = self.swap_items(swapping_vendor, self.inventory[0], swapping_vendor.inventory[0]) + return result + else: + return False + diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index e79b51c1f..f3c91e846 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=[] @@ -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") diff --git a/tests/unit_tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py index 7abea06cd..ac51d01bc 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -3,13 +3,13 @@ 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" From 87db152aa8f327aa5add9485133c99bc9bf5ff8e Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 3 Oct 2022 15:44:14 -0700 Subject: [PATCH 14/25] passed tests 1-3 of wave 5 --- swap_meet/electronics.py | 5 ++++- tests/unit_tests/test_wave_05.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2f9dff68a..ec5e107c3 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,5 @@ 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 8bd0b070008b7bfb8e6f5dd08d3ea7efefbf115b Mon Sep 17 00:00:00 2001 From: LP Date: Tue, 4 Oct 2022 09:51:48 -0700 Subject: [PATCH 15/25] passed all but 1 of wave5 tests --- swap_meet/clothing.py | 4 ++-- swap_meet/decor.py | 3 ++- swap_meet/electronics.py | 3 ++- swap_meet/item.py | 3 ++- tests/unit_tests/test_wave_05.py | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index f48e42422..39946d46c 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,6 +1,6 @@ class Clothing: - def __init__(self, category = "Clothing"): + def __init__(self, category = "Clothing", condition = 0.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 22d244658..b84993f5f 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,6 +1,7 @@ class Decor: - def __init__(self, category = "Decor"): + def __init__(self, category = "Decor", condition = 0.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 ec5e107c3..32f302f1c 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,5 +1,6 @@ class Electronics: - def __init__(self, category = "Electronics"): + def __init__(self, category = "Electronics", 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 6d94b6910..56274339e 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,5 +1,6 @@ class Item: - def __init__(self, category = ""): + def __init__(self, category = "", conditon = 0.0): self.category = category + self.condition = condition def __str__(self): return "Hello World!" \ 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 b87351c782562c78db9721c2ce21e1ddc2067455 Mon Sep 17 00:00:00 2001 From: LP Date: Tue, 4 Oct 2022 10:31:01 -0700 Subject: [PATCH 16/25] refactored wave 5 to inherit from item class. one more test to go in wave 5 still --- swap_meet/clothing.py | 7 ++++--- swap_meet/decor.py | 7 ++++--- swap_meet/electronics.py | 9 +++++---- swap_meet/item.py | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 39946d46c..7c416c482 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,6 +1,7 @@ -class Clothing: +from swap_meet.item import Item + +class Clothing(Item): def __init__(self, category = "Clothing", condition = 0.0): - self.category = category - self.condition = condition + super().__init__(category, 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 b84993f5f..47921351f 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,7 +1,8 @@ -class Decor: +from swap_meet.item import Item + +class Decor(Item): def __init__(self, category = "Decor", condition = 0.0): - self.category = category - self.condition = condition + super().__init__(category, 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 32f302f1c..05cf55dee 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,6 +1,7 @@ -class Electronics: - def __init__(self, category = "Electronics", condition = 0.): - self.category = category - self.condition = condition +from swap_meet.item import Item + +class Electronics(Item): + def __init__(self, category = "Electronics", condition = 0.0): + super().__init__(category, 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 56274339e..348eb30c6 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,5 +1,5 @@ class Item: - def __init__(self, category = "", conditon = 0.0): + def __init__(self, category = "", condition = 0.0): self.category = category self.condition = condition def __str__(self): From 2d63659be24819a1112b3dc91be9cd505904075d Mon Sep 17 00:00:00 2001 From: LP Date: Tue, 4 Oct 2022 10:55:49 -0700 Subject: [PATCH 17/25] passed all tests of wave 5 --- swap_meet/item.py | 13 ++++++++++++- tests/unit_tests/test_wave_05.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 348eb30c6..e923e4c35 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -3,4 +3,15 @@ def __init__(self, category = "", condition = 0.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): + if self.condition <= 1: + return "OMG Don't swap for this!" + elif self.condition <= 2: + return "This item is well-loved" + elif self.condition <= 3: + return "This is average qualtiy" + elif self.condition <= 4: + return "This is in pretty good condition" + else: + return "Love this. Great condition." \ 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 618a62925e49164afeb0f5e6f6b5a8cc3a3d3913 Mon Sep 17 00:00:00 2001 From: LP Date: Tue, 4 Oct 2022 10:56:22 -0700 Subject: [PATCH 18/25] passed all tests of wave 5 --- swap_meet/clothing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 7c416c482..fc37b9da3 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -2,6 +2,7 @@ class Clothing(Item): def __init__(self, category = "Clothing", condition = 0.0): + #is there a way to NOT have condition here??I don't think so. super().__init__(category, condition) def __str__(self): return "The finest clothing you could wear." \ No newline at end of file From 7c9667bc801d4503209a446c795eb6765f3db428 Mon Sep 17 00:00:00 2001 From: LP Date: Tue, 4 Oct 2022 11:08:29 -0700 Subject: [PATCH 19/25] passed test 1 of wave 6 --- swap_meet/vendor.py | 20 +++++++++++++++++++ tests/integration_tests/test_wave_01_02_03.py | 2 +- tests/unit_tests/test_wave_06.py | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 6c9618455..e2ad61e8d 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -58,3 +58,23 @@ def swap_first_item(self, swapping_vendor): else: return False + def get_best_by_category(self, category): + """this will return the best item a vendor has in a given category""" + #In the case of a tie, it will return the LAST instance of this item. + best_item = None + items_in_category = [] + for item in self.inventory: + if item.category == category: + items_in_category.append(item) + #I think there's a faster way to do this, in one loop. + #for now, I'm just going to get it working. + if items_in_category: + best_item = items_in_category[0] + for cat_item in items_in_category: + if cat_item.condition >= best_item.condition: + best_item = cat_item + return best_item + + + + 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_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 99a17151087df7b189dcf4f62c4ad1916bca3b14 Mon Sep 17 00:00:00 2001 From: LP Date: Tue, 4 Oct 2022 11:10:03 -0700 Subject: [PATCH 20/25] passed tests 1-3 of wave 6 --- tests/unit_tests/test_wave_06.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index a26ce750e..eff08d4a6 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -20,7 +20,7 @@ def test_best_by_category(): assert best_item.category == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip +#@pytest.mark.skip def test_best_by_category_no_matches_is_none(): item_a = Decor(condition=2.0) item_b = Decor(condition=2.0) @@ -33,7 +33,7 @@ def test_best_by_category_no_matches_is_none(): assert best_item is None -@pytest.mark.skip +#@pytest.mark.skip def test_best_by_category_with_duplicates(): # Arrange item_a = Clothing(condition=2.0) From b9c08ab5dff29b4816bcdd9f0be4f85ace1ca82f Mon Sep 17 00:00:00 2001 From: LP Date: Tue, 4 Oct 2022 12:01:27 -0700 Subject: [PATCH 21/25] passed first 4 test of wave 6 --- swap_meet/vendor.py | 16 +++++++++++++--- tests/unit_tests/test_wave_06.py | 22 +++++++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index e2ad61e8d..0da3aa90b 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -74,7 +74,17 @@ def get_best_by_category(self, category): if cat_item.condition >= best_item.condition: best_item = cat_item return best_item - - - + + def swap_best_by_category(self, other, my_priority, their_priority): + """This will swap two items: self will give their item + of highest quality from the category their_priority. + In return, the swapping_vendor will give their best item from + the category my_priority.""" + #figure out what items will be swapped. + my_item_to_swap = self.get_best_by_category(their_priority) + their_item_to_swap = other.get_best_by_category(my_priority) + result = self.swap_items(other, my_item_to_swap, their_item_to_swap) + return result + + diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index eff08d4a6..3590df810 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,15 +76,19 @@ def test_swap_best_by_category(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* - # Assertions should check: - # - 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 + assert result + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 + + assert item_f in tai.inventory + assert item_a in tai.inventory + assert item_b 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(): # Arrange From d7d3cd81fe3d64b9e94718f23de85649d9e746ca Mon Sep 17 00:00:00 2001 From: LP Date: Tue, 4 Oct 2022 12:36:27 -0700 Subject: [PATCH 22/25] passed test 6 of wave 5 --- tests/unit_tests/test_wave_06.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 3590df810..efef7d46b 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -89,7 +89,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) @@ -113,15 +113,21 @@ def test_swap_best_by_category_reordered(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* - # Assertions should check: - # - 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 + assert result + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 + + assert item_f in tai.inventory + assert item_a in tai.inventory + assert item_b 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(): tai = Vendor( From edfb694cc1b5bbb5476b9a4b7d77abd85c32a81e Mon Sep 17 00:00:00 2001 From: LP Date: Tue, 4 Oct 2022 12:50:06 -0700 Subject: [PATCH 23/25] passed all but one test of wave 6 --- tests/unit_tests/test_wave_06.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index efef7d46b..9da0bd355 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -128,7 +128,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=[] @@ -154,7 +154,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) @@ -180,7 +180,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) @@ -204,10 +204,16 @@ def test_swap_best_by_category_no_match_is_false(): their_priority="Clothing" ) - raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* + 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 + # Assertions should check: # - That result is falsy # - That tai and jesse's inventories are the correct length From 6b2175682b340a0f375121c53b3ccf48984f7a84 Mon Sep 17 00:00:00 2001 From: LP Date: Tue, 4 Oct 2022 12:51:57 -0700 Subject: [PATCH 24/25] passed all tests --- tests/integration_tests/test_wave_04_05_06.py | 2 +- tests/unit_tests/test_wave_06.py | 24 ++++++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) 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() diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 9da0bd355..aec847eb6 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -213,13 +213,8 @@ def test_swap_best_by_category_no_match_is_false(): assert item_d in jesse.inventory assert item_e in jesse.inventory assert item_f in jesse.inventory - - # Assertions should check: - # - That result is falsy - # - That tai and jesse's inventories are the correct length - # - That all the correct items are in tai and jesse's inventories -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -243,11 +238,12 @@ def test_swap_best_by_category_no_other_match_is_false(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") - # ********************************************************************* - # ****** Complete Assert Portion of this test ********** - # ********************************************************************* - # Assertions should check: - # - That result is falsy - # - That tai and jesse's inventories are the correct length - # - That all the correct items are in tai and jesse's inventories + assert not result + assert len(tai.inventory) == 3 + assert len(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 \ No newline at end of file From e4b55733f0f061cbcb29bc5f2065cab965d824b6 Mon Sep 17 00:00:00 2001 From: LP Date: Mon, 17 Oct 2022 12:50:16 -0700 Subject: [PATCH 25/25] refactored to make the code more readable and use a few list comprehensions --- swap_meet/vendor.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 0da3aa90b..2dd8a2e7e 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -27,11 +27,14 @@ def remove(self, item): def get_by_category(self, category): """given a category, return a list of all items in inventory that have that as their attribute category.""" - items_in_category = [] - #iterate through inventory to append items with the given category - for item in self.inventory: - if item.category == category: - items_in_category.append(item) + # items_in_category = [] + # #iterate through inventory to append items with the given category + # for item in self.inventory: + # if item.category == category: + # items_in_category.append(item) + + items_in_category = [item for item in self.inventory if item.category == category] + return items_in_category def swap_items(self, swapping_vendor, my_item, their_item): @@ -62,12 +65,8 @@ def get_best_by_category(self, category): """this will return the best item a vendor has in a given category""" #In the case of a tie, it will return the LAST instance of this item. best_item = None - items_in_category = [] - for item in self.inventory: - if item.category == category: - items_in_category.append(item) - #I think there's a faster way to do this, in one loop. - #for now, I'm just going to get it working. + items_in_category = self.get_by_category(category) + if items_in_category: best_item = items_in_category[0] for cat_item in items_in_category: