Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

blackqueentech
Copy link

No description provided.

@blackqueentech blackqueentech changed the title Della 8/14 tests passed Della - Pet Park Assignment May 17, 2022
contracts/PetPark.sol Outdated Show resolved Hide resolved
contracts/PetPark.sol Outdated Show resolved Hide resolved
contracts/PetPark.sol Outdated Show resolved Hide resolved
contracts/PetPark.sol Outdated Show resolved Hide resolved
contracts/PetPark.sol Outdated Show resolved Hide resolved
contracts/PetPark.sol Outdated Show resolved Hide resolved
contracts/PetPark.sol Outdated Show resolved Hide resolved
if (_animal == AnimalType.Cat && age < 40) {
revert("Invalid animal for women under 40");
}
if (u.gender != _gender && _gender == Gender.Female) {
Copy link
Author

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.

Copy link

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.

u.gender != _gender ||
(u.gender == Gender.Female && _gender == Gender.Male) ||
(u.gender == Gender.Male && _gender == Gender.Female)
) {
Copy link
Author

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.

{
User storage u = userInfo[msg.sender];

if (u.age != _age && u.age != 0) {
Copy link
Contributor

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.

Copy link
Author

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?")

Copy link
Contributor

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
}

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.

4 participants