-
Notifications
You must be signed in to change notification settings - Fork 21
Ocelots - Ya-Juan Ruan #15
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
base: main
Are you sure you want to change the base?
Conversation
| class Item: | ||
| pass | ||
| def __init__(self, id=None, condition=0): | ||
| self.id = id if id else uuid.uuid4().int |
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 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 = { |
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 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: |
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.
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, |
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 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): |
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 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)) |
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.
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(): |
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 extra testing!
No description provided.