-
Notifications
You must be signed in to change notification settings - Fork 110
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
Cheetahs - June V #97
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.
Great work on this project June! The code is very clean and easy to read. I do want to flag references and items in memory as an area that might be useful for you to review, and maybe for us to chat about in our next 1:1. This project is green.
super().__init__( category = "", condition = 0.0, age = 0) | ||
self.category = category | ||
self.condition = condition | ||
self.age = age |
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 setup makes it possible to pass in a value for category that is not "Clothing", which could result in an instance of Clothing
that has some other category. Right now the values being passed to the __init__
function of the parent class are default values, so lines 6-8 are necessary to initialize this instance with the values that are being passed in to the constructor. However, changing the values that are being passed into the super constructor makes it possible to use the code in the parent class, and then lines 6-8 will no longer be necessary.
def __init__(self, category = "Clothing", condition = 0.0, age = 0): | |
super().__init__( category = "", condition = 0.0, age = 0) | |
self.category = category | |
self.condition = condition | |
self.age = age | |
def __init__(self, condition = 0.0, age = 0): | |
super().__init__( category = "Clothing", condition = condition, age = age) |
or
def __init__(self, category = "Clothing", condition = 0.0, age = 0): | |
super().__init__( category = "", condition = 0.0, age = 0) | |
self.category = category | |
self.condition = condition | |
self.age = age | |
def __init__(self, condition = 0.0, age = 0): | |
super().__init__( "Clothing", condition, age) |
return "mint" | ||
elif math.floor(self.condition) == 5: | ||
return "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.
Neat use of math.floor!
|
||
return last_inventory_item |
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 last_inventory_item
code works, but it's doing some extra work. It is possible to just return item
here.
return product |
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.
👍
if item == my_item: | ||
other_vendor.add(item) | ||
self.remove(item) | ||
|
||
for item in other_inventory: | ||
if item == their_item: | ||
self.add(item) | ||
other_vendor.remove(item) |
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 loops are not necessary here. The check on line 59 has already verified that my_item
is in self_inventory
and their_item
is in other_inventory
. The reference to the item in the list will be the same as any other reference to the item, so we do not have to find the item in the list in order to work with it. When we have an object in memory, all of the variables that are pointing to that object have the same value (ie, the reference to that object), and can be used for comparison purposes interchangably. Fantastic use of helper methods, though!
for item in self_inventory: | |
if item == my_item: | |
other_vendor.add(item) | |
self.remove(item) | |
for item in other_inventory: | |
if item == their_item: | |
self.add(item) | |
other_vendor.remove(item) | |
other_vendor.add(my_item) | |
self.remove(my_item) | |
self.add(their_item) | |
other_vendor.remove(their_item) |
return None | ||
|
||
return max(result, key = lambda c: c.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.
Nice! Snazzy use of lambda!
their_best_category = other.get_best_by_category(my_priority) | ||
|
||
if len(self.inventory) == 0 or len(other.inventory) == 0 or my_best_category is None or their_best_category is None: |
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 conditional only needs to check if the best_category
items are not None, because the length of the inventory doesn't tell us anything about the number of items they have in that category.
if len(self.inventory) == 0 or len(other.inventory) == 0 or my_best_category is None or their_best_category is None: | |
if my_best_category is None or their_best_category is None: |
# Helpers | ||
my_best_category = self.get_best_by_category(their_priority) | ||
their_best_category = other.get_best_by_category(my_priority) |
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.
🎉
@@ -49,7 +49,9 @@ 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 comment
The 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:
assert result == False | |
assert result == False | |
assert len(vendor.inventory) == 3 |
assert tai.inventory == [item_a, item_b, item_f] | ||
assert jesse.inventory == [item_d, item_e, item_c] |
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 works, but it requires that the implementation of swap_best_by_category
doesn't make changes to the order of the items, and also that the new items are added at the end of the lists. It's longer to write out, but I would suggest using a series of assert item in [person].inventory
statements.
No description provided.