-
Notifications
You must be signed in to change notification settings - Fork 110
Lions- Jessica A. #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
3d23b40
f87c019
71f0ae8
ca5d850
07cd953
5317bcc
7329b06
61efe81
0703704
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,13 @@ | ||
| class Clothing: | ||
| pass | ||
| from swap_meet.item import Item | ||
|
|
||
| class Clothing(Item): | ||
| def __init__(self, condition= 0 ): | ||
| category = "Clothing" | ||
| super().__init__(category = category, condition = condition) | ||
|
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can shorten L5-6 to one line by saying: |
||
|
|
||
| def __str__(self): | ||
| return "The finest clothing you could wear." | ||
|
|
||
|
|
||
|
|
||
|
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 Remove any unnecessary newlines at the end of your files! |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| class Decor: | ||
| pass | ||
| from swap_meet.item import Item | ||
|
|
||
| class Decor(Item): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flawless case of inheritance! Great work! |
||
| def __init__(self, condition = None): | ||
| category = "Decor" | ||
| super().__init__(category = category, condition = condition) | ||
|
|
||
| def __str__(self): | ||
| return "Something to decorate your space." | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,14 @@ | ||
| class Electronics: | ||
| pass | ||
|
|
||
| from swap_meet.item import Item | ||
|
|
||
|
|
||
| class Electronics(Item): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 💯 💯 |
||
| def __init__(self, condition = None): | ||
| category = "Electronics" | ||
| super().__init__(category = category, condition = condition) | ||
|
|
||
| def __str__(self): | ||
| return "A gadget full of buttons and secrets." | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,26 @@ | ||
|
|
||
| class Item: | ||
| pass | ||
| def __init__(self, category = "", condition = None): | ||
| self.category = category | ||
| if condition is None: | ||
| self.condition = 0.0 | ||
| else: | ||
| self.condition = condition | ||
|
|
||
|
|
||
| def __str__(self): | ||
| return "Hello World!" | ||
|
|
||
| def condition_description(self): | ||
| if self.condition == 0: | ||
| return "Bad condition." | ||
| elif self.condition == 1: | ||
| return "Heavly used." | ||
| elif self.condition == 2: | ||
| return "Been used" | ||
| elif self.condition == 3: | ||
| return "Lightly used." | ||
| elif self.condition == 4: | ||
| return "Looks new." | ||
| elif self.condition == 5: | ||
| return "Brand new." | ||
|
Comment on lines
+15
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonderful conditional logic here! ✨ |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,83 @@ | ||
| class Vendor: | ||
| pass | ||
| def __init__(self, inventory = None, condition = None): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, we don't set the parameter |
||
|
|
||
| if inventory == None: | ||
| self.inventory = [] | ||
| else: | ||
| self.inventory = inventory | ||
|
|
||
|
|
||
| def add(self, added_item): | ||
| self.inventory.append(added_item) | ||
| return added_item | ||
|
|
||
| def remove(self, removed_item): | ||
| if removed_item not in self.inventory: | ||
| return False | ||
|
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice validation check from the beginning! ⭐ |
||
| self.inventory.remove(removed_item) | ||
| return removed_item | ||
|
|
||
| def get_by_category(self,category): | ||
| items_in_category = [] | ||
|
|
||
| for item in self.inventory: | ||
| if item.category == category: | ||
| items_in_category.append(item) | ||
|
|
||
| return items_in_category | ||
|
Comment on lines
+21
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beautiful code ⭐ |
||
|
|
||
|
|
||
| def swap_items(self, another_vendor, my_item, their_item): | ||
| if their_item not in another_vendor.inventory or my_item not in self.inventory: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love this chained logic for the validation check! |
||
| return False | ||
| self.remove(my_item) | ||
|
|
||
| another_vendor.remove(their_item) | ||
|
|
||
| another_vendor.add(my_item) | ||
|
|
||
| self.add(their_item) | ||
|
|
||
| return True | ||
|
|
||
| def swap_first_item(self, another_vendor): | ||
| if another_vendor.inventory == [] or self.inventory == []: | ||
| return False | ||
|
|
||
| another_item = another_vendor.inventory[0] | ||
| my_item = self.inventory[0] | ||
|
|
||
| self.swap_items(another_vendor, my_item, another_item) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonderful use of the helper method! |
||
| return True | ||
|
|
||
| def get_best_by_category(self, category = ""): | ||
| best_condition_rating = 0 | ||
| best_condition_item = None | ||
| if self.inventory == []: | ||
| return False | ||
| for item in self.inventory: | ||
| if item.category == category: | ||
| if item.condition > best_condition_rating: | ||
|
Comment on lines
+59
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also combine this into: |
||
| best_condition_rating = item.condition | ||
| best_condition_item = item | ||
| return best_condition_item | ||
|
|
||
|
|
||
| def swap_best_by_category(self, other, my_priority, their_priority): | ||
|
|
||
| my_swap_item = self.get_best_by_category(their_priority) | ||
| other_vendor_swap_item = other.get_best_by_category(my_priority) | ||
|
|
||
|
|
||
| if my_swap_item is not None and other_vendor_swap_item is not None: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also shorten this to the following because the values themselves will evaluate to Truthy: |
||
| return self.swap_items(other, my_swap_item, other_vendor_swap_item) | ||
| return False | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
|
|
@@ -28,21 +28,27 @@ def test_integration_wave_01_02_03(): | |
| assert item1 not in vendor.inventory | ||
| assert remove_result == item1 | ||
|
|
||
| print(f"This is vendor inventory{vendor.inventory}") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember to remove your debugging print statements after you finished using them! 😉 |
||
| # get item by category, truthy | ||
| items = vendor.get_by_category("Electronics") | ||
| print(f"This is vendor inventory{vendor.inventory}") | ||
|
|
||
| assert len(items) == 1 | ||
| assert item2 in items | ||
| print(f"This is vendor inventory{vendor.inventory}") | ||
|
|
||
| # get item by category, falsy | ||
| items = vendor.get_by_category("Clothing") | ||
| print(f"This is vendor inventory{vendor.inventory}") | ||
| assert len(items) == 0 | ||
|
|
||
| other_vendor = Vendor() | ||
|
|
||
| print(f"This is vendor inventory{vendor.inventory}") | ||
| # swap items | ||
| item3 = Item(category="Decor") | ||
| print(f"This is vendor inventory{vendor.inventory}") | ||
| other_vendor.add(item3) | ||
| print(f"This is vendor inventory{vendor.inventory}") | ||
|
|
||
| vendor.swap_items(other_vendor, item2, item3) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,18 +23,20 @@ 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(): | ||
| # Arrange | ||
| item_a = Item(category="clothing") | ||
| item_b = Item(category="clothing") | ||
| item_c = Item(category="clothing") | ||
| vendor = Vendor( | ||
| inventory=[item_a, item_b, item_c] | ||
| ) | ||
|
|
||
| # act | ||
| items = vendor.get_by_category("electronics") | ||
|
|
||
| raise Exception("Complete this test according to comments below.") | ||
| # ********************************************************************* | ||
| # ****** Complete Assert Portion of this test ********** | ||
| # ********************************************************************* | ||
| # Assert | ||
| assert len(items) == 0 | ||
| assert item_a not in items | ||
| assert item_b not in items | ||
| assert item_c not in items | ||
|
Comment on lines
+39
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! ✨ |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to clean up your code before submission with proper spaces (or in this case, no spaces) between the values before and after the
=. Clean code goes a long way and I found this section in the PEP8 style convention really useful!