From 0e3b752fe20ab647b5f77a457cdcac9bc2925695 Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Mon, 4 Apr 2022 11:36:41 -0700 Subject: [PATCH 01/12] wave 1: 4/5 tests passed --- swap_meet/vendor.py | 16 +++++++++++++++- tests/unit_tests/test_wave_01.py | 8 ++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..ece282b3b 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,16 @@ class Vendor: - pass \ No newline at end of file + def __init__(self, inventory = []): + self.inventory = inventory + + # This method adds the item to the inventory + def add(self, item): + self.inventory.append(item) + return item + + # This method removes the matching item from the inventory + def remove(self, item): + if item not in self.inventory: + return False + else: + self.inventory.remove(item) + return item diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index 58478ccf9..fc470e81c 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( From 122b93eb1b8dd2c70843b400cbddd12f3bfa42eb Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Mon, 4 Apr 2022 11:43:21 -0700 Subject: [PATCH 02/12] wave 1: all tests passed --- tests/unit_tests/test_wave_01.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index fc470e81c..61fe92feb 100644 --- a/tests/unit_tests/test_wave_01.py +++ b/tests/unit_tests/test_wave_01.py @@ -48,8 +48,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 result == False From f5795171a5061666e8f88054d94fe68035934e24 Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Mon, 4 Apr 2022 11:51:46 -0700 Subject: [PATCH 03/12] wave 2 started --- swap_meet/item.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 560d759c2..cf00b2e43 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,5 @@ class Item: - pass \ No newline at end of file + + def __init__(self, category = ""): + self.category = category + From b7e4353f4588a6d6d6624f470891e224966d4cbc Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Tue, 5 Apr 2022 12:37:42 -0700 Subject: [PATCH 04/12] wave 2: all tests passed --- swap_meet/vendor.py | 13 +++++++++++++ tests/unit_tests/test_wave_02.py | 11 +++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index ece282b3b..6eb78ae5e 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,3 +1,5 @@ +from swap_meet.item import Item + class Vendor: def __init__(self, inventory = []): self.inventory = inventory @@ -14,3 +16,14 @@ def remove(self, item): else: self.inventory.remove(item) return item + + # Takes one argument: a string, representing a category + # Returns a list of Items in the inventory with that category + def get_by_category(self, category): + #self.item = Item(category) + item_list = [] + for item in self.inventory: + if item.category == category: + item_list.append(item) + return item_list + diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index 3d7060d7c..f51fa588f 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,10 @@ 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 item_a not in items + assert item_b not in items + assert item_c not in items \ No newline at end of file From 07d9e1d585e3553081aa87bb8ea7fbe02a366f10 Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Tue, 5 Apr 2022 13:05:14 -0700 Subject: [PATCH 05/12] wave 3: all tests passed --- swap_meet/item.py | 6 ++++++ swap_meet/vendor.py | 20 ++++++++++++++++++-- tests/unit_tests/test_wave_01.py | 2 +- tests/unit_tests/test_wave_03.py | 12 ++++++------ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index cf00b2e43..a20826fc4 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -3,3 +3,9 @@ class Item: def __init__(self, category = ""): self.category = category + #override str() for Item, returns "Hello World!" instead + def __str__(self): + return "Hello World!" + + + diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 6eb78ae5e..a3067f5d6 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -4,12 +4,12 @@ class Vendor: def __init__(self, inventory = []): self.inventory = inventory - # This method adds the item to the inventory + # Adds the item to the inventory def add(self, item): self.inventory.append(item) return item - # This method removes the matching item from the inventory + # Removes the matching item from the inventory def remove(self, item): if item not in self.inventory: return False @@ -27,3 +27,19 @@ def get_by_category(self, category): item_list.append(item) return item_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 + + vendor.add(my_item) + self.remove(my_item) + + self.add(their_item) + vendor.remove(their_item) + + return True + + + + diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index 61fe92feb..b41df178d 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( diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 0300b638f..720879a7c 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -2,7 +2,7 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +#@pytest.mark.skip def test_item_overrides_to_string(): item = Item() @@ -10,7 +10,7 @@ def test_item_overrides_to_string(): assert stringified_item == "Hello World!" -@pytest.mark.skip +#@pytest.mark.skip def test_swap_items_returns_true(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -38,7 +38,7 @@ def test_swap_items_returns_true(): assert item_b in jolie.inventory assert result -@pytest.mark.skip +#@pytest.mark.skip def test_swap_items_when_my_item_is_missing_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -65,7 +65,7 @@ def test_swap_items_when_my_item_is_missing_returns_false(): assert item_e in jolie.inventory assert not result -@pytest.mark.skip +#@pytest.mark.skip def test_swap_items_when_their_item_is_missing_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -92,7 +92,7 @@ def test_swap_items_when_their_item_is_missing_returns_false(): assert item_e in jolie.inventory assert not result -@pytest.mark.skip +#@pytest.mark.skip def test_swap_items_from_my_empty_returns_false(): fatimah = Vendor( inventory=[] @@ -112,7 +112,7 @@ def test_swap_items_from_my_empty_returns_false(): assert len(jolie.inventory) == 2 assert not result -@pytest.mark.skip +#@pytest.mark.skip def test_swap_items_from_their_empty_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") From c5334e566d2962cac9fd74dda35223804be25f81 Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Tue, 5 Apr 2022 13:13:19 -0700 Subject: [PATCH 06/12] wave 4: all tests passed --- swap_meet/vendor.py | 23 ++++++++++++++++++++++- tests/unit_tests/test_wave_04.py | 6 +++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index a3067f5d6..519b04c19 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -27,8 +27,12 @@ def get_by_category(self, category): item_list.append(item) return item_list + # removes my_item from this Vendor's inventory + # adds my_item to the other Vendor's inventory + # removes their_item from other Vendor's inventory + # adds their_item to the this Vendor's inventory 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 @@ -40,6 +44,23 @@ def swap_items(self, vendor, my_item, their_item): return True + def swap_first_item(self, vendor): + if len(self.inventory) == 0 or len(vendor.inventory) == 0: + return False + + self.add(vendor.inventory[0]) + vendor.add(self.inventory[0]) + self.remove(self.inventory[0]) + vendor.remove(vendor.inventory[0]) + + return True + + + + + + + diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index 8190a4ebb..f3c91e846 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 0a1f4530d162df264cbfeb6a7f381f89109c1808 Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Tue, 5 Apr 2022 13:41:27 -0700 Subject: [PATCH 07/12] wave 5: all tests passed --- swap_meet/clothing.py | 14 ++++++++++++-- swap_meet/decor.py | 17 +++++++++++++++-- swap_meet/electronics.py | 14 ++++++++++++-- swap_meet/item.py | 27 +++++++++++++++++++++++++-- tests/unit_tests/test_wave_05.py | 10 +++++----- 5 files changed, 69 insertions(+), 13 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..90bec8d5a 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,12 @@ -class Clothing: - pass \ No newline at end of file +from swap_meet.item import Item + + +class Clothing(Item): + + def __init__(self, condition = 0): + self.category = "Clothing" + self.condition = condition + + #override str() for Clothing, returns "The finest clothing you could wear." + 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..a37bd534b 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,15 @@ -class Decor: - pass \ No newline at end of file +from swap_meet.item import Item + + +class Decor(Item): + + + def __init__(self, condition = 0): + #super().__init__(condition = 0) + self.category = "Decor" + self.condition = condition + #self.condition = super().condition + + #override str() for Decor, returns "Something to decorate your space." + 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 2f9dff68a..c735a0bb2 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,12 @@ -class Electronics: - pass +from swap_meet.item import Item + + +class Electronics(Item): + + def __init__(self, condition = 0): + self.category = "Electronics" + self.condition = condition + + #override str() for Electronics, returns "A gadget full of buttons and secrets." + def __str__(self): + return "A gadget full of buttons and secrets." diff --git a/swap_meet/item.py b/swap_meet/item.py index a20826fc4..e364ee4a7 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,11 +1,34 @@ + class Item: - def __init__(self, category = ""): + def __init__(self, category = "", condition = 0): self.category = category + self.condition = condition #override str() for Item, returns "Hello World!" instead def __str__(self): return "Hello World!" - + + + #describes condition based on the value, range from 0 to 5 + def condition_description(self): + + if self.condition == 0: + return "Wash your hands with bleach after purchase" + + if self.condition == 1: + return "Wash your hands with soap after purchase" + + if self.condition == 2: + return "Kind of gross" + + if self.condition == 3: + return "Acceptably gross" + + if self.condition == 4: + return "Not gross at all" + + if self.condition == 5: + return "Mint conditon" diff --git a/tests/unit_tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py index 7abea06cd..8dedc9e28 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 594e1131eb7ef6690c16a55fa130f20e5540dd38 Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Tue, 5 Apr 2022 14:56:31 -0700 Subject: [PATCH 08/12] Wave 6 first 3 tests passed --- swap_meet/clothing.py | 10 +++++++++- swap_meet/item.py | 1 + swap_meet/vendor.py | 28 ++++++++++++++++++++++++++++ tests/unit_tests/test_wave_05.py | 1 + tests/unit_tests/test_wave_06.py | 6 +++--- 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 90bec8d5a..83a031fc7 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -2,11 +2,19 @@ class Clothing(Item): - + + def __init__(self, condition = 0): self.category = "Clothing" self.condition = condition + """"" + def __init__(self, category, condition): + super(Item, self).__init__(category, condition) + self.category = "Clothing" + self.condition = condition + """"" + #override str() for Clothing, returns "The finest clothing you could wear." def __str__(self): return "The finest clothing you could wear." \ No newline at end of file diff --git a/swap_meet/item.py b/swap_meet/item.py index e364ee4a7..763d0543c 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,4 +1,5 @@ + class Item: def __init__(self, category = "", condition = 0): diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 519b04c19..3581112cb 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -9,6 +9,7 @@ def add(self, item): self.inventory.append(item) return item + # Removes the matching item from the inventory def remove(self, item): if item not in self.inventory: @@ -17,6 +18,7 @@ def remove(self, item): self.inventory.remove(item) return item + # Takes one argument: a string, representing a category # Returns a list of Items in the inventory with that category def get_by_category(self, category): @@ -25,8 +27,11 @@ def get_by_category(self, category): for item in self.inventory: if item.category == category: item_list.append(item) + + return item_list + # removes my_item from this Vendor's inventory # adds my_item to the other Vendor's inventory # removes their_item from other Vendor's inventory @@ -44,6 +49,11 @@ def swap_items(self, vendor, my_item, their_item): return True + + #removes first item from this Vendor's inventory + # adds the other Vendor's first item + # removes first item from other Vendor's inventory + # adds this Vendor's first item def swap_first_item(self, vendor): if len(self.inventory) == 0 or len(vendor.inventory) == 0: return False @@ -56,6 +66,24 @@ def swap_first_item(self, vendor): return True + #gets the item with the best condition in a certain category + def get_best_by_category(self, category): + + category_inventory = self.get_by_category(category) + + if len(category_inventory) == 0: + return None + + highest_rated = category_inventory[0] + + for item in category_inventory: + + if (item.condition) > (highest_rated.condition): + highest_rated = item + + return highest_rated + + diff --git a/tests/unit_tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py index 8dedc9e28..d8575f6e2 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -6,6 +6,7 @@ #@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." diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 1f7065ab4..eff08d4a6 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) From 5fe22f8d5c53b4bd3560668034541980c1e6324b Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Tue, 5 Apr 2022 15:44:54 -0700 Subject: [PATCH 09/12] wave 6: all tests passed --- swap_meet/vendor.py | 12 +++++++ tests/unit_tests/test_wave_06.py | 59 ++++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 3581112cb..3ed801fa5 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -84,8 +84,20 @@ def get_best_by_category(self, category): return highest_rated + #swap the best item of certain categories with another Vendor + def swap_best_by_category(self, other, my_priority, their_priority): + + #find best item in my inventory that matches their_priority + my_best = self.get_best_by_category(their_priority) + + their_best = other.get_best_by_category(my_priority) + if my_best == None or their_best == None: + return False + self.swap_items(other, my_best, their_best) + + return True diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index eff08d4a6..365724792 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,16 +76,26 @@ def test_swap_best_by_category(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* # Assertions should check: # - That the results is truthy + assert result == True # - 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 in jesse.inventory + 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) @@ -109,16 +119,26 @@ 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 ********** # ********************************************************************* # Assertions should check: # - That result is truthy + assert result == True # - 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 in jesse.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_inventory_is_false(): tai = Vendor( inventory=[] @@ -144,7 +164,7 @@ def test_swap_best_by_category_no_inventory_is_false(): assert item_b in jesse.inventory assert item_c in jesse.inventory -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_other_inventory_is_false(): item_a = Clothing(condition=2.0) item_b = Decor(condition=4.0) @@ -170,7 +190,7 @@ def test_swap_best_by_category_no_other_inventory_is_false(): assert item_b in tai.inventory assert item_c in tai.inventory -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -194,16 +214,26 @@ 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 ********** # ********************************************************************* # Assertions should check: # - That result is falsy + assert result == False # - 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 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 + +#@pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -227,11 +257,20 @@ 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 ********** # ********************************************************************* # Assertions should check: # - That result is falsy + assert result == False # - 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 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 cd9db2b14d3d6135ada2ba7f6021a42f86c93190 Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Tue, 5 Apr 2022 15:47:22 -0700 Subject: [PATCH 10/12] DRY code --- swap_meet/vendor.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 3ed801fa5..5597be238 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -58,10 +58,7 @@ def swap_first_item(self, vendor): if len(self.inventory) == 0 or len(vendor.inventory) == 0: 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 From abd72305c6a7ea5d8f22f1c1afe8fd8a48821d99 Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Wed, 6 Apr 2022 19:19:08 -0700 Subject: [PATCH 11/12] all integration tests passed --- swap_meet/decor.py | 3 +-- swap_meet/item.py | 1 + swap_meet/vendor.py | 22 ++++++++++++++----- tests/integration_tests/test_wave_01_02_03.py | 8 +++---- tests/integration_tests/test_wave_04_05_06.py | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/swap_meet/decor.py b/swap_meet/decor.py index a37bd534b..14fea026e 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -3,12 +3,11 @@ class Decor(Item): - + def __init__(self, condition = 0): #super().__init__(condition = 0) self.category = "Decor" self.condition = condition - #self.condition = super().condition #override str() for Decor, returns "Something to decorate your space." def __str__(self): diff --git a/swap_meet/item.py b/swap_meet/item.py index 763d0543c..b74caa2c0 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -5,6 +5,7 @@ class Item: def __init__(self, category = "", condition = 0): self.category = category self.condition = condition + #self.age = age #override str() for Item, returns "Hello World!" instead def __str__(self): diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 5597be238..0d903b56c 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,7 +1,9 @@ from swap_meet.item import Item class Vendor: - def __init__(self, inventory = []): + def __init__(self, inventory = None): + if inventory == None: + inventory = [] self.inventory = inventory # Adds the item to the inventory @@ -36,16 +38,24 @@ def get_by_category(self, category): # adds my_item to the other Vendor's inventory # removes their_item from other Vendor's inventory # adds their_item to the this Vendor's inventory - def swap_items(self, vendor, my_item, their_item): + def swap_items(self, other_vendor, my_item, their_item): - if (my_item not in self.inventory) or (their_item not in vendor.inventory): + if (my_item not in self.inventory) or (their_item not in other_vendor.inventory): return False - vendor.add(my_item) - self.remove(my_item) + #print("********BEFORE***********") + #print(len(self.inventory)) + #print(len(other_vendor.inventory)) + self.remove(my_item) + other_vendor.add(my_item) + + other_vendor.remove(their_item) self.add(their_item) - vendor.remove(their_item) + + #print("********AFTER***********") + # print(len(self.inventory)) + # print(len(other_vendor.inventory)) return True diff --git a/tests/integration_tests/test_wave_01_02_03.py b/tests/integration_tests/test_wave_01_02_03.py index 9912414da..e766bbbf7 100644 --- a/tests/integration_tests/test_wave_01_02_03.py +++ b/tests/integration_tests/test_wave_01_02_03.py @@ -2,11 +2,13 @@ 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 vendor = Vendor() + + assert len(vendor.inventory) == 0 # add an item @@ -49,6 +51,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 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 34cb624e372a509ce082b2b1adae642e3786ca03 Mon Sep 17 00:00:00 2001 From: Nikki Torab Date: Thu, 7 Apr 2022 21:29:02 -0700 Subject: [PATCH 12/12] swap_by_newest done --- swap_meet/clothing.py | 9 +-- swap_meet/decor.py | 4 +- swap_meet/electronics.py | 3 +- swap_meet/item.py | 14 ++--- swap_meet/vendor.py | 47 +++++++++++---- tests/unit_tests/test_wave_06.py | 99 ++++++++++++++++++++++++++++++++ 6 files changed, 149 insertions(+), 27 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 83a031fc7..9032f334b 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -4,16 +4,11 @@ class Clothing(Item): - def __init__(self, condition = 0): + def __init__(self, condition = 0, age = None): self.category = "Clothing" self.condition = condition + self.age = age - """"" - def __init__(self, category, condition): - super(Item, self).__init__(category, condition) - self.category = "Clothing" - self.condition = condition - """"" #override str() for Clothing, returns "The finest clothing you could wear." def __str__(self): diff --git a/swap_meet/decor.py b/swap_meet/decor.py index 14fea026e..089cafcb5 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -4,10 +4,10 @@ class Decor(Item): - def __init__(self, condition = 0): - #super().__init__(condition = 0) + def __init__(self, condition = 0, age = None): self.category = "Decor" self.condition = condition + self.age = age #override str() for Decor, returns "Something to decorate your space." def __str__(self): diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index c735a0bb2..b5121b859 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -3,9 +3,10 @@ class Electronics(Item): - def __init__(self, condition = 0): + def __init__(self, condition = 0, age = None): self.category = "Electronics" self.condition = condition + self.age = age #override str() for Electronics, returns "A gadget full of buttons and secrets." def __str__(self): diff --git a/swap_meet/item.py b/swap_meet/item.py index b74caa2c0..452236fbc 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -2,10 +2,10 @@ class Item: - def __init__(self, category = "", condition = 0): + def __init__(self, category = "", condition = 0, age = None): self.category = category self.condition = condition - #self.age = age + self.age = age #override str() for Item, returns "Hello World!" instead def __str__(self): @@ -16,19 +16,19 @@ def __str__(self): def condition_description(self): if self.condition == 0: - return "Wash your hands with bleach after purchase" + return "Terrible condition" if self.condition == 1: - return "Wash your hands with soap after purchase" + return "Bad condition" if self.condition == 2: - return "Kind of gross" + return "Slightly bad condition" if self.condition == 3: - return "Acceptably gross" + return "Acceptable condition" if self.condition == 4: - return "Not gross at all" + return "Good condition" if self.condition == 5: return "Mint conditon" diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 0d903b56c..299e9efae 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -2,6 +2,7 @@ class Vendor: def __init__(self, inventory = None): + #code on lines 6-7 from https://docs.python-guide.org/writing/gotchas/ if inventory == None: inventory = [] self.inventory = inventory @@ -43,19 +44,12 @@ def swap_items(self, other_vendor, my_item, their_item): if (my_item not in self.inventory) or (their_item not in other_vendor.inventory): return False - #print("********BEFORE***********") - #print(len(self.inventory)) - #print(len(other_vendor.inventory)) - self.remove(my_item) other_vendor.add(my_item) other_vendor.remove(their_item) self.add(their_item) - #print("********AFTER***********") - # print(len(self.inventory)) - # print(len(other_vendor.inventory)) return True @@ -64,11 +58,11 @@ def swap_items(self, other_vendor, my_item, their_item): # adds the other Vendor's first item # removes first item from other Vendor's inventory # adds this Vendor's first item - def swap_first_item(self, vendor): - if len(self.inventory) == 0 or len(vendor.inventory) == 0: + def swap_first_item(self, other_vendor): + if len(self.inventory) == 0 or len(other_vendor.inventory) == 0: return False - self.swap_items(vendor, self.inventory[0], vendor.inventory[0]) + self.swap_items(other_vendor, self.inventory[0], other_vendor.inventory[0]) return True @@ -108,6 +102,39 @@ def swap_best_by_category(self, other, my_priority, their_priority): + def swap_by_newest(self, other): + my_newest = self.inventory[0] + for item in self.inventory: + if not item.age is None: + my_newest = item + break + if my_newest.age is None: + return False + + for item in self.inventory: + if not item.age is None: + if item.age < my_newest.age: + my_newest = item + + their_newest = other.inventory[0] + for item in other.inventory: + if not item.age is None: + their_newest = item + break + if their_newest.age is None: + return False + + for item in other.inventory: + if not item.age is None: + if item.age < their_newest.age: + their_newest = item + + self.swap_items(other, my_newest, their_newest) + return True + + + + diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 365724792..c9d0c012c 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -274,3 +274,102 @@ def test_swap_best_by_category_no_other_match_is_false(): assert item_d in jesse.inventory assert item_e in jesse.inventory assert item_f in jesse.inventory + + + + +# tests for swap_by_newest + +def test_swap_newest(): + # Arrange + item_a = Decor(age=8.0) + item_b = Electronics(age=None) + item_c = Decor(age = 2.0) + tai = Vendor( + inventory=[item_c, item_b, item_a] + ) + + item_d = Clothing(age=None) + item_e = Decor(age=4.0) + item_f = Clothing(age=1.0) + jesse = Vendor( + inventory=[item_e, item_d, item_f] + ) + + # Act + result = tai.swap_by_newest(other=jesse) + + 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 + + + +def test_swap_newest_all_ages_none(): + # Arrange + item_a = Decor(age=None) + item_b = Electronics(age=None) + item_c = Decor(age=None) + tai = Vendor( + inventory=[item_c, item_b, item_a] + ) + + item_d = Clothing(age=None) + item_e = Decor(age=None) + item_f = Clothing(age=None) + jesse = Vendor( + inventory=[item_e, item_d, item_f] + ) + + # Act + result = tai.swap_by_newest(other=jesse) + + assert result == False + 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 + + + +def test_swap_newest_one_vendor_ages_none(): + # Arrange + item_a = Decor(age=None) + item_b = Electronics(age=None) + item_c = Decor(age=None) + tai = Vendor( + inventory=[item_c, item_b, item_a] + ) + + item_d = Clothing(age=4.0) + item_e = Decor(age=2.0) + item_f = Clothing(age=1.0) + jesse = Vendor( + inventory=[item_e, item_d, item_f] + ) + + # Act + result = tai.swap_by_newest(other=jesse) + + assert result == False + 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