Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Cheetahs - June V #97

wants to merge 6 commits into from

Conversation

junemv
Copy link

@junemv junemv commented Oct 7, 2022

No description provided.

Copy link

@jbieniosek jbieniosek left a 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.

Comment on lines +4 to +8
super().__init__( category = "", condition = 0.0, age = 0)
self.category = category
self.condition = condition
self.age = age

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.

Suggested change
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

Suggested change
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"

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!

Comment on lines +23 to +25

return last_inventory_item

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.

Comment on lines +34 to +35
return product

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +62 to +70
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)

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!

Suggested change
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)

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:

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.

Suggested change
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)

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

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:

Suggested change
assert result == False
assert result == False
assert len(vendor.inventory) == 3

Comment on lines +83 to +84
assert tai.inventory == [item_a, item_b, item_f]
assert jesse.inventory == [item_d, item_e, item_c]

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants