-
Notifications
You must be signed in to change notification settings - Fork 110
Carmen Vega - C18 Cheetahs #98
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
922d92e
5668f4b
f14d823
1b0affc
fb1b06a
cf0749f
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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from swap_meet.vendor import Vendor | ||
| from swap_meet.item import Item | ||
|
|
||
| vendor = Vendor() | ||
| print(vendor.inventory) | ||
|
|
||
| # add an item | ||
| item1 = Item(category="Clothing") | ||
| item2 = Item(category="Electronics") | ||
| result1 = vendor.add(item1) | ||
| result2 = vendor.add(item2) | ||
|
|
||
| print(vendor.inventory) | ||
| assert item1 in vendor.inventory | ||
| assert item2 in vendor.inventory | ||
| assert result1 == item1 | ||
| assert result2 == item2 | ||
|
|
||
| # remove an item | ||
| remove_result = vendor.remove(item1) | ||
|
|
||
| assert len(vendor.inventory) == 1 | ||
| assert item1 not in vendor.inventory | ||
| assert remove_result == item1 | ||
|
|
||
| # get item by category, truthy | ||
| items = vendor.get_by_category("Electronics") | ||
|
|
||
| assert len(items) == 1 | ||
| assert item2 in items | ||
|
|
||
| # get item by category, falsy | ||
| items = vendor.get_by_category("Clothing") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| class Clothing: | ||
| pass | ||
| from swap_meet.item import Item | ||
|
|
||
| class Clothing(Item): | ||
| def __init__(self, condition = 0): | ||
| super().__init__(self, condition) | ||
| self.category = "Clothing" | ||
| self.condition = condition | ||
|
|
||
| def __str__(self): | ||
| return f"The finest clothing you could wear." |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| class Decor: | ||
| pass | ||
| from swap_meet.item import Item | ||
|
|
||
| class Decor(Item): | ||
| def __init__(self, condition = 0): | ||
| super().__init__(self, condition) | ||
| self.category = "Decor" | ||
| self.condition = condition | ||
|
|
||
| def __str__(self): | ||
| return f"Something to decorate your space." |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| class Electronics: | ||
| pass | ||
| from swap_meet.item import Item | ||
|
|
||
| class Electronics(Item): | ||
| def __init__(self, condition = 0): | ||
| super().__init__(self, condition) | ||
| self.category = "Electronics" | ||
| self.condition = condition | ||
|
|
||
| def __str__(self): | ||
| return f"A gadget full of buttons and secrets." |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,24 @@ | ||
| class Item: | ||
| pass | ||
| def __init__(self, category = "", condition = 0): | ||
| self.category = category | ||
| self.condition = condition | ||
|
|
||
| def get_by_category(self): | ||
| pass | ||
|
|
||
| def __str__(self): | ||
| return f"Hello World!" | ||
|
|
||
| def condition_description(self): | ||
| if self.condition == 0: | ||
| return "Unusable" | ||
| elif self.condition == 1: | ||
| return "Severely worn" | ||
| elif self.condition == 2: | ||
| return "Just a small hole" | ||
| elif self.condition == 3: | ||
| return "A few scratches" | ||
| elif self.condition == 4: | ||
| return "One light scratch" | ||
| elif self.condition == 5: | ||
| return "Best condition ever" |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,2 +1,76 @@ | ||||||||
| from operator import inv | ||||||||
| from swap_meet.item import Item | ||||||||
|
|
||||||||
| class Vendor: | ||||||||
| pass | ||||||||
| def __init__(self, inventory = None): | ||||||||
| if inventory is None: | ||||||||
| inventory = [] | ||||||||
| self.inventory = inventory | ||||||||
|
|
||||||||
| def add(self, item): | ||||||||
| self.inventory.append(item) | ||||||||
| return item | ||||||||
|
|
||||||||
| def remove(self, item): | ||||||||
| if item not in self.inventory: | ||||||||
| return False | ||||||||
| else: | ||||||||
| self.inventory.remove(item) | ||||||||
| return item | ||||||||
|
Comment on lines
+15
to
+19
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. Great solution! |
||||||||
|
|
||||||||
| def get_by_category(self, category): | ||||||||
| item_list = [] | ||||||||
| for item in self.inventory: | ||||||||
| if item.category == category: | ||||||||
| item_list.append(item) | ||||||||
|
Comment on lines
+23
to
+25
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. 💯 |
||||||||
| return item_list | ||||||||
|
|
||||||||
| def swap_items(self, friend_list, my_item, their_item): | ||||||||
| if my_item in self.inventory: | ||||||||
| if their_item in friend_list.inventory: | ||||||||
|
Comment on lines
+29
to
+30
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. Chained conditionals like this can be combined with
Suggested change
|
||||||||
| friend_list.remove(their_item) | ||||||||
| friend_list.add(my_item) | ||||||||
| self.add(their_item) | ||||||||
| self.remove(my_item) | ||||||||
|
Comment on lines
+31
to
+34
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. Great use of helper methods here! |
||||||||
| return True | ||||||||
| else: | ||||||||
| return False | ||||||||
| else: | ||||||||
| return False | ||||||||
|
|
||||||||
| def swap_first_item(self, friend_list): | ||||||||
| if len(self.inventory) !=0: | ||||||||
| if len(friend_list.inventory) !=0: | ||||||||
|
Comment on lines
+42
to
+43
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.
Suggested change
|
||||||||
| self.swap_items(friend_list,self.inventory[0], friend_list.inventory[0]) | ||||||||
|
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. Great use of a helper method! |
||||||||
| return True | ||||||||
| else: | ||||||||
| return False | ||||||||
| else: | ||||||||
| return False | ||||||||
|
|
||||||||
| def get_best_by_category(self, category): | ||||||||
| best_item = None | ||||||||
| best_condition = -1 | ||||||||
| for item in self.inventory: | ||||||||
| if item.category == category: | ||||||||
| if item.condition > best_condition: | ||||||||
| best_item = item | ||||||||
| best_condition = item.condition | ||||||||
|
|
||||||||
| return best_item | ||||||||
|
|
||||||||
| def swap_best_by_category(self, other, my_priority, their_priority): | ||||||||
| swap_is_happening = False | ||||||||
|
|
||||||||
| their_best_item = other.get_best_by_category(my_priority) | ||||||||
| my_best_item = self.get_best_by_category(their_priority) | ||||||||
|
|
||||||||
| if their_best_item and my_best_item: | ||||||||
| swap_is_happening = True | ||||||||
| self.remove(my_best_item) | ||||||||
| other.remove(their_best_item) | ||||||||
| self.add(their_best_item) | ||||||||
| other.add(my_best_item) | ||||||||
|
|
||||||||
| return swap_is_happening | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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.") | ||||||||
| #raise Exception("Complete this test according to comments below.") | ||||||||
| assert result == False | ||||||||
|
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. I suggest adding a check to verify that the inventory wasn't changed by the remove action:
Suggested change
|
||||||||
| # ********************************************************************* | ||||||||
| # ****** Complete Assert Portion of this test ********** | ||||||||
| # ********************************************************************* | ||||||||
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.
👍