From 8fb4c949dc267050b75b2efbcfdff1ca1b307fc5 Mon Sep 17 00:00:00 2001 From: sterni Date: Sat, 5 Aug 2023 17:58:23 +0200 Subject: test(tvix/eval): check truncation direction of builtins.div builtins.div ought to truncate towards zero so that -(builtins.div a b) == builtins.div (-a) b -(builtins.div a b) == builtins.div a (-b) Change-Id: I8b7c08cd7f4fa8a1363c786d42c8d484f6cd133d Reviewed-on: https://cl.tvl.fyi/c/depot/+/9006 Autosubmit: sterni Reviewed-by: tazjin Tested-by: BuildkiteCI --- .../tests/tvix_tests/eval-okay-builtins-div.exp | 2 +- .../tests/tvix_tests/eval-okay-builtins-div.nix | 23 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.exp index 73e9bc33b083..44154ba6a6b2 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.exp +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.exp @@ -1 +1 @@ -[ 3 7 0 1 0 0.5 0.5 0.5 42 ] +[ 3 7 0 1 0 0.5 0.5 0.5 42 1 1 -1 -1 -1 1 1 -1 -1 -1 1 1 -1 -1 -1 -74711 -74711 -74711 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix index 98b8b74bdf2b..dc6ce2781593 100644 --- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix @@ -8,4 +8,27 @@ (builtins.div 1 2.0) (builtins.div 1.0 2.0) (builtins.div (builtins.div 84 4) 0.5) + + # builtins.div should truncate towards 0 + (builtins.div 3 2) + (builtins.div (-3) (-2)) + (builtins.div (-3) 2) + (builtins.div 3 (-2)) + (-(builtins.div 3 2)) + + (builtins.div 4 3) + (builtins.div (-4) (-3)) + (builtins.div (-4) 3) + (builtins.div 4 (-3)) + (-(builtins.div 4 3)) + + (builtins.div 5 3) + (builtins.div (-5) (-3)) + (builtins.div (-5) 3) + (builtins.div 5 (-3)) + (-(builtins.div 5 3)) + + (builtins.div 2147812578 (-28748)) + (builtins.div (-2147812578) 28748) + (-(builtins.div 2147812578 28748)) ] -- cgit 1.4.1