Skip to content

Pheonix Class- Madeline Bennett#4

Open
MBsea21 wants to merge 12 commits intoAda-C22:mainfrom
MBsea21:main
Open

Pheonix Class- Madeline Bennett#4
MBsea21 wants to merge 12 commits intoAda-C22:mainfrom
MBsea21:main

Conversation

@MBsea21
Copy link
Copy Markdown

@MBsea21 MBsea21 commented Oct 3, 2024

No description provided.

Copy link
Copy Markdown
Collaborator

@anselrognlie anselrognlie left a comment

Choose a reason for hiding this comment

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

Looks good! Please review my comments, and let me know if you have any questions via Slack, our next 1:1, or office hours.

Comment on lines +52 to +53
assert result == False
assert len(vendor.inventory) == 3 No newline at end of file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 This is the expected result, and while making sure the length hasn't changed is a good start, we might also include checks to make sure that the items in the vendor's inventory weren't modified.

# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
print("result is " , result)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👀 Remove debug output before submitting your project.

And consider using the debugger to break in to the test to see what value result is referring to rather than printing it out.

# ****** Complete Assert Portion of this test **********
# *********************************************************************
print("result is " , result)
assert result is False
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Though rare, apart from test cases, if we do literally want to compare with one of the boolean constants, we usually use == (and is for None). Though technically, == doesn't guarantee that result is literally False (in Python 0 == False and 1 == True), so I could be persuaded to prefer is since we're expecting to literally return either True or False.

Note that in application code, we rarely if ever compare against one of the boolean constants (with if some_val: preferred for a truthy check, and if not some_val: for a falsy one, and bool(some_val) if we just need to evaluate in a boolean context), but in a test that is meant to confirm the specified behavior, it's acceptable.

Comment on lines +134 to +139
assert jolie.inventory == []
assert len(fatimah.inventory) == 3
assert item_a in fatimah.inventory
assert item_b in fatimah.inventory
assert item_c in fatimah.inventory
assert len(jolie.inventory) == 0 No newline at end of file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 Great job checking both the result and that no changes happened to the inventories.

Note that the final check (len(jolie.inventory) == 0) is unnecesary since the earlier jolie.inventory == [] already ensures that Jolie's inventory is an empty list (therefore, it has a length of 0).

# ****** Complete Assert Portion of this test **********
# *********************************************************************
assert items == []
assert len(items) == 0
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Again, this check is redundant, since if items compares equal to an empty list, it must have length 0.

While in previous checks, we should check that on failure nothing has moved in the inventories, I think it's fine to omit that here, since we don't generally expect get_by_category to modify the inventory. Checking that n othing had changed is more recommended if the function would otherwise modify some collection or value, but due to a failure, the modification should be prevented.

Comment thread swap_meet/item.py
Comment on lines +39 to +54
def get_vintage_description(self):
item_age = self.age
if item_age > 0 and item_age < 20:
return "Not Vintage"
elif item_age > 20 and item_age < 30:
return "Almost Vintage"
elif item_age > 30 and item_age < 100:
return "It's vintage"
elif item_age >100:
return "SUPER DUPER VINTAGE"

def get_vintage_status(self):
if self.age > 30:
return True
else:
return False
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 Nice additional methods using your custom age attribute. We should add tests for these just like you have for get_oldest

Comment thread swap_meet/item.py
Comment on lines +41 to +48
if item_age > 0 and item_age < 20:
return "Not Vintage"
elif item_age > 20 and item_age < 30:
return "Almost Vintage"
elif item_age > 30 and item_age < 100:
return "It's vintage"
elif item_age >100:
return "SUPER DUPER VINTAGE"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's a little bit more difficult than the condition case since there are ranges of ages here, but we could still make this more data-driven (though maybe not better time complexity). How could we set up a data structure that would let us find the approprate string to use without a long if/elif chain?

Comment thread swap_meet/item.py
Comment on lines +51 to +54
if self.age > 30:
return True
else:
return False
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Again, we should avoid code like

        if conditon:
            return True
        else: 
            return False

Instead, we can return the condition result directly

        return self.age > 30

Comment thread swap_meet/vendor.py
Comment on lines +67 to +68
def get_oldest(self):
return self.get_max_item(self.inventory, "age")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 Nice custom function using your age data.

from swap_meet.decor import Decor
from swap_meet.electronics import Electronics

def test_get_oldest_items():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 Glad to see a test for your get_oldest function.

We'd like to see tests for the custom functions in Item, as well as just constructing Items and subtypes with a variety of age settings.

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