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

Sea Turtles - Olive - swap meet #107

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

Conversation

olive-lavine
Copy link

No description provided.

Copy link

@kelsey-steven-ada kelsey-steven-ada left a comment

Choose a reason for hiding this comment

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

🎉 You completed Unit 1! 🎉 Great work on this project, I've left some suggestions for refactoring. Take a look, and let me know if anything needs clarification!

Comment on lines +10 to +12
descriptions = ["no comment", "eh", "okay", "good", "great"," perfect, mwah"]
return descriptions[int(self.condition)]

Choose a reason for hiding this comment

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

Love this as a succinct solution that works for decimals as well as integers! I'd consider formatting the list a little differently to make it a bit easier to read, even through it take more lines:

Suggested change
def condition_description(self):
descriptions = ["no comment", "eh", "okay", "good", "great"," perfect, mwah"]
return descriptions[int(self.condition)]
def condition_description(self):
descriptions = [
"no comment",
"eh",
"okay",
"good",
"great",
"perfect, mwah"
]
return descriptions[int(self.condition)]

pass
from swap_meet.item import Item

class Electronics(Item):

Choose a reason for hiding this comment

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

The subclasses look great!

Comment on lines +4 to +5
self.inventory = inventory

Choose a reason for hiding this comment

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

Nice handling of the None default value using a Ternary operator! I generally stay away from overwriting the data we get from our parameters in case we ever need that info back. In this case there's no harm, but if we wanted to avoid overwriting the inventory parameter we could use the ternary expression to directly assign self.inventory's value:

Suggested change
inventory = inventory if inventory is not None else []
self.inventory = inventory
self.inventory = inventory if inventory is not None else []

Comment on lines +18 to +21
for item in self.inventory:
if item.category == category:
items_by_category.append(item)

Choose a reason for hiding this comment

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

Notice this pattern of:

result_list = []
for element in source_list:
    if some_condition(element):
        result_list.append(element)

can be rewritten using a list comprehension as:

result_list = [element for element in source_list if some_condition(element)]

Which here would look like:

items_by_category = [item for item in self.inventory if item.category == category]

At first, this may seem more difficult to read, but comprehensions are a very common python style, so try getting used to working with them!


def swap_items(self, other, my_item, their_item):
if my_item not in self.inventory or their_item not in other.inventory:

Choose a reason for hiding this comment

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

I like this check for valid data, very succinct and easy to read!



def swap_best_by_category(self, other, my_priority, their_priority):

Choose a reason for hiding this comment

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

Great approach to this function!

Comment on lines +53 to +54
assert len(vendor.inventory) == 3
assert result == False

Choose a reason for hiding this comment

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

Great consideration to check the inventory's length hasn't changed. We could also confirm there were no side affects that altered the individual contents of the inventory with :

assert all(item in vendor.inventory for item in ["a", "b", "c"])

or by individually checking values:

assert "a" in vendor.inventory
assert "b" in vendor.inventory
assert "c" in vendor.inventory

Comment on lines +38 to +39
assert len(items) == 0
assert items == []

Choose a reason for hiding this comment

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

I would say both of these asserts check the same thing (whether items is empty). Since we want to know that it is a list and it is empty, we could just keep the second check assert items == [].

Aside from confirming the list is empty, what could we assert to make sure the vendor's inventory was not changed?

Comment on lines +81 to +84
assert item_f in tai.inventory
assert item_c in jesse.inventory
assert item_c not in tai.inventory
assert item_f not in jesse.inventory

Choose a reason for hiding this comment

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

It's great that the asserts check on the items that were swapped, but we should add asserts about the other items in the lists too, to make sure there were no unexpected side affects.

assert item_c in tai.inventory
assert item_d in jesse.inventory
assert item_e in jesse.inventory
assert item_f in jesse.inventory

Choose a reason for hiding this comment

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

Great checks for all relevant data!

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