-
Notifications
You must be signed in to change notification settings - Fork 110
Miranda - Lion #83
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?
Miranda - Lion #83
Changes from all commits
4f1ff10
1cc6d02
68a99e8
6287b12
685c915
201d940
ccbf56c
907762f
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,11 @@ | ||
| class Clothing: | ||
| pass | ||
| from swap_meet.item import Item | ||
|
|
||
| class Clothing(Item): | ||
| def __init__(self, category = "Clothing", condition = 0): | ||
| super().__init__(category, condition) | ||
| # self.category = "Clothing" | ||
|
|
||
| def __str__(self): | ||
| return "The finest clothing you could wear." | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,11 @@ | ||
| 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. Great job! |
||
| def __init__(self, category = "Decor", condition = 0): | ||
| super().__init__(category, condition) | ||
| # self.category = "Decor" | ||
|
|
||
| def __str__(self): | ||
| return "Something to decorate your space." | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| 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. Great job! |
||
| def __init__(self, category = "Electronics", condition = 0): | ||
| super().__init__(category, condition) | ||
| # self.category = "Electronics" | ||
|
|
||
| def __str__(self): | ||
| return "A gadget full of buttons and secrets." | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,35 @@ | ||
| # from attr import validate | ||
|
|
||
| class Item: | ||
| pass | ||
| def __init__(self, category = None, condition = 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. The default for category can be |
||
| # category is an empty string | ||
| if category is None: | ||
| category = "" | ||
| self.category = category | ||
| self.condition = condition | ||
|
|
||
| def __str__(self): | ||
| return "Hello World!" | ||
|
|
||
| def condition_description(self): | ||
|
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. It looks like you were changing some of the conditions in the if statements, but didn't finish. The logic has some gaps in it. Good start though! |
||
| if self.condition > 0 and self.condition < 2: | ||
| return "1 star" | ||
| elif self.condition > 1 and self.condition < 3: | ||
| return "2 stars" | ||
| elif self.condition > 2 and self.condition < 3: | ||
| return "3 stars" | ||
| elif self.condition > 4 and self.condition < 5: | ||
| return "4 stars" | ||
| elif self.condition == 5: | ||
| return "5 stars" | ||
| else: | ||
| return "Invalid number" | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,101 @@ | ||
| # from xmlrpc.client import INVALID_ENCODING_CHAR | ||
|
|
||
| # from attr import s | ||
|
|
||
| class Vendor: | ||
| pass | ||
| def __init__(self, inventory = 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. Excellent! |
||
| # inventory is a empty list | ||
| if inventory is None: | ||
| inventory = [] | ||
| self.inventory = inventory | ||
|
|
||
| def add(self, 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. Excellent! |
||
| self.inventory.append(item) | ||
| return item | ||
|
|
||
| def remove(self, 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. Excellent! |
||
| if item not in self.inventory: | ||
| return False | ||
| self.inventory.remove(item) | ||
| return item | ||
|
|
||
|
|
||
|
|
||
| def get_by_category(self, str_category): | ||
|
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. Excellent! One small note, the elements in |
||
| category_list = [] | ||
| for string in self.inventory: | ||
| if string.category == str_category: | ||
| category_list.append(string) | ||
| return category_list | ||
|
|
||
|
|
||
|
|
||
| def swap_items(self, another_vendor, my_item, their_item): | ||
| if my_item not in self.inventory or\ | ||
| their_item not in another_vendor.inventory: | ||
| # another_vendor.inventory --> (parameter_name.attribute_name) | ||
| return False | ||
|
|
||
| another_vendor.inventory.append(self.remove(my_item)) | ||
| another_vendor.inventory.remove(their_item) | ||
| self.inventory.append(their_item) | ||
|
Comment on lines
+39
to
+41
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. This would have been a good place to use the |
||
|
|
||
| # self.inventory.remove(my_item) | ||
| # another_vendor.inventory.append(my_item) | ||
| # another_vendor.inventory.remove(their_item) | ||
| # self.inventory.append(their_item) | ||
| return True | ||
|
|
||
|
|
||
| def swap_first_item(self, another_vendor): | ||
|
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 job! |
||
| if self.inventory == [] or another_vendor.inventory == []: | ||
| return False | ||
|
|
||
| my_item = self.inventory[0] | ||
| their_item = another_vendor.inventory[0] | ||
| self.inventory.remove(my_item) | ||
| self.inventory.append(their_item) | ||
| another_vendor.inventory.remove(their_item) | ||
| another_vendor.inventory.append(my_item) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| def get_best_by_category(self, str_category): | ||
|
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. Excellent! |
||
| category_list = self.get_by_category(str_category) | ||
| # call the get_by_category funtion and assign to a variable | ||
| if len(category_list) == 0: | ||
| return None | ||
| best_condition = category_list[0] | ||
| for item in category_list: | ||
| if item.condition > best_condition.condition: | ||
| best_condition = item | ||
| # will only get the first one that appear with the best condition | ||
| return best_condition | ||
|
|
||
|
|
||
| def swap_best_by_category(self, other, my_priority, their_priority): | ||
|
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. Excellent! |
||
| # other, which represents another Vendor instance to trade with | ||
| # my_priority, which represents a category that the Vendor wants to receive | ||
| # their_priority, which represents a category that other wants to receive | ||
| 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 | ||
| return self.swap_items(other, my_best, their_best) | ||
| # return True | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| 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 | ||
|
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. Please do not remove this! Pytest needs to know that this is an integration test. Please only remove the skip one above. |
||
| def test_integration_wave_01_02_03(): | ||
| # make a vendor | ||
| vendor = Vendor() | ||
|
|
||
| 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,16 +40,20 @@ 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( | ||
| inventory=["a", "b", "c"] | ||
| ) | ||
|
|
||
| result = vendor.remove(item) | ||
| assert len(vendor.inventory) == 3 | ||
| assert item not in vendor.inventory | ||
| assert result == False | ||
|
Comment on lines
+51
to
+53
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. Excellent asserts! |
||
| # raise Exception("Complete this test according to comments below.") | ||
|
|
||
|
|
||
| raise Exception("Complete this test according to comments below.") | ||
| # ********************************************************************* | ||
| # ****** Complete Assert Portion of this test ********** | ||
| # ********************************************************************* | ||
| 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,7 +23,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,7 +34,12 @@ 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 | ||
| assert item_a not in items | ||
| assert item_c not in items | ||
| assert item_b not in items | ||
|
Comment on lines
+39
to
+41
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 asserts! These three aren't necessary since the first one tells us there's nothing in the list. We don't need to check each individual item. |
||
|
|
||
| # ********************************************************************* | ||
| # ****** 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.
Great job! We actually don't want to have
categoryin the__init__function. Since Clothing objects should always have "Clothing" as the category we do not want to let the user to put in their own information. On line 5 instead ofcategoryyou can put"Clothing"to pass to the super class.