Skip to content

Sphinx - Sarah Koch, Sunitha Nela#10

Open
sarah-koch wants to merge 9 commits into
Ada-C22:mainfrom
nelasunitha:main
Open

Sphinx - Sarah Koch, Sunitha Nela#10
sarah-koch wants to merge 9 commits into
Ada-C22:mainfrom
nelasunitha:main

Conversation

@sarah-koch

Copy link
Copy Markdown

No description provided.

nelasunitha and others added 9 commits September 30, 2024 11:33
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>
…. 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 yangashley left a comment

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 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.

Comment thread swap_meet/clothing.py
@@ -1,2 +1,11 @@
class Clothing:
pass No newline at end of file
from swap_meet.item import Item

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 work importing Item since we're using by name as the parent class of Clothing 👍

Comment thread swap_meet/clothing.py
Comment on lines +4 to +5
def __init__(self, id=None, condition=0, fabric="Unknown"):
super().__init__(id, 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.

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.

Comment thread swap_meet/clothing.py
Comment on lines +9 to +11
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

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 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."

Comment thread swap_meet/item.py
self.condition = condition

def get_category(self):
return type(self).__name__

@yangashley yangashley Oct 7, 2024

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 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__

Comment thread swap_meet/item.py
Comment on lines +24 to +25
if self.condition < 0 or self.condition > 5:
return "I don't know what to do with this."

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we need lines 24-25 if we just return the same string on line 31?

Comment thread swap_meet/vendor.py
my_item = self.inventory[0]
their_item = other_vendor.inventory[0]

return self.swap_items(other_vendor, my_item, their_item)

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 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

More than be falsy, swap_items is intended to return an actual boolean. So while we typically write something like

    assert not result

in regular python, here we might prefer the more explicit check of

    assert result == False

To 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.inventory

You could also confirm that inventory didn't change by checking the length of Jolie and Fatimah's inventory lists.

Comment on lines +126 to +127
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]"

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 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.inventory

Same comment applies to the assertions you wrote in the test below.

Comment thread swap_meet/vendor.py
Comment on lines +4 to +21
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 LGTM!

Comment thread swap_meet/vendor.py
Comment on lines +12 to +15
if item_to_remove in self.inventory:
self.inventory.remove(item_to_remove)
return item_to_remove
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.

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.

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.

3 participants