-
Notifications
You must be signed in to change notification settings - Fork 110
Cheetahs - Wanjun Lan #79
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
bc715a3
a3d9988
7faccdd
bc5cfe6
08848fc
33c58d9
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,9 @@ | ||
| class Clothing: | ||
| pass | ||
| from .item import Item | ||
|
|
||
| class Clothing(Item): | ||
| def __init__(self, condition = 0, age = 0): | ||
| super().__init__(category = "Clothing", condition = condition, age = age) | ||
|
|
||
|
|
||
| def __str__(self): | ||
| return "The finest clothing you could wear." | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| class Decor: | ||
| pass | ||
| from .item import Item | ||
|
|
||
| class Decor(Item): | ||
| def __init__(self, condition = 0, age = 0): | ||
| super().__init__(category = "Decor", condition = condition, age = age) | ||
|
|
||
| def __str__(self): | ||
| return "Something to decorate your space." | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,10 @@ | ||
| class Electronics: | ||
| pass | ||
| from .item import Item | ||
|
|
||
| class Electronics(Item): | ||
| def __init__(self, condition = 0, age = 0): | ||
| super().__init__(category = "Electronics", condition = condition, age = age) | ||
|
|
||
| def __str__(self): | ||
| return "A gadget full of buttons and secrets." | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,31 @@ | ||
| class Item: | ||
| pass | ||
|
|
||
| def __init__(self, category = "", condition = 0, age = 0): | ||
| self.category = category | ||
| self.condition = condition | ||
| self.age = age | ||
|
|
||
|
|
||
| def __str__(self): | ||
| return "Hello World!" | ||
|
|
||
| def condition_description(self): | ||
| if self.condition == 0: | ||
| return "mint" | ||
| elif self.condition <= 1.0: | ||
| return "brand new" | ||
| elif self.condition <= 2.0: | ||
| return "almost new" | ||
| elif self.condition <= 3.0: | ||
| return "used" | ||
| elif self.condition <= 4.0: | ||
| return "heavily used" | ||
| elif self.condition <= 5.0: | ||
| return "You probably want a glove for this one..." | ||
|
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 work! |
||
|
|
||
| # return str(self.condition) with 100% code coverage | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,99 @@ | ||
| from swap_meet.item import Item | ||
|
|
||
| class Vendor: | ||
| pass | ||
| def __init__(self, inventory = None): | ||
| if inventory: | ||
| self.inventory = inventory | ||
| else: | ||
| self.inventory = [] | ||
|
|
||
| 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 | ||
|
Comment on lines
+15
to
+17
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 False | ||
|
|
||
| def get_by_category(self, category): | ||
| result = [] | ||
| for item in self.inventory: | ||
| if item.category == category: | ||
| result.append(item) | ||
|
Comment on lines
+22
to
+24
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! |
||
| return result | ||
|
|
||
| def swap_items(self, other, my_item, their_item): | ||
| if my_item not in self.inventory or their_item not in other.inventory: | ||
| return False | ||
|
|
||
| self.remove(my_item) | ||
| other.add(my_item) | ||
| other.remove(their_item) | ||
| self.add(their_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. Good use of helper methods! |
||
| return True | ||
|
|
||
| def swap_first_item(self, other): | ||
| if not self.inventory or not other.inventory: | ||
| return False | ||
|
|
||
| self_first = self.inventory.pop(0) | ||
| another_first = other.inventory.pop(0) | ||
| self.inventory.append(another_first) | ||
| other.inventory.append(self_first) | ||
|
Comment on lines
+41
to
+44
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. Could you use |
||
| return True | ||
|
|
||
| def get_best_by_category(self, category): | ||
| # if not self.inventory: | ||
| # return None | ||
| best_item = None | ||
| highest_condition = 0 | ||
|
|
||
| for item in self.inventory: | ||
| if item.category == category: | ||
| if item.condition > highest_condition: | ||
| highest_condition = item.condition | ||
| best_item = item | ||
|
|
||
| return best_item | ||
|
|
||
|
|
||
| def swap_best_by_category(self, other, my_priority, their_priority): | ||
| my_best = self.get_best_by_category(their_priority) | ||
| their_best = other.get_best_by_category(my_priority) | ||
| if not my_best or not their_best: | ||
| return False | ||
|
|
||
| self.swap_items(other, my_best, their_best) | ||
|
Comment on lines
+63
to
+68
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. Fantastic use of helper methods! |
||
| return True | ||
|
|
||
|
|
||
| def swap_by_newest(self, other): | ||
| if not self.inventory or not other.inventory: | ||
| return False | ||
| my_newest_aged_item = min(self.inventory, key=lambda item: item.age) | ||
| their_newest_aged_item = min(other.inventory, key=lambda item: item.age) | ||
| self.swap_items(other, my_newest_aged_item, their_newest_aged_item) | ||
|
Comment on lines
+75
to
+77
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. 🎉 Fantastic, great use of lambda! |
||
| return True | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| 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,10 @@ 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.") | ||
| # ********************************************************************* | ||
| # ****** Complete Assert Portion of this test ********** | ||
| # ********************************************************************* | ||
| assert len(vendor.inventory) == 3 | ||
| assert item not in vendor.inventory | ||
| assert result == False | ||
|
Comment on lines
+56
to
+58
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. 👍 |
||
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.
👍