some bonehead
parent
2e341a2409
commit
e0adf8c39f
|
@ -13,12 +13,12 @@ builtins // rec {
|
|||
filter_ = list: fn: (builtins.filter fn list);
|
||||
|
||||
# :: [T] -> (T -> V) -> {T[int] = V;}
|
||||
list2Attrs_ = list: fn_k_v (builtins.foldl' (acc: k: acc // { k = (fn_k_v k); }) { } list);
|
||||
list2Attrs = fn_k_v: list (list2Attrs_ list fn_k_v);
|
||||
list2Attrs_ = list: fn_k_v: (builtins.foldl' (acc: k: acc // { "${k}" = (fn_k_v k); }) { } list);
|
||||
list2Attrs = fn_k_v: list: (list2Attrs_ list fn_k_v);
|
||||
|
||||
# range :: int -> int -> [int]
|
||||
rangeIn = lib.range;
|
||||
rangeEx = start: stop: (lib.range start stop-1);
|
||||
rangeEx = start: stop: (lib.range start (stop -1));
|
||||
|
||||
# [T] -> int
|
||||
len = builtins.length;
|
||||
|
|
|
@ -2,7 +2,7 @@ let
|
|||
pkgs = import <nixpkgs> { };
|
||||
inherit (pkgs) lib;
|
||||
inherit (lib) runTests;
|
||||
c_ = import ./default.nix;
|
||||
c_ = import ./default.nix { inherit pkgs lib; };
|
||||
bulkExprTest = { name, fn, list_case, ... }@test: (c_.foldl'
|
||||
(acc: { name, args, expected, ... }@case: acc // {
|
||||
"test_${test.name}_${case.name}" = {
|
||||
|
@ -13,7 +13,8 @@ let
|
|||
{ }
|
||||
list_case);
|
||||
tests = (
|
||||
bulkExprTest {
|
||||
bulkExprTest
|
||||
{
|
||||
name = "filterMap_";
|
||||
fn = c_.filterMap_;
|
||||
list_case = [
|
||||
|
@ -49,7 +50,45 @@ let
|
|||
list_case = [
|
||||
{
|
||||
name = "attach";
|
||||
args = [["123" "abc" "1414"]];
|
||||
args = [ [ "123" "abc" "1414" ] (_x: 515) ];
|
||||
expected = { "123" = 515; "abc" = 515; "1414" = 515; };
|
||||
}
|
||||
];
|
||||
} // bulkExprTest {
|
||||
name = "zip";
|
||||
fn = c_.zip;
|
||||
list_case = [
|
||||
{
|
||||
name = "equal_length";
|
||||
args = [ [ 1 2 3 ] [ 4 5 6 ] ];
|
||||
expected = [ [ 1 4 ] [ 2 5 ] [ 3 6 ] ];
|
||||
}
|
||||
{
|
||||
name = "left_more";
|
||||
args = [ [ 1 2 3 4 ] [ 5 6 7 ] ];
|
||||
expected = [ [ 1 5 ] [ 2 6 ] [ 3 7 ] ];
|
||||
}
|
||||
];
|
||||
} // bulkExprTest {
|
||||
name = "enumerate";
|
||||
fn = c_.enumerate;
|
||||
list_case = [
|
||||
{
|
||||
name = "empty";
|
||||
args = [ [ ] ];
|
||||
expected = [ ];
|
||||
}
|
||||
{
|
||||
name = "normal";
|
||||
args = [ [ 51 51 11 23 17 125 ] ];
|
||||
expected = [
|
||||
{ idx = 0; val = 51; }
|
||||
{ idx = 1; val = 51; }
|
||||
{ idx = 2; val = 11; }
|
||||
{ idx = 3; val = 23; }
|
||||
{ idx = 4; val = 17; }
|
||||
{ idx = 5; val = 125; }
|
||||
];
|
||||
}
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue