diff --git a/test/UtilsLibTest.sol b/test/UtilsLibTest.sol index 41e9c8ab..0e0f7bcd 100644 --- a/test/UtilsLibTest.sol +++ b/test/UtilsLibTest.sol @@ -8,13 +8,21 @@ import "../lib/forge-std/src/Test.sol"; contract UtilsTest is Test { using UtilsLib for int256; - function testBound(int256 x, int256 low, int256 high) public { - if (x <= high) { - if (x >= low) assertEq(x.bound(low, high), x); - else assertEq(x.bound(low, high), low); - } else { - if (low <= high) assertEq(x.bound(low, high), high); - else assertEq(x.bound(low, high), low); - } + function testBoundExpected(int256 x, int256 low, int256 high) public { + int256 expected = x <= high ? (x >= low ? x : low) : (low <= high ? high : low); + assertEq(x.bound(low, high), expected); + } + + function testBoundMaxMin(int256 x, int256 low, int256 high) public { + int256 maxMin = _max(_min(x, high), low); + assertEq(x.bound(low, high), maxMin); + } + + function _min(int256 a, int256 b) private pure returns (int256) { + return a > b ? b : a; + } + + function _max(int256 a, int256 b) private pure returns (int256) { + return a > b ? a : b; } }