bahaghari/lib: add math.isWithinRange'

This commit is contained in:
Gabriel Arazas 2024-06-15 15:12:05 +08:00
parent 2576ef4e43
commit 3f8c59c399
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
2 changed files with 29 additions and 0 deletions

View File

@ -137,6 +137,20 @@ rec {
isWithinRange = min: max: number:
(lib.max number min) <= (lib.min number max);
/* Returns a boolean whether the given number is within the given (exclusive) range.
Type: isWithinRange :: Number -> Number -> Number -> Bool
Example:
isWithinRange 30 50 6
=> false
isWithinRange 0 100 75
=> true
*/
isWithinRange' = min: max: number:
(lib.max number min) < (lib.min number max);
/* Given a number, make it grow by given amount of percentage.
A value of 100 should make the number doubled.

View File

@ -157,6 +157,21 @@ lib.runTests {
expected = false;
};
testMathWithinRangeExclusive = {
expr = self.math.isWithinRange' 5 10 (-5);
expected = false;
};
testMathWithinRangeExclusive2 = {
expr = self.math.isWithinRange' 5 10 10;
expected = false;
};
testMathWithinRangeExclusive3 = {
expr = self.math.isWithinRange' (-100) 100 750;
expected = false;
};
testMathFactorial = {
expr = self.math.factorial 3;
expected = 6;