Conversation
jbieniosek
left a comment
There was a problem hiding this comment.
Fantastic work on this project Nikki! I am a big fan of the unit tests for the age feature. The code is very clean and readable. Great use of helper methods inside of Vendor. This project is green.
| self.category = "Clothing" | ||
| self.condition = condition | ||
| self.age = age |
There was a problem hiding this comment.
This will work, but it's duplicating code that is already in Item. Using the super constructor allows this function to take advantage of all of the code in Item:
| self.category = "Clothing" | |
| self.condition = condition | |
| self.age = age | |
| super().__init__("Clothing", condition, age) |
| return "Good condition" | ||
|
|
||
| if self.condition == 5: | ||
| return "Mint conditon" |
There was a problem hiding this comment.
The condition can be a float, so it can contain a decimal. In the cases where the condition has a decimal, this function will return None. There are a few solutions, one is to cast the condition to an int, which will drop the decimal portion of the number and round down. Another possible solution is to test for a range of values (ex: if self.condition <= 5 and self.condition > 4.
| self.remove(my_item) | ||
| other_vendor.add(my_item) | ||
|
|
||
| other_vendor.remove(their_item) | ||
| self.add(their_item) |
| if len(self.inventory) == 0 or len(other_vendor.inventory) == 0: | ||
| return False | ||
|
|
||
| self.swap_items(other_vendor, self.inventory[0], other_vendor.inventory[0]) |
| if (item.condition) > (highest_rated.condition): | ||
| highest_rated = item | ||
|
|
||
| return highest_rated |
| their_newest = other.inventory[0] | ||
| for item in other.inventory: | ||
| if not item.age is None: | ||
| their_newest = item | ||
| break | ||
| if their_newest.age is None: | ||
| return False | ||
|
|
||
| for item in other.inventory: | ||
| if not item.age is None: | ||
| if item.age < their_newest.age: | ||
| their_newest = item |
There was a problem hiding this comment.
This section is the same as lines 106-117. I recommend pulling this out into a helper method.
| if item.age < their_newest.age: | ||
| their_newest = item | ||
|
|
||
| self.swap_items(other, my_newest, their_newest) |
| # ********************************************************************* | ||
| assert item_a not in items | ||
| assert item_b not in items | ||
| assert item_c not in items No newline at end of file |
There was a problem hiding this comment.
Tests work better when there is no room for ambiguity. In this case, checking that these items are not in the list of items is great, but it leaves room for there to be some other item that is also not wanted. Adding something like:
assert len(items) == 0
helps to make it clear that the items list should be empty.
| assert item_f in tai.inventory | ||
| assert item_c in jesse.inventory | ||
| assert item_d in jesse.inventory | ||
| assert item_e in jesse.inventory |
|
|
||
| # tests for swap_by_newest | ||
|
|
||
| def test_swap_newest(): |
No description provided.