Skip to content

Sea Turtles - Olive - swap meet#107

Open
olive-lavine wants to merge 20 commits intoada-c17:masterfrom
olive-lavine:master
Open

Sea Turtles - Olive - swap meet#107
olive-lavine wants to merge 20 commits intoada-c17:masterfrom
olive-lavine:master

Conversation

@olive-lavine
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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 thread swap_meet/item.py
Comment on lines +10 to +12
def condition_description(self):
descriptions = ["no comment", "eh", "okay", "good", "great"," perfect, mwah"]
return descriptions[int(self.condition)]
Copy link
Copy Markdown

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)]

Comment thread swap_meet/electronics.py
pass
from swap_meet.item import Item

class Electronics(Item):
Copy link
Copy Markdown

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 thread swap_meet/vendor.py
Comment on lines +4 to +5
inventory = inventory if inventory is not None else []
self.inventory = inventory
Copy link
Copy Markdown

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 thread swap_meet/vendor.py
Comment on lines +18 to +21
items_by_category = []
for item in self.inventory:
if item.category == category:
items_by_category.append(item)
Copy link
Copy Markdown

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!

Comment thread swap_meet/vendor.py
return items_by_category

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

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!

Comment thread swap_meet/vendor.py
return best_item


def swap_best_by_category(self, other, my_priority, their_priority):
Copy link
Copy Markdown

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 No newline at end of file
Copy link
Copy Markdown

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 == []
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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