Sphinx - Sarah Koch, Sunitha Nela#10
Conversation
Co-authored-by: nelasunitha <nelasunitha@users.noreply.github.com>
…. Passes first integration test (Waves 1-3). Co-authored-by: nelasunitha <nelasunitha@users.noreply.github.com>
…ntegratins tests for wave_1_3
…. Creates Clothing, Decor, and Electronics classes. Adds further functionality to Item class. Refactors Item and Vendor classes. Co-authored-by: nelasunitha <nelasunitha@users.noreply.github.com>
yangashley
left a comment
There was a problem hiding this comment.
Nice job on swap-meet, Sarah and Sunitha!
I can see from the commit history that you made frequent commits, which is great!
Let me know if you have any questions about my comments.
| @@ -1,2 +1,11 @@ | |||
| class Clothing: | |||
| pass No newline at end of file | |||
| from swap_meet.item import Item | |||
There was a problem hiding this comment.
Nice work importing Item since we're using by name as the parent class of Clothing 👍
| def __init__(self, id=None, condition=0, fabric="Unknown"): | ||
| super().__init__(id, condition) |
There was a problem hiding this comment.
Nice work on here!
On line 4 you correctly set the default value for fabric to "Unknown"
On line 5 you properly call the initializer of the parent, and pass along the values the child wants to use.
| basic_info = super().__str__() | ||
| detailed_info = f" It is made from {self.fabric} fabric." | ||
| return basic_info + detailed_info No newline at end of file |
There was a problem hiding this comment.
Nice job overriding the super class's __str__ method and invoking super() to reuse some of the logic that has already been written which keeps your code DRY.
You could also do a single line return like:
f"{super().__str__()} It is made from {self.fabric} fabric."| self.condition = condition | ||
|
|
||
| def get_category(self): | ||
| return type(self).__name__ |
There was a problem hiding this comment.
Nice job writing this method in the super class and not repeating the logic in the sub classes 👍
You might also see this written as return self.__class__.__name__
| if self.condition < 0 or self.condition > 5: | ||
| return "I don't know what to do with this." |
There was a problem hiding this comment.
Do we need lines 24-25 if we just return the same string on line 31?
| my_item = self.inventory[0] | ||
| their_item = other_vendor.inventory[0] | ||
|
|
||
| return self.swap_items(other_vendor, my_item, their_item) |
There was a problem hiding this comment.
Good work invoking a function you already wrote to keep your code DRY.
| # ********************************************************************* | ||
| # ****** Complete Assert Portion of this test ********** | ||
| # ********************************************************************* | ||
| assert result is False No newline at end of file |
There was a problem hiding this comment.
Since the general intention of this method is to modify the inventory, we can check that the items that started in the inventory all remain there and also that inventory list is still 3 items long to make this test more robust.
assert len(vendor.inventory) == 3
assert "a" in vendor.inventory
assert "b" in vendor.inventory
assert "c" in vendor.inventory| # ********************************************************************* | ||
| # ****** Complete Assert Portion of this test ********** | ||
| # ********************************************************************* | ||
| assert not result No newline at end of file |
There was a problem hiding this comment.
More than be falsy, swap_items is intended to return an actual boolean. So while we typically write something like
assert not resultin regular python, here we might prefer the more explicit check of
assert result == FalseTo make this test more robust we should also verify that the items in the unchanged inventory are actually the items we started with (and not some other 3 items)
assert item_a in fatimah.inventory
assert item_b in fatimah.inventory
assert item_c in fatimah.inventoryYou could also confirm that inventory didn't change by checking the length of Jolie and Fatimah's inventory lists.
| assert tai.inventory == [item_a, item_b, item_f], f"{tai.inventory}, Expected: [item_a, item_b, item_f]" | ||
| assert jesse.inventory == [item_d, item_e, item_c], f"{jesse.inventory}, Expected: [item_d, item_e, item_c]" |
There was a problem hiding this comment.
These assertions will fail if the order of items in each list somehow change. The README didn't specify that the order of inventory items needed to be maintained, so we probably don't need to constrain our tests and therefore our functions to these requirements. In fact, if you were to implement the swap that I suggested in a comment using multiple assignment, then these tests could fail because the order of elements would be changed.
While more verbose, you can check that elements are in a list like:
assert item_a in tai.inventory
assert item_b in tai.inventory
assert item_f in tai.inventory
assert item_d in jesse.inventory
assert item_e in jesse.inventory
assert item_c in jesse.inventorySame comment applies to the assertions you wrote in the test below.
| def __init__(self, inventory=None): | ||
| self.inventory = [] if inventory is None else inventory | ||
|
|
||
| def add(self, item): | ||
| self.inventory.append(item) | ||
| return item | ||
|
|
||
| def remove(self, item_to_remove): | ||
| if item_to_remove in self.inventory: | ||
| self.inventory.remove(item_to_remove) | ||
| return item_to_remove | ||
| return False | ||
|
|
||
| def get_by_id(self, id_num): | ||
| for item in self.inventory: | ||
| if item.id == id_num: | ||
| return item | ||
| return None |
| if item_to_remove in self.inventory: | ||
| self.inventory.remove(item_to_remove) | ||
| return item_to_remove | ||
| return False |
There was a problem hiding this comment.
This works! However, I'd prefer the logic to be flipped and that the guard clause pattern is used here so you check first for invalid input and then return False.
As the method is currently written, it seems like your main logic is to return False, but the main logic that should be emphasized is that the method removes an item and returns it.
No description provided.