From 397d47d7a7913302b24ecbe7d38108f7084fb366 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Mon, 3 Oct 2022 11:03:20 -0700 Subject: [PATCH 01/47] Minimal change to clothing.py --- swap_meet/clothing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..3cf862f64 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,3 @@ class Clothing: + # Minimal change pass \ No newline at end of file From 80d063193534752dc7882f3d8d067816c3dea7d6 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Mon, 3 Oct 2022 11:49:13 -0700 Subject: [PATCH 02/47] created constructor for Vendor class and two methods addand remove --- swap_meet/vendor.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..9150f8c95 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,18 @@ class Vendor: - pass \ No newline at end of file + def __init__(self, inventory=None): + '''A blueprint for different store inventories.''' + # inventory is a list + if inventory: + self.inventory = inventory + else: + self.inventory = [] + + def add(self, item): + '''Add an item to the inventory list.''' + self.inventory.append(item) + return item + + def remove(self, item): + '''Remove an item from inventory list.''' + self.inventory.remove(item) + return item \ No newline at end of file From 6c5e93b5148b4180f63c47d4ac533d1374270db1 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Mon, 3 Oct 2022 11:55:46 -0700 Subject: [PATCH 03/47] remove funtion updated --- swap_meet/vendor.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 9150f8c95..c0e1374ba 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -14,5 +14,8 @@ def add(self, item): def remove(self, item): '''Remove an item from inventory list.''' - self.inventory.remove(item) - return item \ No newline at end of file + if item in self.inventory: + self.inventory.remove(item) + return item + else: + return False \ No newline at end of file From 6f171ef2a81d1e1f942da1dcf6b8e1061cb1a589 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Mon, 3 Oct 2022 11:57:40 -0700 Subject: [PATCH 04/47] created assert for test_removing_not_found_is_false and passed wave1 tests --- tests/unit_tests/test_wave_01.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index 58478ccf9..25a3a94ba 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.") + assert result == False + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* From 83210e60dd96b7ecd55a4c05ce43b25974402579 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Mon, 3 Oct 2022 13:42:17 -0700 Subject: [PATCH 05/47] create constructor for class Item --- swap_meet/item.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 560d759c2..d3346df63 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,7 @@ class Item: - pass \ No newline at end of file + def __init__(self, category=None): + if category: + self.category = category + else: + self.category = "" + From 1d944c38a4d63429ecc130b229d6d4ada9aa1e36 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Mon, 3 Oct 2022 13:43:03 -0700 Subject: [PATCH 06/47] create function get_by_category --- swap_meet/vendor.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index c0e1374ba..7bdc5dd8e 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=None): '''A blueprint for different store inventories.''' @@ -18,4 +20,13 @@ def remove(self, item): self.inventory.remove(item) return item else: - return False \ No newline at end of file + return False + + def get_by_category(self, category): + category_list = [] + for i in self.inventory: + if i.category == category: + category_list.append(i) + return category_list + + From 9d41d1a3a5963a9da628dc7a699f97cebf908c2a Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Mon, 3 Oct 2022 13:45:39 -0700 Subject: [PATCH 07/47] added assert to final test. passed all tests in wave 2 --- tests/unit_tests/test_wave_02.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index 3d7060d7c..625a956ec 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -2,12 +2,12 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +# @pytest.mark.skip def test_items_have_blank_default_category(): item = Item() assert item.category == "" -@pytest.mark.skip +# @pytest.mark.skip def test_get_items_by_category(): item_a = Item(category="clothing") item_b = Item(category="electronics") @@ -23,7 +23,7 @@ def test_get_items_by_category(): assert item_c in items assert item_b not in items -@pytest.mark.skip +# @pytest.mark.skip def test_get_no_matching_items_by_category(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -34,7 +34,11 @@ def test_get_no_matching_items_by_category(): items = vendor.get_by_category("electronics") - raise Exception("Complete this test according to comments below.") + assert len(items) == 0 + assert item_a not in items + assert item_b not in items + assert item_c not in items + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* From 79d047602f3ba56152c29d14713392ab1ce7e1b4 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Mon, 3 Oct 2022 14:01:40 -0700 Subject: [PATCH 08/47] __str__ function created --- swap_meet/item.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index d3346df63..010026397 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -4,4 +4,6 @@ def __init__(self, category=None): self.category = category else: self.category = "" - + + def __str__(self_): + return "Hello World!" From dc31761ca4361fe7bc776bdbbd6e927165657e41 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 09:33:30 -0700 Subject: [PATCH 09/47] created method swap_items in vendor.py --- 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 0300b638f..1cd00badb 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 09f268394b8679cc325107336620c74d557dbc59 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 09:55:38 -0700 Subject: [PATCH 10/47] updated method swap_items in vendor.py --- 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 1cd00badb..0af1098e8 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 9167c0398f85f6e178f0f1ffb576cacb6638146b Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 10:01:20 -0700 Subject: [PATCH 11/47] updated method swap_items in vendor.py --- swap_meet/vendor.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 7bdc5dd8e..5ca556d62 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -29,4 +29,16 @@ def get_by_category(self, category): category_list.append(i) return category_list - + def swap_items(self, other_vendor, my_item, their_item): + '''Remove an item from this Vendor's inventory and swaps + with another vendor.''' + # remove and append + # is there a more efficient way? + if my_item in self.inventory and their_item in other_vendor.inventory: + self.add(their_item) + self.remove(my_item) + other_vendor.add(my_item) + other_vendor.remove(their_item) + return True + else: + return False From 7c8824371330568288d2e10d7198f12675cb4c1a Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 10:01:50 -0700 Subject: [PATCH 12/47] wave 3 tests passed --- 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 0af1098e8..2d573fa52 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -38,7 +38,7 @@ def test_swap_items_returns_true(): assert item_b in jolie.inventory assert result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_items_when_my_item_is_missing_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -65,7 +65,7 @@ def test_swap_items_when_my_item_is_missing_returns_false(): assert item_e in jolie.inventory assert not result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_items_when_their_item_is_missing_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -92,7 +92,7 @@ def test_swap_items_when_their_item_is_missing_returns_false(): assert item_e in jolie.inventory assert not result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_items_from_my_empty_returns_false(): fatimah = Vendor( inventory=[] @@ -112,7 +112,7 @@ def test_swap_items_from_my_empty_returns_false(): assert len(jolie.inventory) == 2 assert not result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_items_from_their_empty_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") From c89af057ea4710842e60f10896e53a22ff7161aa Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 13:10:57 -0700 Subject: [PATCH 13/47] integrattion tests for test wave 1,2,3 passed --- tests/integration_tests/test_wave_01_02_03.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tests/test_wave_01_02_03.py b/tests/integration_tests/test_wave_01_02_03.py index 9912414da..25707d998 100644 --- a/tests/integration_tests/test_wave_01_02_03.py +++ b/tests/integration_tests/test_wave_01_02_03.py @@ -2,7 +2,7 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +# @pytest.mark.skip @pytest.mark.integration_test def test_integration_wave_01_02_03(): # make a vendor From 379a7f1969ab079456054c0edf4cc2dc8de4387f Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 13:29:28 -0700 Subject: [PATCH 14/47] created function swap_first_item in vendor.py --- swap_meet/vendor.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 5ca556d62..c749c81df 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -31,7 +31,7 @@ def get_by_category(self, category): def swap_items(self, other_vendor, my_item, their_item): '''Remove an item from this Vendor's inventory and swaps - with another vendor.''' + with other vendor.''' # remove and append # is there a more efficient way? if my_item in self.inventory and their_item in other_vendor.inventory: @@ -42,3 +42,15 @@ def swap_items(self, other_vendor, my_item, their_item): return True else: return False + + def swap_first_item(self, other_vendor): + '''Swap the first item in this vendor's inventory with + first item of other vendor.''' + if self.inventory or other_vendor.inventory: + my_item = self.inventory[0] + their_item = other_vendor.inventory[0] + self.swap_items(other_vendor, my_item, their_item) + return True + else: + return False + From 988f081b10e6d826aa7d939c657a373d3065a820 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 13:31:02 -0700 Subject: [PATCH 15/47] changed or to and in if conditional of swap_first_item in vendor.py --- swap_meet/vendor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index c749c81df..5e77733be 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -46,7 +46,9 @@ def swap_items(self, other_vendor, my_item, their_item): def swap_first_item(self, other_vendor): '''Swap the first item in this vendor's inventory with first item of other vendor.''' - if self.inventory or other_vendor.inventory: + # why do you have to put the conditional parameters to return T or F if + # the swap_items function already contained a return value of T or F + if self.inventory and other_vendor.inventory: my_item = self.inventory[0] their_item = other_vendor.inventory[0] self.swap_items(other_vendor, my_item, their_item) From 800e3545fe142f1826c0e49db030350127d5b528 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 13:32:16 -0700 Subject: [PATCH 16/47] passed tests in test_wave_04.py --- tests/unit_tests/test_wave_04.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index 8190a4ebb..4ef21ff8e 100644 --- a/tests/unit_tests/test_wave_04.py +++ b/tests/unit_tests/test_wave_04.py @@ -2,7 +2,7 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip +# @pytest.mark.skip def test_swap_first_item_returns_true(): item_a = Item(category="clothing") item_b = Item(category="clothing") @@ -30,7 +30,7 @@ def test_swap_first_item_returns_true(): assert item_a in jolie.inventory assert result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_first_item_from_my_empty_returns_false(): fatimah = Vendor( inventory=[] @@ -48,7 +48,7 @@ def test_swap_first_item_from_my_empty_returns_false(): assert len(jolie.inventory) == 2 assert not result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_first_item_from_their_empty_returns_false(): item_a = Item(category="clothing") item_b = Item(category="clothing") From c56b7badc5a462041f7ede158a3f25bb27760e35 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 13:38:31 -0700 Subject: [PATCH 17/47] created class Clothing with attribute category and stringify method --- swap_meet/clothing.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 3cf862f64..dc1bcc555 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,3 +1,8 @@ class Clothing: - # Minimal change - pass \ No newline at end of file + + def __init__(self): + self.category = "Clothing" + + def __str__(self_): + return "The finest clothing you could wear." + \ No newline at end of file From cdd6bba8292d9bbff549a41be04d6bde800da282 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 13:44:46 -0700 Subject: [PATCH 18/47] created class Decor with attribute category and stringify method. --- swap_meet/decor.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/swap_meet/decor.py b/swap_meet/decor.py index eab7a9dbe..026ea06f8 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): + self.category = "Decor" + + def __str__(self): + return "Something to decorate your space." \ No newline at end of file From 1254610517772cbaf37e1e6968f4e9c2b110bded Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 13:46:37 -0700 Subject: [PATCH 19/47] created class Electronics with attribute category and stringify method --- swap_meet/electronics.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2f9dff68a..b5239acf9 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,8 @@ class Electronics: - pass + + def __init__(self): + self.category = "Electronics" + + def __str__(self): + return "A gadget full of buttons and secrets." + From b117b517cedac9d9c27c035e3090e6ed295a0993 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 15:40:56 -0700 Subject: [PATCH 20/47] refactored __init__ method in Item class --- swap_meet/item.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 010026397..e14f23688 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,9 +1,9 @@ class Item: - def __init__(self, category=None): - if category: - self.category = category - else: + def __init__(self, category=""): #, condition=0): + if category is None: self.category = "" - + self.category = category + # self.condition = condition + def __str__(self_): return "Hello World!" From 89a6eb8014830e913480a62552d23a3c5b23376d Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 15:41:55 -0700 Subject: [PATCH 21/47] added condition parameter and attribute to __init__ method --- swap_meet/item.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index e14f23688..aa5f362b0 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,9 +1,9 @@ class Item: - def __init__(self, category=""): #, condition=0): + def __init__(self, category="", condition=0): if category is None: self.category = "" self.category = category - # self.condition = condition + self.condition = condition def __str__(self_): return "Hello World!" From a8bb8bb90f4ce21963ffc1e6212d6f914c463343 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 15:44:02 -0700 Subject: [PATCH 22/47] added condition attribute to __init__ method --- swap_meet/clothing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index dc1bcc555..af39277f5 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,7 +1,8 @@ class Clothing: - def __init__(self): + def __init__(self, condition=0): self.category = "Clothing" + self.condition = condition def __str__(self_): return "The finest clothing you could wear." From 649ac701b35ad9f017a60b0184fc0c79c92d1351 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 15:44:44 -0700 Subject: [PATCH 23/47] added condition attribute to __ini__ method --- swap_meet/decor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swap_meet/decor.py b/swap_meet/decor.py index 026ea06f8..826119f86 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,7 +1,8 @@ class Decor: - def __init__(self): + def __init__(self, condition=0): self.category = "Decor" + self.condition = condition def __str__(self): return "Something to decorate your space." \ No newline at end of file From 3fb91769ba4515f1fa7a4102b311039dce6e7330 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 15:45:58 -0700 Subject: [PATCH 24/47] added condition attribute to __init__ method --- swap_meet/electronics.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index b5239acf9..db791e292 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,8 +1,9 @@ class Electronics: - def __init__(self): + def __init__(self, condition=0): self.category = "Electronics" + self.condition = condition def __str__(self): return "A gadget full of buttons and secrets." - + From 8ffb25902ab83b2624e186220c95cefd4f0da2a4 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 16:30:17 -0700 Subject: [PATCH 25/47] created condition_description method --- swap_meet/item.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index aa5f362b0..3b2b653c2 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -5,5 +5,26 @@ def __init__(self, category="", condition=0): self.category = category self.condition = condition - def __str__(self_): + def __str__(self): return "Hello World!" + + def condition_description(self): + # is there a more concise way? for loop? + if self.condition == 0: + zero_condition_description = "Yo, this is bad. Reconsider." + return zero_condition_description + elif self.condition == 1: + one_condition_description = "You could probably find better... but this'll do." + return one_condition_description + elif self.condition == 2: + two_condition_description = "If you're okay with some dings and things." + return two_condition_description + elif self.condition == 3: + three_condition_description = "Lots of life left in this one." + return three_condition_description + elif self.condition == 4: + four_condition_description = "Oooh, quite the find! Barely a scratch." + return four_condition_description + elif self.condition == 5: + five_condition_description = "ULTRA RARE, PERFECT CONDITION." + return five_condition_description \ No newline at end of file From 7022952e05fed4c3717eef6a6338291dc46bb3b1 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 16:30:56 -0700 Subject: [PATCH 26/47] refactored and imported parent class Item --- swap_meet/clothing.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index af39277f5..018c74171 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,9 +1,12 @@ -class Clothing: +from .item import Item + +class Clothing(Item): def __init__(self, condition=0): - self.category = "Clothing" - self.condition = condition + super().__init__("Clothing", condition) + # self.category = "Clothing" + # self.condition = condition - def __str__(self_): + def __str__(self): return "The finest clothing you could wear." \ No newline at end of file From fa6a30432fe263aec3acdd45dd93e6df5a30657a Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 16:31:17 -0700 Subject: [PATCH 27/47] refactored and imported parent class Item --- swap_meet/decor.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/swap_meet/decor.py b/swap_meet/decor.py index 826119f86..8dee901d2 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,8 +1,11 @@ -class Decor: +from .item import Item + +class Decor(Item): def __init__(self, condition=0): - self.category = "Decor" - self.condition = condition + super().__init__("Decor", condition) + # self.category = "Decor" + # self.condition = condition def __str__(self): return "Something to decorate your space." \ No newline at end of file From e8c4269c3b495cbec73e7cc1624f9fa83a4a449a Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 16:31:36 -0700 Subject: [PATCH 28/47] refactored and imported parent class Item --- swap_meet/electronics.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index db791e292..f4260f71f 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,8 +1,11 @@ -class Electronics: +from .item import Item + +class Electronics(Item): def __init__(self, condition=0): - self.category = "Electronics" - self.condition = condition + super().__init__("Electronics", condition) + # self.category = "Electronics" + # self.condition = condition def __str__(self): return "A gadget full of buttons and secrets." From d15c7e18e007f41adecdd1f6ed77e1ecdc92c7f2 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Tue, 4 Oct 2022 16:32:04 -0700 Subject: [PATCH 29/47] passed tests in wave 5 --- tests/unit_tests/test_wave_05.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py index 7abea06cd..fdeb063a9 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -3,25 +3,25 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip +# @pytest.mark.skip def test_clothing_has_default_category_and_to_str(): cloth = Clothing() assert cloth.category == "Clothing" assert str(cloth) == "The finest clothing you could wear." -@pytest.mark.skip +# @pytest.mark.skip def test_decor_has_default_category_and_to_str(): decor = Decor() assert decor.category == "Decor" assert str(decor) == "Something to decorate your space." -@pytest.mark.skip +# @pytest.mark.skip def test_electronics_has_default_category_and_to_str(): electronics = Electronics() assert electronics.category == "Electronics" assert str(electronics) == "A gadget full of buttons and secrets." -@pytest.mark.skip +# @pytest.mark.skip def test_items_have_condition_as_float(): items = [ Clothing(condition=3.5), @@ -31,7 +31,7 @@ def test_items_have_condition_as_float(): for item in items: assert item.condition == pytest.approx(3.5) -@pytest.mark.skip +# @pytest.mark.skip def test_items_have_condition_descriptions_that_are_the_same_regardless_of_type(): items = [ Clothing(condition=5), From c40257830463babd75423bc33342e5b5458cffda Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Wed, 5 Oct 2022 14:29:15 -0700 Subject: [PATCH 30/47] refactored condition_description method to dictionary from if-elif --- swap_meet/item.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 3b2b653c2..3f3f34bea 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -9,22 +9,17 @@ def __str__(self): return "Hello World!" def condition_description(self): - # is there a more concise way? for loop? - if self.condition == 0: - zero_condition_description = "Yo, this is bad. Reconsider." - return zero_condition_description - elif self.condition == 1: - one_condition_description = "You could probably find better... but this'll do." - return one_condition_description - elif self.condition == 2: - two_condition_description = "If you're okay with some dings and things." - return two_condition_description - elif self.condition == 3: - three_condition_description = "Lots of life left in this one." - return three_condition_description - elif self.condition == 4: - four_condition_description = "Oooh, quite the find! Barely a scratch." - return four_condition_description - elif self.condition == 5: - five_condition_description = "ULTRA RARE, PERFECT CONDITION." - return five_condition_description \ No newline at end of file + # changed from if-elif to dictionary + condition_dict = { + 0:"Yo this is trash.", + 1:"Definitely used. Perhaps too much.", + 2:"If you're okay with some dings and things.", + 3:"Lots of life left if you handle with care.", + 4:"Barely even a scractch.", + 5:"ULTRA RARE PIECE, NWOT CONDITION.", + + } + if self.condition in condition_dict: + return condition_dict[self.condition] + + \ No newline at end of file From c6713e5fdf03f0d5b87a5f4e914c847257a514e1 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Wed, 5 Oct 2022 16:46:09 -0700 Subject: [PATCH 31/47] created method get_best_by_category --- swap_meet/vendor.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 5e77733be..272d7beb2 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -56,3 +56,36 @@ def swap_first_item(self, other_vendor): else: return False + def get_best_by_category(self, category): + '''Returns item with the best condition in a certain category.''' + + condition_max = 0 + best_item = "" + for item in self.inventory: + category_counter = 0 + if item.category == category: + category_counter += 1 + if item.condition > condition_max: + condition_max = item.condition + best_item = item + + if category_counter == 0: + return None + else: + return best_item + + + + + + + + + + + + + # if item.condition == max_condition: + # return max_condition + + From 6d3b365adaec12447239b963bc17c07225a89869 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Wed, 5 Oct 2022 16:49:08 -0700 Subject: [PATCH 32/47] cleaned up comments --- swap_meet/item.py | 1 + 1 file changed, 1 insertion(+) diff --git a/swap_meet/item.py b/swap_meet/item.py index 3f3f34bea..df081aeff 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -10,6 +10,7 @@ def __str__(self): def condition_description(self): # changed from if-elif to dictionary + '''Returns descriptions of condition based on condition value.''' condition_dict = { 0:"Yo this is trash.", 1:"Definitely used. Perhaps too much.", From 9bf1020df2f525d390b7319cdf0280ff6d36b62b Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Wed, 5 Oct 2022 22:55:07 -0700 Subject: [PATCH 33/47] refactor __init__ method --- swap_meet/vendor.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 272d7beb2..191c50271 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -4,10 +4,9 @@ class Vendor: def __init__(self, inventory=None): '''A blueprint for different store inventories.''' # inventory is a list - if inventory: - self.inventory = inventory - else: - self.inventory = [] + if inventory is None: + inventory = [] + self.inventory = inventory def add(self, item): '''Add an item to the inventory list.''' @@ -48,6 +47,7 @@ def swap_first_item(self, other_vendor): first item of other vendor.''' # why do you have to put the conditional parameters to return T or F if # the swap_items function already contained a return value of T or F + # because two completely different conditional situations... if self.inventory and other_vendor.inventory: my_item = self.inventory[0] their_item = other_vendor.inventory[0] @@ -74,18 +74,6 @@ def get_best_by_category(self, category): else: return best_item - + # def swap_best_by_category(self, other, my_priority, their_priority): + #use swap_items function - - - - - - - - - - # if item.condition == max_condition: - # return max_condition - - From 480061a042bc386a72fab868d76d90640a135588 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 15:11:33 -0700 Subject: [PATCH 34/47] created method swap_best_by_category --- swap_meet/vendor.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 191c50271..f246da9cc 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -3,7 +3,6 @@ class Vendor: def __init__(self, inventory=None): '''A blueprint for different store inventories.''' - # inventory is a list if inventory is None: inventory = [] self.inventory = inventory @@ -32,7 +31,6 @@ def swap_items(self, other_vendor, my_item, their_item): '''Remove an item from this Vendor's inventory and swaps with other vendor.''' # remove and append - # is there a more efficient way? if my_item in self.inventory and their_item in other_vendor.inventory: self.add(their_item) self.remove(my_item) @@ -45,9 +43,6 @@ def swap_items(self, other_vendor, my_item, their_item): def swap_first_item(self, other_vendor): '''Swap the first item in this vendor's inventory with first item of other vendor.''' - # why do you have to put the conditional parameters to return T or F if - # the swap_items function already contained a return value of T or F - # because two completely different conditional situations... if self.inventory and other_vendor.inventory: my_item = self.inventory[0] their_item = other_vendor.inventory[0] @@ -74,6 +69,22 @@ def get_best_by_category(self, category): else: return best_item - # def swap_best_by_category(self, other, my_priority, their_priority): - #use swap_items function - + def swap_best_by_category(self, other, my_priority, their_priority): + '''Swap best item of certain categories with another vendor.''' + # use swap_items function + # swap best item in my inventory that matches their_priority + # swap best item in other inventory that matches my_priority + # return true + # if have no matching category for either person, return false + + if not self.inventory or not other.inventory: + return False + + my_item = self.get_best_by_category(their_priority) + their_item = other.get_best_by_category(my_priority) + + if not my_item or not their_item: + return False + + self.swap_items(other, my_item, their_item) + return True From 67d26f1108742251466a68e354fa831456235194 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 15:12:15 -0700 Subject: [PATCH 35/47] added assertions and passed all tests --- tests/unit_tests/test_wave_06.py | 66 ++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 1f7065ab4..506bc411d 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -4,7 +4,7 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip +# @pytest.mark.skip def test_best_by_category(): item_a = Clothing(condition=2.0) item_b = Decor(condition=2.0) @@ -20,7 +20,7 @@ def test_best_by_category(): assert best_item.category == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip +# @pytest.mark.skip def test_best_by_category_no_matches_is_none(): item_a = Decor(condition=2.0) item_b = Decor(condition=2.0) @@ -33,7 +33,7 @@ def test_best_by_category_no_matches_is_none(): assert best_item is None -@pytest.mark.skip +# @pytest.mark.skip def test_best_by_category_with_duplicates(): # Arrange item_a = Clothing(condition=2.0) @@ -50,7 +50,7 @@ def test_best_by_category_with_duplicates(): assert best_item.category == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category(): # Arrange # me @@ -76,7 +76,18 @@ def test_swap_best_by_category(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + 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_d in jesse.inventory + assert item_e in jesse.inventory + assert item_c in jesse.inventory + assert item_f not in jesse.inventory + #raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -85,7 +96,7 @@ def test_swap_best_by_category(): # - That tai and jesse's inventories are the correct length # - That all the correct items are in tai and jesse's inventories, including the items which were swapped from one vendor to the other -@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category_reordered(): # Arrange item_a = Decor(condition=2.0) @@ -108,8 +119,16 @@ def test_swap_best_by_category_reordered(): my_priority="Clothing", their_priority="Decor" ) - - raise Exception("Complete this test according to comments below.") + 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_d in jesse.inventory + assert item_e in jesse.inventory + assert item_c in jesse.inventory + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -118,7 +137,7 @@ def test_swap_best_by_category_reordered(): # - That tai and jesse's inventories are the correct length # - That all the correct items are in tai and jesse's inventories, and that the items that were swapped are not there -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_inventory_is_false(): tai = Vendor( inventory=[] @@ -144,7 +163,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 +189,7 @@ def test_swap_best_by_category_no_other_inventory_is_false(): assert item_b in tai.inventory assert item_c in tai.inventory -@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category_no_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -194,7 +213,16 @@ def test_swap_best_by_category_no_match_is_false(): their_priority="Clothing" ) - raise Exception("Complete this test according to comments below.") + 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 + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -203,7 +231,7 @@ def test_swap_best_by_category_no_match_is_false(): # - That tai and jesse's inventories are the correct length # - That all the correct items are in tai and jesse's inventories -@pytest.mark.skip +#@pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -226,8 +254,16 @@ def test_swap_best_by_category_no_other_match_is_false(): my_priority="Electronics", their_priority="Decor" ) - - raise Exception("Complete this test according to comments below.") + 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 + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* From be42eb24cd8d7b11e8ca709cfb0de937daed29a2 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 15:12:37 -0700 Subject: [PATCH 36/47] cleaned up comments --- swap_meet/item.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index df081aeff..111e020a6 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -16,7 +16,7 @@ def condition_description(self): 1:"Definitely used. Perhaps too much.", 2:"If you're okay with some dings and things.", 3:"Lots of life left if you handle with care.", - 4:"Barely even a scractch.", + 4:"Barely even a scratch.", 5:"ULTRA RARE PIECE, NWOT CONDITION.", } From 60c2472fef49daa7a404993ff67f986b2347e5c0 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 16:01:25 -0700 Subject: [PATCH 37/47] refactored get_best_by_category --- swap_meet/vendor.py | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index f246da9cc..63ed08c90 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -53,21 +53,34 @@ def swap_first_item(self, other_vendor): def get_best_by_category(self, category): '''Returns item with the best condition in a certain category.''' + list_of_items_of_category = self.get_by_category(category) + if not list_of_items_of_category: + return None condition_max = 0 best_item = "" - for item in self.inventory: - category_counter = 0 - if item.category == category: - category_counter += 1 - if item.condition > condition_max: - condition_max = item.condition - best_item = item + for item in list_of_items_of_category: + if item.condition > condition_max: + condition_max = item.condition + best_item = item + + return best_item + + + # condition_max = 0 + # best_item = "" + # for item in self.inventory: + # category_counter = 0 + # if item.category == category: + # category_counter += 1 + # if item.condition > condition_max: + # condition_max = item.condition + # best_item = item - if category_counter == 0: - return None - else: - return best_item + # if category_counter == 0: + # return None + # else: + # return best_item def swap_best_by_category(self, other, my_priority, their_priority): '''Swap best item of certain categories with another vendor.''' @@ -77,13 +90,13 @@ def swap_best_by_category(self, other, my_priority, their_priority): # return true # if have no matching category for either person, return false - if not self.inventory or not other.inventory: - return False + # if not self.inventory or not other.inventory: + # return False my_item = self.get_best_by_category(their_priority) their_item = other.get_best_by_category(my_priority) - if not my_item or not their_item: + if my_item is None or their_item is None: return False self.swap_items(other, my_item, their_item) From 84b12f283ad57ce275725828b9a25a3b5928faa2 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 16:17:50 -0700 Subject: [PATCH 38/47] integration tests for wave 4,5,6 passed --- 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..91b1362b6 100644 --- a/tests/integration_tests/test_wave_04_05_06.py +++ b/tests/integration_tests/test_wave_04_05_06.py @@ -4,7 +4,7 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip +# @pytest.mark.skip @pytest.mark.integration_test def test_integration_wave_04_05_06(): camila = Vendor() From d2c4111794a1df957daaed39aad03ae60675369c Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 16:20:23 -0700 Subject: [PATCH 39/47] recomment and uncomment --- tests/unit_tests/test_wave_06.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 506bc411d..043659648 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -76,9 +76,10 @@ def test_swap_best_by_category(): their_priority="Decor" ) - assert result + assert result is True assert len(tai.inventory) == 3 assert len(jesse.inventory) == 3 + # assert all(item in [item_a, item_b, item_f] for item in tai.inventory) assert item_f in tai.inventory assert item_a in tai.inventory assert item_b in tai.inventory @@ -119,7 +120,7 @@ def test_swap_best_by_category_reordered(): my_priority="Clothing", their_priority="Decor" ) - assert result + assert result is True assert len(tai.inventory) == 3 assert len(jesse.inventory) == 3 assert item_f in tai.inventory @@ -156,7 +157,7 @@ def test_swap_best_by_category_no_inventory_is_false(): their_priority="Decor" ) - assert not result + assert result == False assert len(tai.inventory) == 0 assert len(jesse.inventory) == 3 assert item_a in jesse.inventory @@ -182,7 +183,7 @@ def test_swap_best_by_category_no_other_inventory_is_false(): their_priority="Clothing" ) - assert not result + assert result == False assert len(tai.inventory) == 3 assert len(jesse.inventory) == 0 assert item_a in tai.inventory From ca41d7de4dc902641b227aeb93cebcb09c6f3838 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 20:55:24 -0700 Subject: [PATCH 40/47] refactor remove method --- swap_meet/vendor.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 63ed08c90..56bf78948 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -14,11 +14,11 @@ def add(self, item): def remove(self, item): '''Remove an item from inventory list.''' - if item in self.inventory: - self.inventory.remove(item) - return item - else: + if item not in self.inventory: return False + self.inventory.remove(item) + return item + def get_by_category(self, category): category_list = [] @@ -66,21 +66,6 @@ def get_best_by_category(self, category): return best_item - - # condition_max = 0 - # best_item = "" - # for item in self.inventory: - # category_counter = 0 - # if item.category == category: - # category_counter += 1 - # if item.condition > condition_max: - # condition_max = item.condition - # best_item = item - - # if category_counter == 0: - # return None - # else: - # return best_item def swap_best_by_category(self, other, my_priority, their_priority): '''Swap best item of certain categories with another vendor.''' From 767f7c650a091fd0a11f7e4a86941eb7ffffa338 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 21:04:23 -0700 Subject: [PATCH 41/47] refactor get_by_category method --- swap_meet/vendor.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 56bf78948..99daf446c 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,3 +1,4 @@ +from re import I from swap_meet.item import Item class Vendor: @@ -18,13 +19,10 @@ def remove(self, item): return False self.inventory.remove(item) return item - def get_by_category(self, category): - category_list = [] - for i in self.inventory: - if i.category == category: - category_list.append(i) + '''Return a list of items in the inventory with category.''' + category_list = [i for i in self.inventory if i.category == category] return category_list def swap_items(self, other_vendor, my_item, their_item): From ac17b09102b5236f28a17933bbe032fcbb5b388f Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 21:27:40 -0700 Subject: [PATCH 42/47] refactor asserts in tests --- tests/unit_tests/test_wave_06.py | 95 ++++++++------------------------ 1 file changed, 24 insertions(+), 71 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 043659648..dbabb2e29 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -76,26 +76,12 @@ def test_swap_best_by_category(): their_priority="Decor" ) - assert result is True + assert result assert len(tai.inventory) == 3 assert len(jesse.inventory) == 3 - # assert all(item in [item_a, item_b, item_f] for item in tai.inventory) - 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_d in jesse.inventory - assert item_e in jesse.inventory - assert item_c in jesse.inventory - assert item_f not in jesse.inventory - #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 all(item in [item_a, item_b, item_f] for item in tai.inventory) + assert all(item in [item_d, item_e, item_c] for item in jesse.inventory) + # @pytest.mark.skip def test_swap_best_by_category_reordered(): @@ -120,23 +106,16 @@ def test_swap_best_by_category_reordered(): my_priority="Clothing", their_priority="Decor" ) - assert result is True + 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_d in jesse.inventory - assert item_e in jesse.inventory - assert item_c in jesse.inventory - # 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 all(item in [item_a, item_b, item_f] for item in tai.inventory) + assert all(item in [item_d, item_e, item_c] for item in jesse.inventory) + assert item_f not in jesse.inventory + assert item_c not in tai.inventory + + + #@pytest.mark.skip def test_swap_best_by_category_no_inventory_is_false(): @@ -157,12 +136,10 @@ def test_swap_best_by_category_no_inventory_is_false(): their_priority="Decor" ) - assert result == False + assert not result assert len(tai.inventory) == 0 assert len(jesse.inventory) == 3 - assert item_a in jesse.inventory - assert item_b in jesse.inventory - assert item_c in jesse.inventory + assert all(item in [item_a, item_b, item_c] for item in jesse.inventory) #@pytest.mark.skip def test_swap_best_by_category_no_other_inventory_is_false(): @@ -183,12 +160,10 @@ def test_swap_best_by_category_no_other_inventory_is_false(): their_priority="Clothing" ) - assert result == False + assert not result assert len(tai.inventory) == 3 assert len(jesse.inventory) == 0 - assert item_a in tai.inventory - assert item_b in tai.inventory - assert item_c in tai.inventory + assert all(item in [item_a, item_b, item_c] for item in tai.inventory) # @pytest.mark.skip def test_swap_best_by_category_no_match_is_false(): @@ -214,23 +189,11 @@ def test_swap_best_by_category_no_match_is_false(): their_priority="Clothing" ) - assert result == False + 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 - # 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 all(item in [item_a, item_b, item_c] for item in tai.inventory) + assert all(item in [item_d, item_e, item_f] for item in jesse.inventory) #@pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): @@ -255,20 +218,10 @@ def test_swap_best_by_category_no_other_match_is_false(): my_priority="Electronics", their_priority="Decor" ) - assert result == False + assert not result # equivalent to "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 - # 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 + # check membership of multiple values at once in a list + assert all(item in [item_a, item_b, item_c] for item in tai.inventory) + assert all(item in [item_d, item_e, item_f] for item in jesse.inventory) + From 9182871393da44836089cde78bfab5253e943e83 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 21:29:03 -0700 Subject: [PATCH 43/47] refactor swap_items --- swap_meet/vendor.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 99daf446c..40ab92467 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -28,15 +28,14 @@ def get_by_category(self, category): def swap_items(self, other_vendor, my_item, their_item): '''Remove an item from this Vendor's inventory and swaps with other vendor.''' - # remove and append - if my_item in self.inventory and their_item in other_vendor.inventory: - self.add(their_item) - self.remove(my_item) - other_vendor.add(my_item) - other_vendor.remove(their_item) - return True - else: - return False + if my_item not in self.inventory or their_item not in other_vendor.inventory: + return False + self.add(their_item) + self.remove(my_item) + other_vendor.add(my_item) + other_vendor.remove(their_item) + return True + def swap_first_item(self, other_vendor): '''Swap the first item in this vendor's inventory with From edb63b38264ad5b27cbd8ae0da5ce5619a20a53a Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 21:43:09 -0700 Subject: [PATCH 44/47] refactor get_best_by_category --- swap_meet/vendor.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 40ab92467..3aeb358ed 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -50,16 +50,10 @@ def swap_first_item(self, other_vendor): def get_best_by_category(self, category): '''Returns item with the best condition in a certain category.''' - list_of_items_of_category = self.get_by_category(category) - if not list_of_items_of_category: + items_in_category = self.get_by_category(category) + if not items_in_category: return None - - condition_max = 0 - best_item = "" - for item in list_of_items_of_category: - if item.condition > condition_max: - condition_max = item.condition - best_item = item + best_item = max(items_in_category, key=lambda item: item.condition) return best_item From 2e32ea5941e6129956fff3346232aec7ac0bb859 Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 21:44:31 -0700 Subject: [PATCH 45/47] cleaned up comments on swap_best_by_category --- swap_meet/vendor.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 3aeb358ed..26052a20a 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -60,20 +60,10 @@ def get_best_by_category(self, category): def swap_best_by_category(self, other, my_priority, their_priority): '''Swap best item of certain categories with another vendor.''' - # use swap_items function - # swap best item in my inventory that matches their_priority - # swap best item in other inventory that matches my_priority - # return true - # if have no matching category for either person, return false - - # if not self.inventory or not other.inventory: - # return False - my_item = self.get_best_by_category(their_priority) their_item = other.get_best_by_category(my_priority) if my_item is None or their_item is None: return False - self.swap_items(other, my_item, their_item) return True From 313f632af31591f9e7565ec65e0c02111bb21cea Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Thu, 6 Oct 2022 21:51:58 -0700 Subject: [PATCH 46/47] refactored __init__ --- swap_meet/item.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 111e020a6..92505f187 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,7 +1,5 @@ class Item: def __init__(self, category="", condition=0): - if category is None: - self.category = "" self.category = category self.condition = condition From 72488b31d6c93708ccd8c4c4e501642838d43fab Mon Sep 17 00:00:00 2001 From: Alyssa Reyes Date: Fri, 7 Oct 2022 13:14:23 -0700 Subject: [PATCH 47/47] cleaned up comments --- swap_meet/item.py | 1 - 1 file changed, 1 deletion(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 92505f187..9f6bff729 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -7,7 +7,6 @@ def __str__(self): return "Hello World!" def condition_description(self): - # changed from if-elif to dictionary '''Returns descriptions of condition based on condition value.''' condition_dict = { 0:"Yo this is trash.",