-
Notifications
You must be signed in to change notification settings - Fork 110
Vivian Zhu, C18 Cheetahs #84
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
fb28969
d12e027
e16b3c6
46053e5
a62f97f
06d0348
1210aec
80e197a
7d8f7e5
7e0fff4
91da7f2
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): | ||
|
||
# Wave 5 | ||
def __init__(self, condition = 0.0): | ||
self.category = "Clothing" | ||
self.condition = condition | ||
|
||
def __str__ (self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
|
||
# Wave 5 | ||
def __init__(self, condition = 0.0): | ||
self.category = "Decor" | ||
self.condition = condition | ||
|
||
#super().__init__("Decor", condition, age) | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
|
||
# Wave 5 | ||
def __init__(self, condition = 0.0): | ||
self.category = "Electronics" | ||
self.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,32 @@ | ||
class Item: | ||
pass | ||
|
||
# Wave 2 & 5 | ||
def __init__(self, category = None, condition = 0.0): | ||
# category & condition are the properties of Item | ||
if category is None: | ||
category = "" | ||
Comment on lines
+6
to
+7
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. You do not need to use |
||
self.category = category | ||
self.condition = condition | ||
|
||
|
||
# Wave 3 | ||
def __str__(self): | ||
return "Hello World!" | ||
|
||
|
||
# Wave 5 | ||
def condition_description(self, condition = 0.0): | ||
''' | ||
Describe the condition in words based on the value. | ||
''' | ||
if self.condition <= 1: | ||
return "Uhhh" | ||
elif self.condition <= 2 and self.condition >= 1: | ||
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. Since you use elif, you can make your statements cleaner. For instance, you don't need to use |
||
return "Bad Enough" | ||
elif self.condition <= 3 and self.condition >= 2: | ||
return "So so" | ||
elif self.condition <= 4 and self.condition >= 5: | ||
return "Nice Enough" | ||
elif self.condition <= 5: | ||
return "Sparkling" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,94 @@ | ||
#from swap_meet.item import Item | ||
|
||
class Vendor: | ||
pass | ||
# def __init__(self, inventory = []): | ||
# default value None is IMMUTABLE. MUTABLE type should not be used in DEFAULT argument. | ||
|
||
# Wave 1 | ||
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! |
||
if inventory is None: | ||
inventory = [] | ||
self.inventory = inventory | ||
|
||
def add(self, add_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! |
||
''' | ||
Returns the item that was added | ||
''' | ||
self.inventory.append(add_item) | ||
return add_item | ||
|
||
def remove(self, remove_item): | ||
''' | ||
Returns the item that was removed | ||
''' | ||
if remove_item in self.inventory: | ||
self.inventory.remove(remove_item) | ||
return remove_item | ||
else: | ||
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 else is not necessary! Since the if has a return statement, you know that if the code goes past the if we must be in whatever did not fit in the if. You can just have |
||
return False | ||
|
||
# Wave 2 | ||
def get_by_category(self, category_str): | ||
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! |
||
''' | ||
Returns a list of Strings (items) in the inventory with given category. | ||
''' | ||
same_category_list = [] | ||
for item in self.inventory: | ||
# does not need import at this point | ||
# cause of "dynamic type" does not care about ".category" until it sees Item class | ||
# varies in different languages | ||
if item.category == category_str: | ||
same_category_list.append(item) | ||
return same_category_list | ||
|
||
|
||
# Wave 3 | ||
def swap_items(self, swap_vendor, my_item, their_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! |
||
''' | ||
Returns True if swap items action is successful. | ||
Otherwise, returns False. | ||
''' | ||
if their_item in swap_vendor.inventory and my_item in self.inventory: | ||
# Mistake made; using swap_vendor.inventory | ||
# Class methods must be called on a class objects, not a list | ||
swap_vendor.remove(their_item) | ||
self.add(their_item) | ||
self.remove(my_item) | ||
swap_vendor.add(my_item) | ||
return True | ||
# okay to delete, clear to leave it? | ||
return False | ||
|
||
|
||
# Wave 4 | ||
def swap_first_item(self, swap_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! One thing to note: as you wrote in your docstring, this function should return |
||
''' | ||
Returns True if swap first avaiable item action is successful. | ||
Otherwise, returns False. | ||
''' | ||
if len(self.inventory) >= 1 and len(swap_vendor.inventory) >= 1: | ||
return self.swap_items(swap_vendor, self.inventory[0], swap_vendor.inventory[0]) | ||
|
||
|
||
# Wave 6 | ||
def get_best_by_category(self, given_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! |
||
''' | ||
Returns the item with the best condition in a certain category. | ||
''' | ||
items = self.get_by_category(given_category) | ||
if len(items) > 0: | ||
best_item = max(items, key=lambda i:i.condition) | ||
return best_item | ||
return None | ||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
''' | ||
Returns True if swap the best item (category) action is successful. | ||
Otherwise, returns False. | ||
''' | ||
# watch out for self.func or other.func | ||
my_best_item = self.get_best_by_category(their_priority) | ||
their_best_item = other.get_best_by_category(my_priority) | ||
if my_best_item is not None and their_best_item is not None: | ||
self.swap_items(other, my_best_item, their_best_item) | ||
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,7 @@ def test_removing_not_found_is_false(): | |
|
||
result = vendor.remove(item) | ||
|
||
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
+52
to
+54
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! |
||
|
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,7 @@ def test_get_no_matching_items_by_category(): | |
|
||
items = vendor.get_by_category("electronics") | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
# ********************************************************************* | ||
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
+38
to
+40
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 are actually not needed. Since the first assert tells us that there is nothing in the list, we don't need to check if these individual items are in the list. |
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 start on adding Item as the parent class for Clothing! However, you are not fully using all of the things that parent classes offer. Rather than setting category and condition in the child class, you can send those values to the super class and it can be set there for you. You would use this line of code:
and then you could remove lines 7 and 8. This works for Decor and Electronics as well!