mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-31 04:58:01 +00:00
bahaghari/lib: add math.isWithinRange'
This commit is contained in:
parent
2576ef4e43
commit
3f8c59c399
@ -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.
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user