-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Della - Pet Park Assignment #19
base: main
Are you sure you want to change the base?
Conversation
contracts/PetPark.sol
Outdated
if (_animal == AnimalType.Cat && age < 40) { | ||
revert("Invalid animal for women under 40"); | ||
} | ||
if (u.gender != _gender && _gender == Gender.Female) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what is unclear to me. Zero value for enums is the first value, so the "default" gender is Male. I'm struggling to work that logic into the check for when a user hasn't borrowed any animals yet. This makes sense to me but it leads to the women <40 cat test failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of thinking of a negative test case, how would you write a condition for women under the age of 40 inside the if clause? And then lets if they are requesting a cat, if so then revert.
contracts/PetPark.sol
Outdated
u.gender != _gender || | ||
(u.gender == Gender.Female && _gender == Gender.Male) || | ||
(u.gender == Gender.Male && _gender == Gender.Female) | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not able to pass the female under 40 borrowing cats because it hits this test. Here is my logic for the code:
u.gender != _gender
- this is the clear incorrect case.
(u.gender == Gender.Female && _gender == Gender.Male)
- this is an example of another clear case, feels redundant but it shows genders not matching
(u.gender == Gender.Male && _gender == Gender.Female)
- this is the case I have an issue with. If I am understanding solidity correctly, before an address is added to the map, it will default to male since it is first in the Gender enum. Therefore, if an address calls borrow
for the first time and is of Gender.Female
, this will always fail because it won't match the default option on the enum. I need clarification as to how to get around this. I don't know why there isn't a need for a Gender.None
enum option to avoid this, like there is for AnimalType
.
contracts/PetPark.sol
Outdated
{ | ||
User storage u = userInfo[msg.sender]; | ||
|
||
if (u.age != _age && u.age != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The age, gender and animal checks for the case when the pet was already borrowed, should be in a single if clause. Once you move them, all your tests will pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can you add them into one clause while keeping all the separate revert statements? ("Invalid Age", "Invalid Gender", "Already borrowed a pet?")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad.I meant if block
not if clause
. Something like this
if (u.age != 0) { // If clause to check if the pet was already borrowed
// All the conditions go here
}
No description provided.