refactor(users/sterni/nix): move generic number operation into num
We omit type checks for performance reasons in most places currently, so the library grouping is important in showing people what to use for what sort of input. The moved functions make sense to use with floats as well, so we'll move them to the num library. Some of the remaining functions could theoretically be adapted and moved, but aren't for now. Change-Id: Ifdecaa60be594f4438b2a58b9ea6445e2da080e3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9007 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
dbdb2575cf
commit
984ea69386
6 changed files with 64 additions and 45 deletions
26
users/sterni/nix/num/tests/default.nix
Normal file
26
users/sterni/nix/num/tests/default.nix
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{ depot, ... }:
|
||||
|
||||
let
|
||||
|
||||
inherit (depot.nix.runTestsuite)
|
||||
runTestsuite
|
||||
it
|
||||
assertEq
|
||||
;
|
||||
|
||||
inherit (depot.users.sterni.nix)
|
||||
num
|
||||
;
|
||||
|
||||
testsBasic = it "tests basic operations" [
|
||||
(assertEq "abs -4959" (num.abs (-4959)) 4959)
|
||||
(assertEq "sum" (num.sum [ 123 321 1.5 ]) (123 + 321 + 1.5))
|
||||
(assertEq "inRange"
|
||||
(builtins.map (num.inRange 1.0 5) [ 0 0.5 3 4 4.5 5.5 5 6 ])
|
||||
[ false false true true true false true false ])
|
||||
];
|
||||
in
|
||||
|
||||
runTestsuite "nix.num" [
|
||||
testsBasic
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue