From e078066b53a11429f7ae6a479ac58308827a2e9a Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Mon, 3 Apr 2023 11:40:24 -0700 Subject: [PATCH 01/39] added comment to README to test git commit and push --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e90419fb0..ffcd61d84 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +# Testing git push # Swap Meet ## Skills Assessed From c017f59b67cec0ef5326bc3c094c69cec92def1f Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Mon, 3 Apr 2023 11:53:10 -0700 Subject: [PATCH 02/39] implemented contructor for Vendor class --- swap_meet/vendor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..50ea671f2 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,3 @@ class Vendor: - pass \ No newline at end of file + def __init__(self, inventory = []): + self.inventory = inventory \ No newline at end of file From ac142db924767779faa27d93cf534b1edfe688bd Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Mon, 3 Apr 2023 11:57:52 -0700 Subject: [PATCH 03/39] implemented instance method add in Vendor class --- swap_meet/vendor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 50ea671f2..404a8fa8a 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,3 +1,7 @@ class Vendor: def __init__(self, inventory = []): - self.inventory = inventory \ No newline at end of file + self.inventory = inventory + + def add(self, item): + self.inventory.append(item) + return item \ No newline at end of file From 50520828f71ed54832d0f9ed699192a2041d305f Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Mon, 3 Apr 2023 12:01:22 -0700 Subject: [PATCH 04/39] implemented instance method remove in Vendor class --- swap_meet/vendor.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 404a8fa8a..80651e847 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -4,4 +4,11 @@ def __init__(self, inventory = []): def add(self, item): self.inventory.append(item) - return item \ No newline at end of file + return item + + def remove(self, item): + if item in self.inventory: + self.inventory.remove(item) + return item + + return False \ No newline at end of file From 0abff7f36dc11ef76589b142a70dcbac79d3489d Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Mon, 3 Apr 2023 13:16:06 -0700 Subject: [PATCH 05/39] implemented test_removing_not_found_is_false --- 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 e7664409ad012d417c68b0a433b7f236ed5f988e Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 13:13:09 -0700 Subject: [PATCH 06/39] fixed default arg of constructor --- 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 80651e847..ae218b0a7 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,5 +1,7 @@ class Vendor: - def __init__(self, inventory = []): + def __init__(self, inventory = None): + if inventory is None: + inventory = [] self.inventory = inventory def add(self, item): From 701f134c055941dfcfdfa722509cd6989e782479 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 13:25:53 -0700 Subject: [PATCH 07/39] imported uuid and created constructor for Item class --- 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..46b467104 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,5 @@ +import uuid + class Item: - pass \ No newline at end of file + def __init__(self, id = uuid.uuid4().int): + self.id = id \ No newline at end of file From 540e2568d48c787ead6dfe21de683ed0e82af98b Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 13:29:13 -0700 Subject: [PATCH 08/39] implemented get_category --- 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 46b467104..e35a9480b 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -2,4 +2,7 @@ class Item: def __init__(self, id = uuid.uuid4().int): - self.id = id \ No newline at end of file + self.id = id + + def get_category(self): + return "Item" \ No newline at end of file From 5f893f95480f46dd6666ddf2e2f59f5d1a92e627 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 13:44:35 -0700 Subject: [PATCH 09/39] fixed default arg of constructor --- 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 e35a9480b..58ce58af0 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,7 +1,9 @@ import uuid class Item: - def __init__(self, id = uuid.uuid4().int): + def __init__(self, id = None): + if id is None: + id = uuid.uuid4().int self.id = id def get_category(self): From 8fbd05a330508c8f69307ef06f19d9acb6085e57 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 13:55:46 -0700 Subject: [PATCH 10/39] implemented get_by_id --- swap_meet/vendor.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index ae218b0a7..002e17e80 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -13,4 +13,11 @@ def remove(self, item): self.inventory.remove(item) return item - return False \ No newline at end of file + return False + + def get_by_id(self, item_id): + for item in self.inventory: + if item.id == item_id: + return item + + return None \ No newline at end of file From d84bfb3d2db19c7d39770bb70f1f7fa98529716c Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 14:53:41 -0700 Subject: [PATCH 11/39] implemented __str__ --- 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 58ce58af0..cb9b0d440 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -7,4 +7,7 @@ def __init__(self, id = None): self.id = id def get_category(self): - return "Item" \ No newline at end of file + return "Item" + + def __str__(self): + return f"An object of type Item with id {self.id}." \ No newline at end of file From 8b9e23c6dac0cc6ddcd4f4525e9f874c5a762bc1 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 15:16:27 -0700 Subject: [PATCH 12/39] implemented swap_items --- 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 002e17e80..6dfbbd2a3 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -20,4 +20,16 @@ def get_by_id(self, item_id): if item.id == item_id: return item - return None \ No newline at end of file + return None + + 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 + + self.remove(my_item) + other_vendor.add(my_item) + + other_vendor.remove(their_item) + self.add(their_item) + + return True \ No newline at end of file From c24939318e62743916bc1f38c0f16c3b92dc9a73 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 15:17:48 -0700 Subject: [PATCH 13/39] implemented test_swap_items_from_their_empty_returns_false --- tests/unit_tests/test_wave_03.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index c85da6797..993fa2196 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(): test_id = 12345 item = Item(id=test_id) @@ -12,7 +12,7 @@ def test_item_overrides_to_string(): expected_result = f"An object of type Item with id {test_id}." assert item_as_string == expected_result -@pytest.mark.skip +# @pytest.mark.skip def test_swap_items_returns_true(): item_a = Item() item_b = Item() @@ -40,7 +40,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() item_b = Item() @@ -67,7 +67,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() item_b = Item() @@ -94,7 +94,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=[] @@ -114,7 +114,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() item_b = Item() @@ -131,7 +131,11 @@ def test_swap_items_from_their_empty_returns_false(): result = fatimah.swap_items(jolie, item_b, nobodys_item) - raise Exception("Complete this test according to comments below.") + assert len(fatimah.inventory) == 3 + assert len(jolie.inventory) == 0 + assert not result + + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* From 42f252047eea652ebabfb7479827ce1174102d59 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 15:30:31 -0700 Subject: [PATCH 14/39] implemented swap_first_item --- swap_meet/vendor.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 6dfbbd2a3..4e05837cf 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -32,4 +32,11 @@ def swap_items(self, other_vendor, my_item, their_item): other_vendor.remove(their_item) self.add(their_item) + return True + + def swap_first_item(self, other_vendor): + if not self.inventory or not other_vendor.inventory: + return False + + self.swap_items(other_vendor, self.inventory[0], other_vendor.inventory[0]) return True \ No newline at end of file From 88be6b1fe277bfed801584a8b7804125f4cfb974 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 15:44:50 -0700 Subject: [PATCH 15/39] imported Item class and implemented constructor for Clothing class --- swap_meet/clothing.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..b436f75d3 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,6 @@ -class Clothing: - pass \ No newline at end of file +from swap_meet.item import Item + +class Clothing(Item): + def __init__(self, id=None, fabric="Unknown"): + super().__init__() + self.fabric = fabric \ No newline at end of file From 4c54b280b0f5053df8391b0aceeeb6004ab47761 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 15:50:16 -0700 Subject: [PATCH 16/39] implemented get_category in Clothing class --- swap_meet/clothing.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b436f75d3..5d8a02a1d 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -3,4 +3,7 @@ class Clothing(Item): def __init__(self, id=None, fabric="Unknown"): super().__init__() - self.fabric = fabric \ No newline at end of file + self.fabric = fabric + + def get_category(self): + return "Clothing" \ No newline at end of file From 24ad341424d568d589eba579c34a5dcd8b6ed8a0 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 15:56:13 -0700 Subject: [PATCH 17/39] implemented __str__ in Clothing class --- swap_meet/clothing.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 5d8a02a1d..8bfe231c7 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -6,4 +6,8 @@ def __init__(self, id=None, fabric="Unknown"): self.fabric = fabric def get_category(self): - return "Clothing" \ No newline at end of file + return "Clothing" + + def __str__(self): + return f"An object of type Clothing with id {self.id}. It is made from {self.fabric} fabric." + \ No newline at end of file From e983a0d99cf1f2a6c7c0d97bcfdf605d78dfe075 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 21:54:45 -0700 Subject: [PATCH 18/39] fixed default arg id in constructor --- swap_meet/clothing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 8bfe231c7..92c565c0c 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -2,9 +2,9 @@ class Clothing(Item): def __init__(self, id=None, fabric="Unknown"): - super().__init__() + super().__init__(id) self.fabric = fabric - + def get_category(self): return "Clothing" From eee6a6de5f2a77da352f55530ed0290edc1dcd6a Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 22:01:07 -0700 Subject: [PATCH 19/39] imported Item class and created constructor for Decor class --- swap_meet/decor.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/swap_meet/decor.py b/swap_meet/decor.py index eab7a9dbe..9dd5cd3f5 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,7 @@ -class Decor: - pass \ No newline at end of file +from swap_meet.item import Item + +class Decor(Item): + def __init__(self, id=None, width=0, length=0): + super().__init__(id) + self.width = width + self.length = length \ No newline at end of file From 502e9f486fe945c8153d483c935daf48ce170ac4 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 22:02:34 -0700 Subject: [PATCH 20/39] implemented get_category for Decor class --- swap_meet/decor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/swap_meet/decor.py b/swap_meet/decor.py index 9dd5cd3f5..63828d3e1 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -4,4 +4,7 @@ class Decor(Item): def __init__(self, id=None, width=0, length=0): super().__init__(id) self.width = width - self.length = length \ No newline at end of file + self.length = length + + def get_category(self): + return "Decor" \ No newline at end of file From ac7e52e71a43b0d730855a1f791eab70381f5750 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 22:05:21 -0700 Subject: [PATCH 21/39] implemented __str__ in Decor --- swap_meet/decor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/swap_meet/decor.py b/swap_meet/decor.py index 63828d3e1..74974e7da 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -7,4 +7,7 @@ def __init__(self, id=None, width=0, length=0): self.length = length def get_category(self): - return "Decor" \ No newline at end of file + return "Decor" + + def __str__(self): + return f"An object of type Decor with id {self.id}. It takes up a {self.width} by {self.length} sized space." \ No newline at end of file From 957c23bed2a5c2693e9f2473418a65f0461c1120 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 22:06:23 -0700 Subject: [PATCH 22/39] imported Item class into Electronics --- swap_meet/electronics.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2f9dff68a..95fc7d353 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,4 @@ +from swap_meet.item import Item + class Electronics: pass From 7ecbbb03f0ee86da02aa2833bd29610a243fa63c Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 22:09:28 -0700 Subject: [PATCH 23/39] implemented constructor for Electronics --- swap_meet/electronics.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 95fc7d353..0923418c8 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,4 +1,6 @@ from swap_meet.item import Item -class Electronics: - pass +class Electronics(Item): + def __init__(self, id=None, type="Unknown"): + super().__init__(id) + self.type = type From 2674624d0e432c510230357877f162278071d8ab Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 22:10:13 -0700 Subject: [PATCH 24/39] implemented get_category for Electronics --- swap_meet/electronics.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 0923418c8..04d16b1d3 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -4,3 +4,6 @@ class Electronics(Item): def __init__(self, id=None, type="Unknown"): super().__init__(id) self.type = type + + def get_category(self): + return "Electronics" \ No newline at end of file From e08874b554341897341547efe0c4d774b506a5ac Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 22:11:42 -0700 Subject: [PATCH 25/39] implemented __str__ for Electronics --- swap_meet/electronics.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 04d16b1d3..9468b0a11 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -6,4 +6,7 @@ def __init__(self, id=None, type="Unknown"): self.type = type def get_category(self): - return "Electronics" \ No newline at end of file + return "Electronics" + + def __str__(self): + return f"An object of type Electronics with id {self.id}. This is a {self.type} device." \ No newline at end of file From 9b75e9342920702a9cd868798c496d030887af5d Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Tue, 4 Apr 2023 22:18:42 -0700 Subject: [PATCH 26/39] added condition as an optional parameter for all classes --- swap_meet/clothing.py | 4 ++-- swap_meet/decor.py | 4 ++-- swap_meet/electronics.py | 4 ++-- swap_meet/item.py | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 92c565c0c..a822f97ea 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,8 +1,8 @@ from swap_meet.item import Item class Clothing(Item): - def __init__(self, id=None, fabric="Unknown"): - super().__init__(id) + def __init__(self, id=None, condition=0, fabric="Unknown"): + super().__init__(id, condition) self.fabric = fabric def get_category(self): diff --git a/swap_meet/decor.py b/swap_meet/decor.py index 74974e7da..daf96dc64 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,8 +1,8 @@ from swap_meet.item import Item class Decor(Item): - def __init__(self, id=None, width=0, length=0): - super().__init__(id) + def __init__(self, id=None, condition=0, width=0, length=0): + super().__init__(id, condition) self.width = width self.length = length diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 9468b0a11..2bb2dde6a 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,8 +1,8 @@ from swap_meet.item import Item class Electronics(Item): - def __init__(self, id=None, type="Unknown"): - super().__init__(id) + def __init__(self, id=None, condition=0, type="Unknown"): + super().__init__(id, condition) self.type = type def get_category(self): diff --git a/swap_meet/item.py b/swap_meet/item.py index cb9b0d440..6092d8e92 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,10 +1,11 @@ import uuid class Item: - def __init__(self, id = None): + def __init__(self, id=None, condition=0): if id is None: id = uuid.uuid4().int self.id = id + self.condition = condition def get_category(self): return "Item" From 08ec32701a61c88913eaca96214ca303bc5c8712 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Wed, 5 Apr 2023 10:57:26 -0700 Subject: [PATCH 27/39] implemented condition_description --- swap_meet/item.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 6092d8e92..fc6c3ea6a 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -11,4 +11,16 @@ def get_category(self): return "Item" def __str__(self): - return f"An object of type Item with id {self.id}." \ No newline at end of file + return f"An object of type Item with id {self.id}." + + def condition_description(self): + condition_dict = { + 1: "Bad", + 2: "Not good", + 3: "Okay", + 4: "Good", + 5: "Great" + } + + if self.condition in condition_dict: + return condition_dict[self.condition] \ No newline at end of file From 25b7825c963d1dcdc1c62025a5d154e62df34d45 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Wed, 5 Apr 2023 11:14:30 -0700 Subject: [PATCH 28/39] updated dict values in condition_description --- swap_meet/item.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index fc6c3ea6a..834d91f2d 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -15,11 +15,12 @@ def __str__(self): def condition_description(self): condition_dict = { - 1: "Bad", - 2: "Not good", + 0: "Trash", + 1: "Yikes", + 2: "Meh", 3: "Okay", - 4: "Good", - 5: "Great" + 4: "Pretty good", + 5: "Brilliant, incredible, amazing, show stopping, spectacular, never the same, totally unique, completely not ever been done before" } if self.condition in condition_dict: From 11fe273f43378531614bc19e84d39639eebd5ab9 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Thu, 6 Apr 2023 13:56:30 -0700 Subject: [PATCH 29/39] implemented get_by_category --- swap_meet/vendor.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 4e05837cf..36bf582d3 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -39,4 +39,11 @@ def swap_first_item(self, other_vendor): return False self.swap_items(other_vendor, self.inventory[0], other_vendor.inventory[0]) - return True \ No newline at end of file + return True + + def get_by_category(self, category): + category_items = [] + for item in self.inventory: + if item.get_category() == category: + category_items.append(item) + return category_items From 3ac50cfa6018800a645ad76b352ce468970090d5 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Thu, 6 Apr 2023 14:02:27 -0700 Subject: [PATCH 30/39] implemented assert portion of test_get_no_matching_items_by_category --- tests/unit_tests/test_wave_06.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index ad51bf42d..4d215fcca 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -5,7 +5,7 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip +# @pytest.mark.skip def test_get_items_by_category(): item_a = Clothing() item_b = Electronics() @@ -22,7 +22,7 @@ def test_get_items_by_category(): assert item_a in items assert item_c in items -@pytest.mark.skip +# @pytest.mark.skip def test_get_no_matching_items_by_category(): item_a = Clothing() item_b = Item() @@ -31,9 +31,11 @@ def test_get_no_matching_items_by_category(): inventory=[item_a, item_b, item_c] ) - items = vendor.get_by_category("Electronics") + items = vendor.get_by_category("Electronics") - raise Exception("Complete this test according to comments below.") + assert len(items) == 0 + assert items == [] + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* From d5d681204d16f45f18f42d7c12d3654aab08bbeb Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Thu, 6 Apr 2023 14:20:05 -0700 Subject: [PATCH 31/39] implemented get_best_by_category --- swap_meet/vendor.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 36bf582d3..d2bb8acfd 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -47,3 +47,12 @@ def get_by_category(self, category): if item.get_category() == category: category_items.append(item) return category_items + + def get_best_by_category(self, category): + best_item = None + condition = 0 + for item in self.inventory: + if item.get_category() == category and item.condition > condition: + condition = item.condition + best_item = item + return best_item From 2b3abd7ba776bfb57cd8bc25f0922236c6285654 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Thu, 6 Apr 2023 14:31:55 -0700 Subject: [PATCH 32/39] implemented test_swap_best_by_category --- tests/unit_tests/test_wave_06.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 4d215fcca..0ab6ffcb1 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -40,7 +40,7 @@ def test_get_no_matching_items_by_category(): # ****** Complete Assert Portion of this test ********** # ********************************************************************* -@pytest.mark.skip +# @pytest.mark.skip def test_best_by_category(): item_a = Clothing(condition=2.0) item_b = Decor(condition=2.0) @@ -56,7 +56,7 @@ def test_best_by_category(): assert best_item.get_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) @@ -69,7 +69,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) @@ -92,7 +92,7 @@ def test_swap_best_by_category(): # me item_a = Decor(condition=2.0) item_b = Electronics(condition=4.0) - item_c = Decor(condition=4.0) + item_c = Decor(condition=4.0) tai = Vendor( inventory=[item_a, item_b, item_c] ) @@ -100,7 +100,7 @@ def test_swap_best_by_category(): # them item_d = Clothing(condition=2.0) item_e = Decor(condition=4.0) - item_f = Clothing(condition=4.0) + item_f = Clothing(condition=4.0) jesse = Vendor( inventory=[item_d, item_e, item_f] ) @@ -112,7 +112,12 @@ 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 tai.inventory == [item_a, item_b, item_f] + assert jesse.inventory == [item_d, item_e, item_c] + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* From 32263183e9f717081e6fb6e7087a372ac7b4ccb1 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Thu, 6 Apr 2023 14:46:54 -0700 Subject: [PATCH 33/39] implemented swap_best_by_category --- swap_meet/vendor.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index d2bb8acfd..7df4c4b6d 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -56,3 +56,18 @@ def get_best_by_category(self, category): condition = item.condition best_item = item return best_item + + def swap_best_by_category(self, other_vendor, my_priority, their_priority): + if other_vendor.get_by_category(my_priority): + their_best_item = other_vendor.get_best_by_category(my_priority) + else: + return False + + if self.get_by_category(their_priority): + my_best_item = self.get_best_by_category(their_priority) + else: + return False + + self.swap_items(other_vendor, my_best_item, their_best_item) + return True + \ No newline at end of file From cf4f071bb17dd250c514d36706056b5a8dc03763 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Thu, 6 Apr 2023 15:02:52 -0700 Subject: [PATCH 34/39] implemented assert portion of test_swap_best_by_category_reordered --- tests/unit_tests/test_wave_06.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 0ab6ffcb1..74dc086bc 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -86,7 +86,7 @@ def test_best_by_category_with_duplicates(): assert best_item.get_category() == "Clothing" assert best_item.condition == pytest.approx(4.0) -@pytest.mark.skip +# @pytest.mark.skip def test_swap_best_by_category(): # Arrange # me @@ -126,7 +126,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) @@ -150,7 +150,20 @@ def test_swap_best_by_category_reordered(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + # Assert + assert result + assert len(tai.inventory) == 3 + assert len(jesse.inventory) == 3 + assert item_c not in tai.inventory + assert item_f not in jesse.inventory + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_f in tai.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_c in jesse.inventory + + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* From 43a7d2e9968280d7f4eb191e939129d6b87c353d Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Thu, 6 Apr 2023 15:05:13 -0700 Subject: [PATCH 35/39] added and deleted assert statements in test_swap_best_by_category --- tests/unit_tests/test_wave_06.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 74dc086bc..cdd962269 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -115,8 +115,13 @@ def test_swap_best_by_category(): assert result assert len(tai.inventory) == 3 assert len(jesse.inventory) == 3 - assert tai.inventory == [item_a, item_b, item_f] - assert jesse.inventory == [item_d, item_e, item_c] + assert item_a in tai.inventory + assert item_b in tai.inventory + assert item_f in tai.inventory + assert item_d in jesse.inventory + assert item_e in jesse.inventory + assert item_c in jesse.inventory + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** From 618c8d32a692480c55f5650bf9c912005a570b66 Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Thu, 6 Apr 2023 15:11:38 -0700 Subject: [PATCH 36/39] implemented assert portion of test_swap_best_by_category_no_match_is_false --- tests/unit_tests/test_wave_06.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index cdd962269..4b98896fc 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -121,7 +121,7 @@ def test_swap_best_by_category(): 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 ********** @@ -177,7 +177,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=[] @@ -203,7 +203,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) @@ -229,7 +229,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) @@ -253,7 +253,17 @@ def test_swap_best_by_category_no_match_is_false(): their_priority="Clothing" ) - raise Exception("Complete this test according to comments below.") + 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 ********** # ********************************************************************* From 090f94a754d0812f546aebcfd4b42f17880ce6de Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Thu, 6 Apr 2023 15:14:42 -0700 Subject: [PATCH 37/39] implemented assert portion of test_swap_best_by_category_no_other_match_is_false --- tests/unit_tests/test_wave_06.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 4b98896fc..05023c74b 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -272,7 +272,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) @@ -296,7 +296,17 @@ def test_swap_best_by_category_no_other_match_is_false(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + 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 ********** # ********************************************************************* From 55f9676a321acddd2c47ee128cfd7d887386754c Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Thu, 6 Apr 2023 18:39:53 -0700 Subject: [PATCH 38/39] refactored swap_best_by_category --- swap_meet/vendor.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 7df4c4b6d..1c639a478 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -58,16 +58,10 @@ def get_best_by_category(self, category): return best_item def swap_best_by_category(self, other_vendor, my_priority, their_priority): - if other_vendor.get_by_category(my_priority): - their_best_item = other_vendor.get_best_by_category(my_priority) - else: - return False - - if self.get_by_category(their_priority): - my_best_item = self.get_best_by_category(their_priority) - else: - return False - - self.swap_items(other_vendor, my_best_item, their_best_item) - return True + my_best_item = self.get_best_by_category(their_priority) + their_best_item = other_vendor.get_best_by_category(my_priority) + if my_best_item and their_best_item: + self.swap_items(other_vendor, my_best_item, their_best_item) + return True + return False \ No newline at end of file From 8c3108ec36fa8fd87fa1abc5244fbe261db475de Mon Sep 17 00:00:00 2001 From: Sophia Tran Date: Thu, 6 Apr 2023 18:49:10 -0700 Subject: [PATCH 39/39] spaced out code for readability --- swap_meet/vendor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 1c639a478..60f150837 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -43,14 +43,17 @@ def swap_first_item(self, other_vendor): def get_by_category(self, category): category_items = [] + for item in self.inventory: if item.get_category() == category: category_items.append(item) + return category_items def get_best_by_category(self, category): best_item = None condition = 0 + for item in self.inventory: if item.get_category() == category and item.condition > condition: condition = item.condition @@ -60,6 +63,7 @@ def get_best_by_category(self, category): def swap_best_by_category(self, other_vendor, my_priority, their_priority): my_best_item = self.get_best_by_category(their_priority) their_best_item = other_vendor.get_best_by_category(my_priority) + if my_best_item and their_best_item: self.swap_items(other_vendor, my_best_item, their_best_item) return True