Branchless ternary, min and max methods (#4976)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Ernesto García <ernestognw@gmail.com>
This commit is contained in:
committed by
GitHub
parent
60afc99053
commit
4032b42694
@ -7,6 +7,16 @@ import {Test, stdError} from "forge-std/Test.sol";
|
||||
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
|
||||
|
||||
contract MathTest is Test {
|
||||
function testSelect(bool f, uint256 a, uint256 b) public {
|
||||
assertEq(Math.ternary(f, a, b), f ? a : b);
|
||||
}
|
||||
|
||||
// MIN & MAX
|
||||
function testMinMax(uint256 a, uint256 b) public {
|
||||
assertEq(Math.min(a, b), a < b ? a : b);
|
||||
assertEq(Math.max(a, b), a > b ? a : b);
|
||||
}
|
||||
|
||||
// CEILDIV
|
||||
function testCeilDiv(uint256 a, uint256 b) public {
|
||||
vm.assume(b > 0);
|
||||
|
||||
Reference in New Issue
Block a user