-
-
Notifications
You must be signed in to change notification settings - Fork 140
test: add fuzz tests for msb and sqrt #265
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
Conversation
|
Hi, @PaulRBerg. Any chance I get a review on this one? |
|
Hi @marmitar, I'm so sorry for dropping the ball here. You have my word that by Saturday, this PR and the other will be both reviewed. Thank you. |
PaulRBerg
left a comment
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.
left some feedback below and pushed directly to your branch
will merge now to speed up the review process; if you have any further feedback feel free to open another PR @marmitar :)
Thanks again for your contribution!
test/fuzz/common/msb.t.sol
Outdated
| /// @dev Collection of tests for the most significant bit function available in `Common.sol`. | ||
| contract Common_Sqrt_Test is Base_Test { | ||
| function testFuzz_Msb_FitsUint8(uint256 x) external pure { | ||
| assertLe(msb(x), type(uint8).max, "Common msb"); |
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.
would be good to use more specific test descriptions here
test/fuzz/common/msb.t.sol
Outdated
| import { Base_Test } from "../../Base.t.sol"; | ||
|
|
||
| /// @dev Collection of tests for the most significant bit function available in `Common.sol`. | ||
| contract Common_Sqrt_Test is Base_Test { |
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.
Incorrect test contract name
test/fuzz/common/sqrt.t.sol
Outdated
| // This case cannot be tested nicely using 'vm.assume()', | ||
| // because the fuzzer fails to find enough valid input. | ||
| // That's why we have to embed it here with an 'if'. | ||
| vm.assertEq(sqrt(x), MAX_SQRT, "Common sqrt"); |
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''ll move this to another text function and use bound:
For broad checks, such as ensuring a uint256 falls within a certain range, you can bound your input with the modulo operator or Forge Standard's bound method.
Tests for mathematical properties of some functions in
Common.sol. The implementation relies on the properties below.For
msb():For
sqrt():