Skip to content

Conversation

@ryjpink
Copy link

@ryjpink ryjpink commented Dec 9, 2022

No description provided.

class Item:
pass
def __init__(self, id=None, condition=0):
self.id = id if id else uuid.uuid4().int

Choose a reason for hiding this comment

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

nice use of ternary operator

def condition_description(self) :
# Make sure condition is a integer between zero and five
condition = max(0, min(5, math.floor(self.condition)))
description_dict = {

Choose a reason for hiding this comment

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

great use of a dict here. And if/else block would take O(n) worse case to fall through to the last condition!

Plus, nice formatting of the contents of the dict here

cur_best_condition = None
for item in self.inventory:
if item.get_category() == category:
if cur_best_item is None or item.condition > cur_best_condition:

Choose a reason for hiding this comment

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

Okay, this is clean code that only loops through the whole thing once. In a more complex project, you can probably see how we could use things like filter to pull specific sets out of the inventory. Well done, though!

def display_inventory(self, category=""):
# When there is no assigned category, it should display all inventory
assigned_category_inventory = list(filter(
lambda item: item.get_category() == category if category else True,
Copy link

@ilana-adadev ilana-adadev Dec 23, 2022

Choose a reason for hiding this comment

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

nice use of a lambda. with a ternary operator, too!


return self.swap_by_id(other_vendor, my_item_id, their_item_id)

def swap_similar_items(self, other_vendor, my_item):
Copy link

@ilana-adadev ilana-adadev Dec 23, 2022

Choose a reason for hiding this comment

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

Nice use of OOP-based similarity enhancement!

def swap_similar_items(self, other_vendor, my_item):
their_inventory = other_vendor.get_by_category(my_item.get_category())

final_candidates = list(filter(lambda item: my_item.is_similar(item), their_inventory))

Choose a reason for hiding this comment

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

Ah, and there's filter. Good use of it here!


assert one_condition_description != five_condition_description

def test_item_condition_higher_than_five_return_five():

Choose a reason for hiding this comment

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

Nice extra testing!

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