Skip to content

Amber Tanaka: Orca Whale#105

Open
AmberRose2 wants to merge 8 commits intoada-c17:masterfrom
AmberRose2:master
Open

Amber Tanaka: Orca Whale#105
AmberRose2 wants to merge 8 commits intoada-c17:masterfrom
AmberRose2:master

Conversation

@AmberRose2
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@alope107 alope107 left a comment

Choose a reason for hiding this comment

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

This looks great! Nice logic and nice use of inheritance! This project is definitely green~

Comment thread swap_meet/clothing.py
Comment on lines +3 to +6
class Clothing (Item):
def __init__ (self, category=str(), condition = 0):
self.category = "Clothing"
self.condition = 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.

Here and in the other Item subclasses, the category=str() is not needed. You hardcode the category to "Clothing" on line 5, so the category that gets passed in as an argument is ignored, and thus unneeded.

Also, consider using super instead of copying the logic to set the category and condition. Even though it doesn't save you much here, it makes your code easier to extend if you ever add more complex logic to the Item constructor.

Comment thread swap_meet/clothing.py
Comment on lines +8 to +9
def __str__ (self):
return "The finest clothing you could wear."
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 override of __str__!

Comment thread swap_meet/item.py
Comment on lines +9 to +21
def condition_description(self):
if self.condition == 0:
return "This would be better served on a pedestal in a museum"
elif self.condition == 1:
return "I mean...It works, mostly"
elif self.condition == 2:
return "This is...acceptable"
elif self.condition == 3:
return "Passable for sure"
elif self.condition == 4:
return "Lightly used, a couple scuffs, but still in good shape!"
elif self.condition == 5:
return "Like new!"
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 job defining this in the superclass and letting the subclasses inherit it.

Comment thread swap_meet/vendor.py
Comment on lines +4 to +8
def __init__(self, inventory = None):
if inventory == None:
self.inventory = []
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.

Good job avoiding a mutable default value! One small nitpick, use is None when checking whether an object is None.

Comment thread swap_meet/vendor.py
Comment on lines +14 to +18
def remove(self, item):
if item in self.inventory:
self.inventory.remove(item)
return item
return False
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Really nice job recognizing you don't need an else here!

Comment thread swap_meet/vendor.py
Comment on lines +57 to +64
def swap_best_by_category(self, other, my_priority, their_priority):
their_offer = other.get_best_by_category(my_priority)
my_offer = self.get_best_by_category(their_priority)
if their_offer == None or my_offer == None:
return False
else:
self.swap_items(other, my_offer, their_offer)
return True 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 logic here!

Comment on lines +56 to +58
assert result == False
assert len(vendor.inventory) == 3
assert item not in vendor.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 asserts!

Comment on lines +37 to +38
assert len(items) == 0
assert item_b not in 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.

The first assert is great here, but the second one is unneeded. If the length of the items is 0, we can assume that item_b is not in items.

Comment on lines +79 to +83
assert result is True
assert len(jesse.inventory) == 3
assert len(tai.inventory) == 3
assert item_f in tai.inventory
assert item_c 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 asserts!

Comment on lines +221 to +225
assert result is False
assert len(jesse.inventory) == 3
assert len(tai.inventory) == 3
assert item_d and item_e and item_f in jesse.inventory
assert item_a and item_b and item_c in tai.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.

These asserts have the right idea, but there's a subtle bug in them. Take a look at this snippet and see if you can figure out how this same unintuitive behavior could cause problems in your code:

data = [1, 2, 3]
a = 1
b = 99
print(b and a in data)
# Prints True

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