Panthers_A18 - Lee Reyes and Sika Sarpong#85
Panthers_A18 - Lee Reyes and Sika Sarpong#85sikasarpong wants to merge 16 commits intoAda-C18:masterfrom
Conversation
… method to overide string
audreyandoy
left a comment
There was a problem hiding this comment.
Lee and Sika!
Your submission completed all waves and passed all required tests. Your code was easy to read and utilized a lot of helper functions which made your code very neat!
My main feedback primarily focuses on using the parent constructor and ways to refactor.
Overall, this project is well-deserving of a 🟢 green 🟢 ✨
Keep up the great work 🐈⬛ ✨
| class Clothing(Item): | ||
| def __init__(self, category="Clothing", condition=0, age=0): | ||
| super().__init__(category, condition, age) | ||
|
|
||
| def __str__(self): | ||
| return "The finest clothing you could wear." | ||
|
|
There was a problem hiding this comment.
Setting a default value will still allow us to reassign the value. In this case, every Clothing instance can change its category to 'Electronics':
pants = Clothing('Electronics', 4.0)
print(pants.category) # returns 'Electronics'
#what are electronic pants? lolWe can move the default assignment of category to the parent super() constructor. This will ensure that every Clothing instance will be assigned 'Clothing' as its category.
pants = Clothing(4.0)
print(pants.category) # returns clothing| class Decor(Item): | ||
| def __init__(self, category="Decor", condition=0, age=0): | ||
| super().__init__(category, condition, age) | ||
|
|
||
| def __str__(self): | ||
| return "Something to decorate your space." |
There was a problem hiding this comment.
Same comment about category in the child class constructor can also be applied here.
| class Electronics(Item): | ||
| def __init__(self, category="Electronics", condition=0, age=0): | ||
| super().__init__(category, condition, age) | ||
|
|
||
| def __str__(self): | ||
| return "A gadget full of buttons and secrets." |
There was a problem hiding this comment.
Same comment about category in the child class constructor can also be applied here.
| def condition_description(self): | ||
| if self.condition == 0: | ||
| return "Ew. You don't want that." | ||
| elif self.condition == 1: | ||
| return "Maybe you need gloves for that." | ||
| elif self.condition == 2: | ||
| return "Heavily Used" | ||
| elif self.condition == 3: | ||
| return "Decent" | ||
| elif self.condition == 4: | ||
| return "Lightly Used" | ||
| elif self.condition == 5: | ||
| return "Like new!" |
There was a problem hiding this comment.
🤣 lol Love the condition descriptions. "maybe you need gloves for that" is my fav.
| class Vendor: | ||
| pass No newline at end of file | ||
| def __init__(self, inventory=None) -> None: | ||
| self.inventory = inventory if inventory is not None else [] |
There was a problem hiding this comment.
👍 Great work in handling default parameters for mutable types. It's unsafe to set [] as the default value, but we can use None to stand in for the value when not supplied by the caller, and then use a new empty list in its place.
| assert result | ||
| assert len(tai.inventory) == 3 | ||
| assert len(jesse.inventory) == 3 | ||
| assert item_a and item_b and item_f in tai.inventory | ||
| assert item_c and item_d and item_e in jesse.inventory |
| assert result | ||
| assert len(tai.inventory) == 3 | ||
| assert len(jesse.inventory) == 3 | ||
| assert item_a and item_b and item_f in tai.inventory | ||
| assert item_c and item_d and item_e in jesse.inventory | ||
| assert item_c not in tai.inventory | ||
| assert item_f not in jesse.inventory |
| assert not result | ||
| assert len(tai.inventory) == 3 | ||
| assert len(jesse.inventory) == 3 | ||
| assert item_a in tai.inventory | ||
| assert item_b in tai.inventory | ||
| assert item_c in tai.inventory | ||
| assert item_d in jesse.inventory | ||
| assert item_e in jesse.inventory | ||
| assert item_f in jesse.inventory |
| assert not result | ||
| assert len(tai.inventory) == 3 | ||
| assert len(jesse.inventory) == 3 | ||
| assert item_a in tai.inventory | ||
| assert item_b in tai.inventory | ||
| assert item_c in tai.inventory | ||
| assert item_d in jesse.inventory | ||
| assert item_e in jesse.inventory | ||
| assert item_f in jesse.inventory |
| def test_swap_by_newest(): | ||
| # Arrange: | ||
| item_a = Decor(age=3) | ||
| item_b = Electronics(age=4) | ||
| item_c = Decor(age=5) | ||
| tai = Vendor( | ||
| inventory=[item_a, item_b, item_c] | ||
| ) | ||
|
|
||
| item_d = Clothing(age=2) | ||
| item_e = Decor(age=4) | ||
| item_f = Clothing(age=4) | ||
| jesse = Vendor( | ||
| inventory=[item_f, item_e, item_d] | ||
| ) | ||
| # Act | ||
| result = tai.swap_by_newest(other=jesse, my_priority="Clothing", | ||
| their_priority="Decor") | ||
| # Assert | ||
| assert result is None |
No description provided.