Skip to content

Sapphire - Monica Lagdaan#90

Open
mmcknett-ada wants to merge 9 commits into
Ada-C19:mainfrom
monicadjl:main
Open

Sapphire - Monica Lagdaan#90
mmcknett-ada wants to merge 9 commits into
Ada-C19:mainfrom
monicadjl:main

Conversation

@mmcknett-ada

Copy link
Copy Markdown

[From Matt] I went ahead created a pull request for you so that I could provide you comments in the context of the code.

@mmcknett-ada mmcknett-ada left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Green 🟢!

@pytest.mark.skip
@pytest.mark.integration_test
#@pytest.mark.skip
#@pytest.mark.integration_test

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

[nit] You should leave the @pytest.mark.integration_test marks

from swap_meet.electronics import Electronics

@pytest.mark.skip
#@pytest.mark.skip

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

[nit] You can delete these vs. just commenting them out.

Comment on lines +36 to +37
assert len(items) == 0
assert items == []

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

[nit] Only one of these conditions is strictly necessary.

Comment on lines +117 to +118
assert len(tai.inventory) == 3
assert len(jesse.inventory) == 3

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You should not only check the length but also assert that the items you expect to be present in each list are present. For example, you might write:

    assert result == True
    assert len(tai.inventory) == 3
    assert item_a in tai.inventory
    assert item_b in tai.inventory
    assert item_f in tai.inventory
    assert len(jesse.inventory) == 3
    assert item_c in jesse.inventory
    assert item_d in jesse.inventory
    assert item_e in jesse.inventory

Your implementation passes this test. 🙂

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Same comment for the other three tests you filled out below.

Comment thread swap_meet/clothing.py
from swap_meet.item import Item

class Clothing(Item):
def __init__(self, id = None, fabric = "Unknown", condition=0):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

[opinion] I prefer space around = like you did with fabric = "Unknown". So condition = 0. You may prefer the other way, but whichever you prefer, I recommend being consistent.

Comment thread swap_meet/vendor.py
Comment on lines +15 to +19
if item in self.inventory:
self.inventory.remove(item)
return item
else:
return False

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

[suggestion] If your if body has a return, you technically don't need the else:. You could do:

        if item in self.inventory:
            self.inventory.remove(item)
            return item
        return False

Comment thread swap_meet/vendor.py

def swap_first_item(self, other_vendor):
if len(self.inventory) == 0 or len(other_vendor.inventory) == 0:
# if len(self.inventory) or len(other_vendor.inventory) == 0:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

[nit] You can remove this commented-out line.

Comment thread swap_meet/vendor.py
Comment on lines +51 to +56
category_list = []
for item in self.inventory:
if item.get_category() == category:
category_list.append(item)

return category_list

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Notice this pattern of:

result_list = []
for element in source_list:
    if some_condition(element):
        result_list.append(element)

can be rewritten using a list comprehension as:

result_list = [element for element in source_list if some_condition(element)]

Which here would look like:

items_in_category = [item for item in self.inventory if item.get_category() == category]
return items_in_category

At first, this may seem more difficult to read, but comprehensions are a very common python style, so I encourage y’all to try working with them!

Comment thread swap_meet/vendor.py
Comment on lines +59 to +68
of_category = self.get_by_category(category)
counter = 0
if len(of_category) == 0:
return None
for item in of_category:
if item.condition > counter:
counter = item.condition
for item in of_category:
if item.condition == counter:
return item

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Nice! Once you're comfortable with the version that uses loops, you can also write this with max:

of_category = self.get_by_category(category)
return max(of_category, key=lambda item: item.condition) if of_category else None

Comment thread swap_meet/vendor.py
Comment on lines +77 to +80
if swapski == True:
return True
else:
return False

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Whenever you have

if x == True:
    return True
else:
    return False

you can always replace it with

return x

@mmcknett-ada mmcknett-ada changed the title Monica Lagdaan Sapphire - Monica Lagdaan Apr 19, 2023
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.

2 participants