From 9cfe636e2315a1832f67ed664c0a7de3fadded98 Mon Sep 17 00:00:00 2001 From: Alma Date: Tue, 4 Oct 2022 22:11:46 -0700 Subject: [PATCH 01/10] wave 1 finished --- README.md | 21 ++++++++++----------- swap_meet/item.py | 15 ++++++++++++++- swap_meet/vendor.py | 30 +++++++++++++++++++++++++++++- tests/unit_tests/test_wave_01.py | 16 +++++++++------- tests/unit_tests/test_wave_02.py | 5 +++-- 5 files changed, 65 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 20ec0dad2..5908ffb67 100644 --- a/README.md +++ b/README.md @@ -61,30 +61,29 @@ At submission time, no matter where you are, submit the project via Learn. ### Wave 1 In Wave 1 we will create the `Vendor` class. - + + -- Similarly, every instance of `Vendor` has an instance method named `remove`, which takes in one item + ### Wave 2 -In Wave 2 we will create the `Item` class and the `get_by_category` method. + -- Inside this module, there is a class named `Item` -- Each `Item` will have an attribute named `category`, which is an empty string by default + + - When we initialize an instance of `Item`, we can optionally pass in a string with the keyword argument `category` - Instances of `Vendor` have an instance method named `get_by_category` - It takes one argument: a string, representing a category diff --git a/swap_meet/item.py b/swap_meet/item.py index 560d759c2..5458ca5c8 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,15 @@ + class Item: - pass \ No newline at end of file + def __init__(self, category=''): + self.category = category + + if self.category == "": + return None + + else: + return category + + +# item_a = Item(category="clothing") +# item_b = Item(category="electronics") +# item_c = Item(category="clothing") \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 87302c056..53470f607 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,30 @@ +from pickle import FALSE +from swap_meet import item +# from item import Item + class Vendor: - pass \ No newline at end of file + def __init__(self, inventory=[]): + self.inventory = inventory + # self.item = item + + def add(self, item): + self.inventory.append(item) + return item + + def remove(self, item): + if item in self.inventory: + self.inventory.remove(item) + return item + else: + return False + + def get_by_category(self,category): + items = [] + self.category = category + if self.category == item.self.category: + items.append(item.self.category) + + else: + return None + + # def swap_items(): diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index 58478ccf9..038715371 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,16 +40,18 @@ 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" + item = "d" #"item to remove" vendor = Vendor( inventory=["a", "b", "c"] ) result = vendor.remove(item) - raise Exception("Complete this test according to comments below.") + assert item not in vendor.inventory + # raise Exception("Complete this test according to comments below.") + # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index 3d7060d7c..cf77e4df1 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -2,16 +2,17 @@ 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") item_c = Item(category="clothing") + vendor = Vendor( inventory=[item_a, item_b, item_c] ) From 8dc866bc5f320e217f4f40726e9157c2fc3a4b80 Mon Sep 17 00:00:00 2001 From: Alma Date: Tue, 4 Oct 2022 22:14:35 -0700 Subject: [PATCH 02/10] ignore this file --- alma_test.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 alma_test.py diff --git a/alma_test.py b/alma_test.py new file mode 100644 index 000000000..052a84931 --- /dev/null +++ b/alma_test.py @@ -0,0 +1,15 @@ +# class Vendor: +# def __init__(self, inventory=[]): +# self.inventory = inventory + + +# vendor = Vendor() + +# print(len(vendor.inventory)) + + +class Item: + def __init__(self, category=''): + self.category = category + + \ No newline at end of file From f89dcb32fd05acd3cf3a0131a3208076e1208663 Mon Sep 17 00:00:00 2001 From: Alma Date: Wed, 5 Oct 2022 09:26:10 -0700 Subject: [PATCH 03/10] Wave 2 finished --- README.md | 4 +-- alma_test.py | 31 ++++++++++++----- swap_meet/item.py | 15 +++------ swap_meet/vendor.py | 58 ++++++++++++++++++++++++++------ tests/unit_tests/test_wave_02.py | 6 ++-- tests/unit_tests/test_wave_03.py | 2 +- 6 files changed, 81 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 5908ffb67..572e063e0 100644 --- a/README.md +++ b/README.md @@ -84,10 +84,10 @@ In Wave 1 we will create the `Vendor` class. -- When we initialize an instance of `Item`, we can optionally pass in a string with the keyword argument `category` + ### Wave 3 diff --git a/alma_test.py b/alma_test.py index 052a84931..9d22b0151 100644 --- a/alma_test.py +++ b/alma_test.py @@ -1,15 +1,30 @@ -# class Vendor: -# def __init__(self, inventory=[]): -# self.inventory = inventory +# # class Vendor: +# # def __init__(self, inventory=[]): +# # self.inventory = inventory -# vendor = Vendor() +# # vendor = Vendor() -# print(len(vendor.inventory)) +# # print(len(vendor.inventory)) -class Item: - def __init__(self, category=''): - self.category = category +# class Item: +# def __init__(self, category=''): +# self.category = category + +# class Item: +# def __init__(self, category=None): +# self.category = category + +# if self.category == "": +# return + +# else: +# return self.category + + +# item_a = Item(category="clothing") +# item_b = Item(category="electronics") +# item_c = Item(category="clothing") \ No newline at end of file diff --git a/swap_meet/item.py b/swap_meet/item.py index 5458ca5c8..cbbd50910 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,15 +1,8 @@ class Item: - def __init__(self, category=''): + def __init__(self, category = ""): self.category = category - if self.category == "": - return None - - else: - return category - - -# item_a = Item(category="clothing") -# item_b = Item(category="electronics") -# item_c = Item(category="clothing") \ No newline at end of file + def __str__ (self): + return 'Hello World!' + \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 53470f607..425c931b1 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,6 +1,6 @@ from pickle import FALSE from swap_meet import item -# from item import Item +# from swap_meet.item import Item class Vendor: def __init__(self, inventory=[]): @@ -17,14 +17,52 @@ def remove(self, item): return item else: return False - - def get_by_category(self,category): - items = [] - self.category = category - if self.category == item.self.category: - items.append(item.self.category) - else: - return None + # wave_2 + def get_by_category(self, category): + # self.category = category # no needed + items_list = [] + for item in self.inventory: + if item.category == category: + items_list.append(item) + return items_list + + + # wave_3 + + + + + + + + + + + + + + + + + + +# # wave_3 +# def swap_items(self, ): - # def swap_items(): +# #pending!! +# def swap_items(self, swapping_vendor, my_item, their_item): +# """given another vendor, my_item to swap, their_item to receive, make that swap.""" +# #if each item is in the right place, make the swap: +# if my_item in self.inventory and their_item in swapping_vendor.inventory: +# #make the swap +# self.remove(my_item) +# self.add(their_item) +# swapping_vendor.add(my_item) +# swapping_vendor.remove(their_item) +# return True +# else: +# return False + + + diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index cf77e4df1..b17df3980 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -24,7 +24,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,8 +34,8 @@ def test_get_no_matching_items_by_category(): ) items = vendor.get_by_category("electronics") - - raise Exception("Complete this test according to comments below.") + assert len(items) == 0 + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* 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 b2d93b8184d55cff9e2aa8dd0c0c35e8243a4a45 Mon Sep 17 00:00:00 2001 From: Alma Date: Wed, 5 Oct 2022 09:52:52 -0700 Subject: [PATCH 04/10] wave_3 finished --- README.md | 4 +-- swap_meet/vendor.py | 50 ++++++++------------------------ tests/unit_tests/test_wave_03.py | 10 +++---- 3 files changed, 19 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 572e063e0..765fc7ce7 100644 --- a/README.md +++ b/README.md @@ -91,10 +91,10 @@ In Wave 1 we will create the `Vendor` class. ### Wave 3 -In Wave 3 we will write a method to stringify an `Item` using `str()` and write the method `swap_items`. + The remaining tests in wave 3 imply: diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 425c931b1..3dd7d26cb 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -20,49 +20,23 @@ def remove(self, item): # wave_2 def get_by_category(self, category): - # self.category = category # no needed items_list = [] for item in self.inventory: if item.category == category: items_list.append(item) return items_list - - # wave_3 - - - - - - - - - - - - - - - - - - -# # wave_3 -# def swap_items(self, ): - -# #pending!! -# def swap_items(self, swapping_vendor, my_item, their_item): -# """given another vendor, my_item to swap, their_item to receive, make that swap.""" -# #if each item is in the right place, make the swap: -# if my_item in self.inventory and their_item in swapping_vendor.inventory: -# #make the swap -# self.remove(my_item) -# self.add(their_item) -# swapping_vendor.add(my_item) -# swapping_vendor.remove(their_item) -# return True -# else: -# return False - + # wave_3 + def swap_items(self, swapping_other_vendor, my_item, their_item): + if my_item in self.inventory and their_item in swapping_other_vendor.inventory: + self.remove(my_item) + self.add(their_item) + swapping_other_vendor.add(my_item) + swapping_other_vendor.remove(their_item) + return True + else: + return False + # Wave_4 + diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 1cd00badb..41d4b0da3 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") @@ -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 425c38395b156f6cf5dfa1cd812fe05034022f67 Mon Sep 17 00:00:00 2001 From: Alma Date: Wed, 5 Oct 2022 12:21:40 -0700 Subject: [PATCH 05/10] wave_4 finished --- swap_meet/vendor.py | 9 +++++++-- tests/unit_tests/test_wave_04.py | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 3dd7d26cb..fb2c8b403 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -37,6 +37,11 @@ def swap_items(self, swapping_other_vendor, my_item, their_item): else: return False - # Wave_4 - + def swap_first_item(self, swapping_other_vendor): + if self.inventory == [] or swapping_other_vendor.inventory == []: + return False + + self.swap_items(swapping_other_vendor, self.inventory[0], swapping_other_vendor.inventory[0]) + return True + diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index 8190a4ebb..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 9c62c83f2efeab72fe79d57a4824250e6dc1482d Mon Sep 17 00:00:00 2001 From: Alma Date: Thu, 6 Oct 2022 13:17:21 -0700 Subject: [PATCH 06/10] Wave_5 finished --- README.md | 28 ++++++++--------- alma_test.py | 30 ------------------- swap_meet/clothing.py | 13 ++++++-- swap_meet/decor.py | 12 ++++++-- swap_meet/electronics.py | 12 ++++++-- swap_meet/item.py | 19 ++++++++++-- swap_meet/vendor.py | 19 ++++++++++-- tests/integration_tests/test_wave_01_02_03.py | 4 +-- tests/unit_tests/test_wave_05.py | 10 +++---- 9 files changed, 84 insertions(+), 63 deletions(-) delete mode 100644 alma_test.py diff --git a/README.md b/README.md index 765fc7ce7..01e53d24e 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ In Wave 1 we will create the `Vendor` class. - When we stringify (convert to a string) an instance of `Item` using `str()`, it returns `"Hello World!"` - This implies `Item` overrides its stringify method. We may need to research the `__str__` method for more details! --> -The remaining tests in wave 3 imply: + ### Wave 4 -In Wave 4 we will write one method, `swap_first_item`. + ### Wave 5 In Wave 5 we will create three additional modules with three additional classes: -- `Clothing` + + + --> - All three classes and the `Item` class have an attribute called `condition`, which can be optionally provided in the initializer. The default value should be `0`. - All three classes and the `Item` class have an instance method named `condition_description`, which should describe the condition in words based on the value, assuming they all range from 0 to 5. These can be basic descriptions (eg. 'mint', 'heavily used') but feel free to have fun with these (e.g. 'You probably want a glove for this one..."). The one requirement is that the `condition_description` for all three classes above have the same behavior. -#### Using Inheritance + + ### Wave 6 diff --git a/alma_test.py b/alma_test.py deleted file mode 100644 index 9d22b0151..000000000 --- a/alma_test.py +++ /dev/null @@ -1,30 +0,0 @@ -# # class Vendor: -# # def __init__(self, inventory=[]): -# # self.inventory = inventory - - -# # vendor = Vendor() - -# # print(len(vendor.inventory)) - - -# class Item: -# def __init__(self, category=''): -# self.category = category - - -# class Item: -# def __init__(self, category=None): -# self.category = category - -# if self.category == "": -# return - -# else: -# return self.category - - -# item_a = Item(category="clothing") -# item_b = Item(category="electronics") -# item_c = Item(category="clothing") - \ No newline at end of file diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index b8afdeb1e..8f1df1286 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,11 @@ -class Clothing: - pass \ No newline at end of file +# from pyparsing import condition_as_parse_action +from swap_meet.item import Item + +class Clothing(Item): + def __init__(self, condition=0): + category = 'Clothing' + super().__init__(category = category, condition=condition) + + + def __str__(self): + return 'The finest clothing you could wear.' \ No newline at end of file diff --git a/swap_meet/decor.py b/swap_meet/decor.py index eab7a9dbe..4a55b69e2 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,10 @@ -class Decor: - pass \ No newline at end of file +from swap_meet.item import Item + +class Decor(Item): + def __init__(self, condition=0): + category = 'Decor' + super().__init__(category = category, condition=condition) + + + def __str__(self): + return "Something to decorate your space." \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 2f9dff68a..3d5689e1c 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,10 @@ -class Electronics: - pass +from swap_meet.item import Item + +class Electronics(Item): + def __init__(self, condition=0): + category = 'Electronics' + super().__init__(category = category, condition=condition) + + + def __str__(self): + return "A gadget full of buttons and secrets." diff --git a/swap_meet/item.py b/swap_meet/item.py index cbbd50910..d8e3367bc 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,8 +1,21 @@ +# from attr import NOTHING + class Item: - def __init__(self, category = ""): + def __init__(self, category = "", condition=None): + if not condition: + condition = 0.0 + self.condition = condition self.category = category def __str__ (self): - return 'Hello World!' - \ No newline at end of file + return "Hello World!" + + def condition_description(self): + if self.condition >= 0 and self.condition <=2: + return "Condition: imperfect" + elif self.condition >=3 and self.condition <=4: + return "Condition: gently used" + else: + return "Condition: like new" + \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index fb2c8b403..aeac09bf3 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,11 +1,12 @@ -from pickle import FALSE +# from pickle import FALSE from swap_meet import item # from swap_meet.item import Item class Vendor: - def __init__(self, inventory=[]): + def __init__(self, inventory=None): + if not inventory: + inventory = [] self.inventory = inventory - # self.item = item def add(self, item): self.inventory.append(item) @@ -45,3 +46,15 @@ def swap_first_item(self, swapping_other_vendor): self.swap_items(swapping_other_vendor, self.inventory[0], swapping_other_vendor.inventory[0]) return True + # Wave_5 + + + # Wave_6 + + + # def get_best_by_category(self,category): + # pass + + + # def swap_best_by_category`(self, + # pass \ No newline at end of file diff --git a/tests/integration_tests/test_wave_01_02_03.py b/tests/integration_tests/test_wave_01_02_03.py index 9912414da..34d042fdd 100644 --- a/tests/integration_tests/test_wave_01_02_03.py +++ b/tests/integration_tests/test_wave_01_02_03.py @@ -2,8 +2,8 @@ from swap_meet.vendor import Vendor from swap_meet.item import Item -@pytest.mark.skip -@pytest.mark.integration_test +# @pytest.mark.skip +# @pytest.mark.integration_test def test_integration_wave_01_02_03(): # make a vendor vendor = Vendor() 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 e274e98b55d62ab410c58e456586b128c6cb9957 Mon Sep 17 00:00:00 2001 From: Alma Date: Thu, 6 Oct 2022 16:45:36 -0700 Subject: [PATCH 07/10] Wave_6 finished --- swap_meet/vendor.py | 33 ++++++++++++++++++++++---------- tests/unit_tests/test_wave_06.py | 20 ++++++++++++------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index aeac09bf3..4250eac65 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -46,15 +46,28 @@ def swap_first_item(self, swapping_other_vendor): self.swap_items(swapping_other_vendor, self.inventory[0], swapping_other_vendor.inventory[0]) return True - # Wave_5 - - # Wave_6 - - # def get_best_by_category(self,category): - # pass - - - # def swap_best_by_category`(self, - # pass \ No newline at end of file + def get_best_by_category(self, category): + + inventory_items_category = self.get_by_category(category) + if inventory_items_category == []: + return None + + highest_item = inventory_items_category[0] + for item in inventory_items_category: + if item.condition >= highest_item.condition: + highest_item = item + return highest_item + + def swap_best_by_category(self, other, my_priority, their_priority): + + if not self.inventory or not other: + return None + + my_priority_item = other.get_best_by_category(my_priority) # item + their_priority_item = self.get_best_by_category(their_priority) #item + + self.swap_items(other, my_priority_item, their_priority_item) + return True + \ No newline at end of file diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 1f7065ab4..4f385b92b 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,13 +76,19 @@ def test_swap_best_by_category(): their_priority="Decor" ) - raise Exception("Complete this test according to comments below.") + # raise Exception("Complete this test according to comments below.") + + assert result == True + assert len(jesse.inventory) == 3 + assert len(tai.inventory) == 3 + assert item_c in jesse.inventory + assert item_f in tai.inventory # ********************************************************************* # ****** 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 the results is truthy << ok + # - That tai and jesse's inventories are the correct length << ok # - 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 From 83bfef8474b53b18e2e32edf232264f61660184d Mon Sep 17 00:00:00 2001 From: Alma Date: Fri, 7 Oct 2022 08:39:23 -0700 Subject: [PATCH 08/10] Wave_6 finished --- README.md | 4 +- swap_meet/item.py | 6 +- swap_meet/vendor.py | 26 ++++--- tests/integration_tests/test_wave_04_05_06.py | 4 +- tests/unit_tests/test_wave_06.py | 69 ++++++++++++------- 5 files changed, 71 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 01e53d24e..e0a679f63 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ You'll need to refer to `Item` in order to declare it as a parent. To reference from swap_meet.item import Item ``` --> -### Wave 6 + ### DRYing up the code diff --git a/swap_meet/item.py b/swap_meet/item.py index d8e3367bc..4cdd94bff 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -7,7 +7,11 @@ def __init__(self, category = "", condition=None): condition = 0.0 self.condition = condition self.category = category - + # if not age: + # age = 0 + # self.age = age + + def __str__ (self): return "Hello World!" diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 4250eac65..f4f623851 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,6 +1,8 @@ # from pickle import FALSE -from swap_meet import item -# from swap_meet.item import Item +# from operator import invert +# from unittest import result +# from swap_meet import item +from swap_meet.item import Item class Vendor: def __init__(self, inventory=None): @@ -31,9 +33,9 @@ def get_by_category(self, category): def swap_items(self, swapping_other_vendor, my_item, their_item): if my_item in self.inventory and their_item in swapping_other_vendor.inventory: self.remove(my_item) + swapping_other_vendor.remove(their_item) self.add(their_item) swapping_other_vendor.add(my_item) - swapping_other_vendor.remove(their_item) return True else: return False @@ -49,8 +51,8 @@ def swap_first_item(self, swapping_other_vendor): # Wave_6 def get_best_by_category(self, category): - - inventory_items_category = self.get_by_category(category) + inventory_items_category = self.get_by_category(category) #list + print("inventory>>>", inventory_items_category) if inventory_items_category == []: return None @@ -61,13 +63,19 @@ def get_best_by_category(self, category): return highest_item def swap_best_by_category(self, other, my_priority, their_priority): + print('inve other>>', other.inventory) + print('self inv>>', self.inventory) - if not self.inventory or not other: - return None + if self.inventory == [] or other == []: + return False my_priority_item = other.get_best_by_category(my_priority) # item + print('my item>>>', my_priority_item) their_priority_item = self.get_best_by_category(their_priority) #item + print('their item>>>',their_priority_item) - self.swap_items(other, my_priority_item, their_priority_item) - return True + if my_priority_item in other.inventory and their_priority_item in self.inventory: + return self.swap_items(other, their_priority_item, my_priority_item) + + return False \ No newline at end of file diff --git a/tests/integration_tests/test_wave_04_05_06.py b/tests/integration_tests/test_wave_04_05_06.py index 4d0be9909..cb3b346a2 100644 --- a/tests/integration_tests/test_wave_04_05_06.py +++ b/tests/integration_tests/test_wave_04_05_06.py @@ -4,8 +4,8 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -@pytest.mark.skip -@pytest.mark.integration_test +# @pytest.mark.skip +# @pytest.mark.integration_test def test_integration_wave_04_05_06(): camila = Vendor() valentina = Vendor() diff --git a/tests/unit_tests/test_wave_06.py b/tests/unit_tests/test_wave_06.py index 4f385b92b..1a343d311 100644 --- a/tests/unit_tests/test_wave_06.py +++ b/tests/unit_tests/test_wave_06.py @@ -4,7 +4,8 @@ from swap_meet.decor import Decor from swap_meet.electronics import Electronics -# @pytest.mark.skip +#1 ok +# @pytest.mark.skip def test_best_by_category(): item_a = Clothing(condition=2.0) item_b = Decor(condition=2.0) @@ -19,7 +20,7 @@ def test_best_by_category(): assert best_item.category == "Clothing" assert best_item.condition == pytest.approx(4.0) - +#2 ok # @pytest.mark.skip def test_best_by_category_no_matches_is_none(): item_a = Decor(condition=2.0) @@ -32,7 +33,7 @@ def test_best_by_category_no_matches_is_none(): best_item = tai.get_best_by_category("Electronics") assert best_item is None - +#3 ok # @pytest.mark.skip def test_best_by_category_with_duplicates(): # Arrange @@ -49,7 +50,7 @@ def test_best_by_category_with_duplicates(): # Assert assert best_item.category == "Clothing" assert best_item.condition == pytest.approx(4.0) - +#4 ok # @pytest.mark.skip def test_swap_best_by_category(): # Arrange @@ -76,13 +77,14 @@ def test_swap_best_by_category(): their_priority="Decor" ) - # raise Exception("Complete this test according to comments below.") assert result == True assert len(jesse.inventory) == 3 assert len(tai.inventory) == 3 assert item_c in jesse.inventory assert item_f in tai.inventory + + # raise Exception("Complete this test according to comments below.") # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* @@ -90,8 +92,8 @@ def test_swap_best_by_category(): # - That the results is truthy << ok # - That tai and jesse's inventories are the correct length << ok # - 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 +#5 +# @pytest.mark.skip def test_swap_best_by_category_reordered(): # Arrange item_a = Decor(condition=2.0) @@ -114,17 +116,24 @@ def test_swap_best_by_category_reordered(): my_priority="Clothing", their_priority="Decor" ) - - raise Exception("Complete this test according to comments below.") + + assert result == True + assert len(jesse.inventory) == 3 + assert len(tai.inventory) == 3 + assert item_f in tai.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 result is truthy ok + # - That tai and jesse's inventories are the correct length ok # - 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 +# 6 ok +# @pytest.mark.skip def test_swap_best_by_category_no_inventory_is_false(): tai = Vendor( inventory=[] @@ -149,8 +158,8 @@ def test_swap_best_by_category_no_inventory_is_false(): assert item_a in jesse.inventory assert item_b in jesse.inventory assert item_c in jesse.inventory - -@pytest.mark.skip +#7 ok +# @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) @@ -175,8 +184,8 @@ def test_swap_best_by_category_no_other_inventory_is_false(): assert item_a in tai.inventory assert item_b in tai.inventory assert item_c in tai.inventory - -@pytest.mark.skip +#8 ok +# @pytest.mark.skip def test_swap_best_by_category_no_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -200,16 +209,23 @@ 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 tai.inventory == [item_a, item_b, item_c] + assert jesse.inventory == [item_d, item_e, item_f] + + # raise Exception("Complete this test according to comments below.") + # ********************************************************************* # ****** Complete Assert Portion of this test ********** # ********************************************************************* # Assertions should check: - # - That result is falsy + # - That result is falsy OK # - 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 +#9 ok +# @pytest.mark.skip def test_swap_best_by_category_no_other_match_is_false(): # Arrange item_a = Decor(condition=2.0) @@ -232,12 +248,17 @@ 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 jesse.inventory == [item_f, item_e, item_d] + assert tai.inventory == [item_c, item_b, item_a] + + # 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 result is falsy ok + # - That tai and jesse's inventories are the correct length OK # - That all the correct items are in tai and jesse's inventories From cc53960ecaa126578f3598caa0927109a602d00b Mon Sep 17 00:00:00 2001 From: Alma Date: Fri, 7 Oct 2022 09:42:04 -0700 Subject: [PATCH 09/10] last one,wave_1-6 -> completed / swap_newest_item -> incompleted --- README.md | 14 +++++++------- swap_meet/clothing.py | 4 ++-- swap_meet/decor.py | 4 ++-- swap_meet/electronics.py | 4 ++-- swap_meet/item.py | 8 ++++---- swap_meet/vendor.py | 25 +++++++++++++++++-------- 6 files changed, 34 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index e0a679f63..398447eae 100644 --- a/README.md +++ b/README.md @@ -135,9 +135,9 @@ In Wave 5 we will create three additional modules with three additional classes: - Has an attribute `category` that is `"Electronics"` - Its stringify method returns `"A gadget full of buttons and secrets."` --> --> -- All three classes and the `Item` class have an attribute called `condition`, which can be optionally provided in the initializer. The default value should be `0`. + ### DRYing up the code + -To further reduce the amount of repeated code in your project, consider how `swap_best_by_category` and `swap_first_item` might be able to make use of `swap_items`. Is there a way that these methods could incorporate a call to `swap_items` into the body of these methods? - -Try it out and see if the tests still pass! If you can't get them to pass with this refactor, you can always return to the most recent working commit before you submit the project! + ## Optional Enhancements Should a project be completed before submission, and there is a desire for optional enhancements, consider this idea: -- `Item`s have age - - Add an `age` attribute to all `Item`s + - Implement a `Vendor` method named `swap_by_newest`, using any logic that seems appropriate - Write unit tests for `swap_by_newest` diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 8f1df1286..dc48bc956 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -2,9 +2,9 @@ from swap_meet.item import Item class Clothing(Item): - def __init__(self, condition=0): + def __init__(self, condition=0, age=0): category = 'Clothing' - super().__init__(category = category, condition=condition) + super().__init__(category = category, condition=condition, age = age) def __str__(self): diff --git a/swap_meet/decor.py b/swap_meet/decor.py index 4a55b69e2..daaf9a180 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,9 +1,9 @@ from swap_meet.item import Item class Decor(Item): - def __init__(self, condition=0): + def __init__(self, condition=0, age=0): category = 'Decor' - super().__init__(category = category, condition=condition) + super().__init__(category = category, condition=condition, age=age) def __str__(self): diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py index 3d5689e1c..31c2b85cb 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,9 +1,9 @@ from swap_meet.item import Item class Electronics(Item): - def __init__(self, condition=0): + def __init__(self, condition=0, age=0): category = 'Electronics' - super().__init__(category = category, condition=condition) + super().__init__(category = category, condition=condition, age=age) def __str__(self): diff --git a/swap_meet/item.py b/swap_meet/item.py index 4cdd94bff..04bcfa21d 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -2,14 +2,14 @@ # from attr import NOTHING class Item: - def __init__(self, category = "", condition=None): + def __init__(self, category = "", condition=None, age = None): if not condition: condition = 0.0 self.condition = condition self.category = category - # if not age: - # age = 0 - # self.age = age + if not age: + age = 0 + self.age = age def __str__ (self): diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index f4f623851..2d9000a44 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -2,6 +2,7 @@ # from operator import invert # from unittest import result # from swap_meet import item +from operator import ne from swap_meet.item import Item class Vendor: @@ -52,7 +53,6 @@ def swap_first_item(self, swapping_other_vendor): def get_best_by_category(self, category): inventory_items_category = self.get_by_category(category) #list - print("inventory>>>", inventory_items_category) if inventory_items_category == []: return None @@ -62,20 +62,29 @@ def get_best_by_category(self, category): highest_item = item return highest_item - def swap_best_by_category(self, other, my_priority, their_priority): - print('inve other>>', other.inventory) - print('self inv>>', self.inventory) - + def swap_best_by_category(self, other, my_priority, their_priority): if self.inventory == [] or other == []: return False my_priority_item = other.get_best_by_category(my_priority) # item - print('my item>>>', my_priority_item) their_priority_item = self.get_best_by_category(their_priority) #item - print('their item>>>',their_priority_item) if my_priority_item in other.inventory and their_priority_item in self.inventory: return self.swap_items(other, their_priority_item, my_priority_item) return False - \ No newline at end of file + + # Optional Enhancements + + def get_newest(self): + pass + if self.item.age == None: + return None + + my_newest_item = min(self.inventory, key=lambda i:i[age]) + return my_newest_item + + + def swap_by_newest(self, age): + pass + \ No newline at end of file From d0ff20efcf11576219602f75d9128bede6178307 Mon Sep 17 00:00:00 2001 From: Alma Date: Fri, 7 Oct 2022 09:57:37 -0700 Subject: [PATCH 10/10] Finally version --- swap_meet/vendor.py | 12 ++++++++++-- tests/unit_tests/newest_test.py | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/unit_tests/newest_test.py diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 2d9000a44..f5eaac9c6 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -6,16 +6,19 @@ from swap_meet.item import Item class Vendor: + """ Object: create a profile with the inventory and some features of each item""" def __init__(self, inventory=None): if not inventory: inventory = [] self.inventory = inventory def add(self, item): + """ Append new items to the current inventory""" self.inventory.append(item) return item def remove(self, item): + """ Remove one item to the current inventory""" if item in self.inventory: self.inventory.remove(item) return item @@ -24,6 +27,7 @@ def remove(self, item): # wave_2 def get_by_category(self, category): + """ Get a list of items with the same category""" items_list = [] for item in self.inventory: if item.category == category: @@ -31,7 +35,8 @@ def get_by_category(self, category): return items_list # wave_3 - def swap_items(self, swapping_other_vendor, my_item, their_item): + def swap_items(self, swapping_other_vendor, my_item, their_item): + """ Swap items, remove items from the original inventory and add it to other person's inventory""" if my_item in self.inventory and their_item in swapping_other_vendor.inventory: self.remove(my_item) swapping_other_vendor.remove(their_item) @@ -43,6 +48,7 @@ def swap_items(self, swapping_other_vendor, my_item, their_item): # Wave_4 def swap_first_item(self, swapping_other_vendor): + """Swap the first item in the inventory""" if self.inventory == [] or swapping_other_vendor.inventory == []: return False @@ -52,6 +58,7 @@ def swap_first_item(self, swapping_other_vendor): # Wave_6 def get_best_by_category(self, category): + """Return the item with the hightest condition per category""" inventory_items_category = self.get_by_category(category) #list if inventory_items_category == []: return None @@ -62,7 +69,8 @@ def get_best_by_category(self, category): highest_item = item return highest_item - def swap_best_by_category(self, other, my_priority, their_priority): + def swap_best_by_category(self, other, my_priority, their_priority): + """Swap the desire category items from the inventories """ if self.inventory == [] or other == []: return False diff --git a/tests/unit_tests/newest_test.py b/tests/unit_tests/newest_test.py new file mode 100644 index 000000000..be641336a --- /dev/null +++ b/tests/unit_tests/newest_test.py @@ -0,0 +1,23 @@ +import pytest +from swap_meet.vendor import Vendor +from swap_meet.clothing import Clothing +from swap_meet.decor import Decor +from swap_meet.electronics import Electronics +from swap_meet.item import Item + +@pytest.mark.skip +def test_get_newest(): + item_a = Item(age=10) + item_b = Item(age=40) + item_c = Item(age=6) + + vendor = Vendor( + inventory=[item_a, item_b, item_c] + ) + + items = vendor.get_newest(vendor) + + assert len(items) == 1 + # assert item_a in items + # assert item_c in items + # assert item_b not in items