swap-meet AC2 - Catherine Bandarchuk#3
swap-meet AC2 - Catherine Bandarchuk#3CatherineBandarchuk wants to merge 13 commits intoada-ac2:mainfrom
Conversation
…st_wave_2 passed.
…te swap_items method. Test_wave4
… Class. Test_wave5 passed.
… in Vendor class. Test_wave7 is passed.
…r class. Test_wave7 passed.
kelsey-steven-ada
left a comment
There was a problem hiding this comment.
Great work Kate! I've left a mix of suggestions and questions to consider for feedback. Please reply here on Github or reach out on Slack if there's anything I can clarify =]
|
|
||
|
|
||
| def __str__( self ): | ||
| return f"An object of type {super().get_category()} with id {str(self.id)}. It is made from {str(self.fabric)} fabric." |
There was a problem hiding this comment.
The superclass __str__ function returns f"An object of type {self.get_category()} with id {str(self.id)}". We could use this reduce a little bit of repetition:
base_msg = super().__str__()
return f"{base_msg}. It is made from {str(self.fabric)} fabric." | class Decor( Item ): | ||
|
|
||
| def __init__( self, id = None, condition = None, width = None, length = None ): | ||
| super().__init__(id, condition) |
There was a problem hiding this comment.
I'm noticing that in some places there are spaces around keywords or arguments in parentheses. It isn't common to add spaces between parentheses and what goes inside them, to be consistent across the code, I recommend removing them in the future.
| if fabric == None: | ||
| self.fabric = "Unknown" | ||
| else: | ||
| self.fabric = fabric |
There was a problem hiding this comment.
Another option here could be a python conditional assignment:
# Assigns self.fabric to the parameter fabric if it is truthy,
# otherwise assigns self.fabric the value "Unknown"
self.fabric = fabric if fabric else "Unknown"| super().__init__( id, condition ) | ||
|
|
||
| if fabric == None: | ||
| self.fabric = "Unknown" |
There was a problem hiding this comment.
Strings are an immutable type; unlike lists and dictionaries, we could set the default in the function definition to "Unknown", which could let us remove the if-check.
|
|
||
| def __str__(self): | ||
|
|
||
| return f'''An object of type {super().get_category()} with id {str(self.id)}. It takes up a {str(self.width)} by {str(self.lenght)} sized space.''' No newline at end of file |
There was a problem hiding this comment.
We would want to break this up over a couple lines to meet the best practice of keeping lines under 79 characters. One option could be to close the quotes and use a \ at the end of the line:
return f"An object of type {super().get_category()} with id {str(self.id)}. " \
f"It takes up a {str(self.width)} by {str(self.lenght)} sized space."| if not my_item or not their_item: | ||
| return False | ||
|
|
||
| else: |
There was a problem hiding this comment.
We could remove the else here and unindent return self.swap_items(other_vendor, my_item, their_item) without changing the result of the function.
| if self.swap_by_id( other_vendor, my_item_id, their_item_id ): | ||
| return True | ||
| return False |
There was a problem hiding this comment.
We could remove the if/else by directly returning the result of self.swap_by_id.
| assert item_c in tai.inventory | ||
|
|
||
| assert len(jesse.inventory) == 1 | ||
| assert item_e in jesse.inventory No newline at end of file |
| # ********************************************************************* | ||
| # ****** Complete Assert Portion of this test ********** | ||
| # ********************************************************************* | ||
| assert result == None |
There was a problem hiding this comment.
Nice assert, we definitely want to confirm our return value is None. We generally also want to confirm that there weren't side affects or changes to the input that we didn't intend. What could we check about the vendor's inventory to confirm that its content didn’t change?
There was a problem hiding this comment.
assert len(vendor.inventory) == 3
There was a problem hiding this comment.
Definitely! Since knowing the length doesn't guarantee the individual elements are still what we expect, we might also check the elements of the inventory list.
| # ********************************************************************* | ||
| assert result == False | ||
| assert len(jolie.inventory) == 0 | ||
| assert len(fatimah.inventory) == fatimah_len_l |
There was a problem hiding this comment.
Great assertions, I would also suggest checking the inventory contents, since the length being correct doesn't guarantee that the individual elements are still what we expect.
No description provided.