-
Notifications
You must be signed in to change notification settings - Fork 113
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
Amber Tanaka: Orca Whale #105
base: master
Are you sure you want to change the base?
Conversation
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.
This looks great! Nice logic and nice use of inheritance! This project is definitely green~
def __init__ (self, category=str(), condition = 0): | ||
self.category = "Clothing" | ||
self.condition = condition |
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.
Here and in the other Item subclasses, the category=str()
is not needed. You hardcode the category to "Clothing" on line 5, so the category
that gets passed in as an argument is ignored, and thus unneeded.
Also, consider using super
instead of copying the logic to set the category and condition. Even though it doesn't save you much here, it makes your code easier to extend if you ever add more complex logic to the Item constructor.
return "The finest clothing you could wear." |
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.
Nice override of __str__
!
if self.condition == 0: | ||
return "This would be better served on a pedestal in a museum" | ||
elif self.condition == 1: | ||
return "I mean...It works, mostly" | ||
elif self.condition == 2: | ||
return "This is...acceptable" | ||
elif self.condition == 3: | ||
return "Passable for sure" | ||
elif self.condition == 4: | ||
return "Lightly used, a couple scuffs, but still in good shape!" | ||
elif self.condition == 5: | ||
return "Like new!" |
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.
Nice job defining this in the superclass and letting the subclasses inherit it.
if inventory == None: | ||
self.inventory = [] | ||
else: | ||
self.inventory = inventory |
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.
Good job avoiding a mutable default value! One small nitpick, use is None
when checking whether an object is None.
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
return False |
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.
Really nice job recognizing you don't need an else
here!
their_offer = other.get_best_by_category(my_priority) | ||
my_offer = self.get_best_by_category(their_priority) | ||
if their_offer == None or my_offer == None: | ||
return False | ||
else: | ||
self.swap_items(other, my_offer, their_offer) | ||
return True |
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 logic here!
assert result == False | ||
assert len(vendor.inventory) == 3 | ||
assert item not in vendor.inventory |
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 asserts!
assert len(items) == 0 | ||
assert item_b not in items |
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.
The first assert is great here, but the second one is unneeded. If the length of the items is 0, we can assume that item_b
is not in items
.
assert result is True | ||
assert len(jesse.inventory) == 3 | ||
assert len(tai.inventory) == 3 | ||
assert item_f in tai.inventory | ||
assert item_c in jesse.inventory |
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 asserts!
assert result is False | ||
assert len(jesse.inventory) == 3 | ||
assert len(tai.inventory) == 3 | ||
assert item_d and item_e and item_f in jesse.inventory | ||
assert item_a and item_b and item_c in tai.inventory |
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.
These asserts have the right idea, but there's a subtle bug in them. Take a look at this snippet and see if you can figure out how this same unintuitive behavior could cause problems in your code:
data = [1, 2, 3]
a = 1
b = 99
print(b and a in data)
# Prints True
No description provided.