mirror of
https://git.mediani.de/mirrors_public/oddlama_nixos-extra-modules.git
synced 2025-10-10 22:10:38 +02:00
fix: tests
fix: arithmeticRight
This commit is contained in:
parent
19b469d1b3
commit
fb68031848
5 changed files with 101 additions and 3 deletions
|
@ -1160,7 +1160,10 @@ let
|
|||
# coshadow :: integer -> (ip | mac | integer) -> (ip | mac | integer)
|
||||
coshadow = n: a: and (not (right n (left n (coerce a (-1))))) a;
|
||||
|
||||
# coerce :: (ip | mac | integer) -> (ip | mac | integer) -> (ip | mac | integer)
|
||||
# coerce target value
|
||||
# coerce value to the type of target
|
||||
# coerce :: A -> (ip | mac | integer) -> A
|
||||
# where A :: (ip | mac | integer)
|
||||
coerce =
|
||||
target: value:
|
||||
if target ? ipv6 then
|
||||
|
|
|
@ -109,7 +109,7 @@ let
|
|||
arithmeticRight =
|
||||
a: b:
|
||||
if a >= 64 then
|
||||
0
|
||||
if b < 0 then -1 else 0
|
||||
else if a == 0 then
|
||||
b
|
||||
else if a < 0 then
|
||||
|
|
|
@ -5,4 +5,5 @@
|
|||
}:
|
||||
[
|
||||
(import ./shift.nix { inherit pkgs nixt; })
|
||||
(import ./net.nix { inherit pkgs nixt; })
|
||||
]
|
||||
|
|
93
tests/net.nix
Normal file
93
tests/net.nix
Normal file
|
@ -0,0 +1,93 @@
|
|||
{
|
||||
nixt,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (nixt.lib) block describe it;
|
||||
inherit (pkgs) lib;
|
||||
expected = {
|
||||
cidrv6 = {
|
||||
empty = {
|
||||
base = {
|
||||
ipv6 = {
|
||||
a = 0;
|
||||
b = 0;
|
||||
c = 0;
|
||||
d = 0;
|
||||
};
|
||||
};
|
||||
length = 0;
|
||||
};
|
||||
base4 = {
|
||||
base = {
|
||||
ipv6 = {
|
||||
a = 65536;
|
||||
b = 0;
|
||||
c = 0;
|
||||
d = 0;
|
||||
};
|
||||
};
|
||||
length = 4;
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
block ./net.nix [
|
||||
(describe "cidrv6" [
|
||||
(it "child 1" (lib.net.cidr.child "1::/4" "0::/0"))
|
||||
(it "child 2" (lib.net.cidr.child "1::/4" "::/0"))
|
||||
(it "child 3" (!lib.net.cidr.child "::/0" "::/4"))
|
||||
(it "child 4" (lib.net.cidr.child "1100::/8" "1000::/4"))
|
||||
(it "child 5" (!lib.net.cidr.child "1100::/16" "1000::/8"))
|
||||
(it "child 6" (lib.net.cidr.child "0:1::/24" "0:1::/8"))
|
||||
|
||||
(it "typechecks 1" (lib.typechecks.cidr "" "" "::/0" == expected.cidrv6.empty))
|
||||
(it "typechecks 2" (lib.typechecks.cidr "" "" "0::/0" == expected.cidrv6.empty))
|
||||
(it "typechecks 3" (lib.typechecks.cidr "" "" "1::/4" == expected.cidrv6.empty // { length = 4; }))
|
||||
|
||||
(it "impl child" (lib.implementations.cidr.child expected.cidrv6.base4 expected.cidrv6.empty))
|
||||
|
||||
(it "cidr length 0" (lib.implementations.cidr.length expected.cidrv6.empty == 0))
|
||||
(it "cidr length 4" (lib.implementations.cidr.length expected.cidrv6.base4 == 4))
|
||||
|
||||
(it "contains 4" (
|
||||
lib.implementations.cidr.contains expected.cidrv6.base4.base expected.cidrv6.empty
|
||||
))
|
||||
|
||||
(it "host 4" (lib.implementations.cidr.host 0 expected.cidrv6.base4 == expected.cidrv6.base4.base))
|
||||
(it "host 0" (lib.implementations.cidr.host 0 expected.cidrv6.empty == expected.cidrv6.empty.base))
|
||||
|
||||
(it "make len 0" (
|
||||
lib.implementations.cidr.make 0 expected.cidrv6.base4.base == expected.cidrv6.empty
|
||||
))
|
||||
(it "make base 4 len 0 length" (
|
||||
(lib.implementations.cidr.make 0 expected.cidrv6.base4.base).length == 0
|
||||
))
|
||||
(it "make base 4 len 0 base" (
|
||||
(lib.implementations.cidr.make 0 expected.cidrv6.base4.base).base == expected.cidrv6.empty.base
|
||||
))
|
||||
])
|
||||
(describe "cidrv4" [
|
||||
(it "child 1" (lib.net.cidr.child "10.10.10.0/24" "10.0.0.0/8"))
|
||||
(it "child 2" (!lib.net.cidr.child "127.0.0.0/24" "10.0.0.0/8"))
|
||||
])
|
||||
(describe "arithmetic" [
|
||||
(it "coshadow 1" (
|
||||
(lib.arithmetic.coshadow 0 expected.cidrv6.base4.base) == expected.cidrv6.empty.base
|
||||
))
|
||||
(it "coerce 1" (
|
||||
(lib.arithmetic.coerce expected.cidrv6.base4.base (-1)) == {
|
||||
ipv6 = {
|
||||
a = 4294967295;
|
||||
b = 4294967295;
|
||||
c = 4294967295;
|
||||
d = 4294967295;
|
||||
};
|
||||
}
|
||||
))
|
||||
])
|
||||
(describe "bit" [
|
||||
(it "mask 32 " ((lib.bit.mask 32 (-1)) == 4294967295))
|
||||
])
|
||||
]
|
|
@ -393,6 +393,7 @@ block ./shift.nix [
|
|||
(it "negative logical right shift 21068 >> 0" (logicalRight 0 (-21068) == -21068))
|
||||
(it "arithmetic right shift 21068 >> 0" (arithmeticRight 0 21068 == 21068))
|
||||
(it "negative arithmetic right shift 21068 >> 0" (arithmeticRight 0 (-21068) == -21068))
|
||||
|
||||
(it "arithmetic right shift -1 >> 32" (arithmeticRight 32 (-1) == (-1)))
|
||||
(it "arithmetic right shift -1 >> 102" (arithmeticRight 102 (-1) == (-1)))
|
||||
])
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue