From 313a24e4de935576193519ea196dbcbf378a98b4 Mon Sep 17 00:00:00 2001 From: sterni Date: Sat, 29 Oct 2022 14:25:17 +0200 Subject: test(tvix/eval): builtins.sort must preserve order of equal elements Change-Id: I59a0756940d1e5360a2ab4e886cf0bc9af7b8901 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7133 Autosubmit: sterni Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.exp | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.nix | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.nix (limited to 'tvix/eval') diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.exp new file mode 100644 index 0000000000..9d78376214 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.exp @@ -0,0 +1 @@ +[ { index = 7; key = 0; } { index = 0; key = 1; } { index = 13; key = 1; } { index = 1; key = 2; } { index = 3; key = 2; } { index = 4; key = 2; } { index = 5; key = 2; } { index = 12; key = 2; } { index = 14; key = 2; } { index = 2; key = 3; } { index = 11; key = 3; } { index = 15; key = 3; } { index = 10; key = 4; } { index = 6; key = 5; } { index = 8; key = 5; } { index = 9; key = 5; } { index = 16; key = 22; } ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.nix new file mode 100644 index 0000000000..9969e0a294 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-stable-sort.nix @@ -0,0 +1,7 @@ +let + keys = [ 1 2 3 2 2 2 5 0 5 5 4 3 2 1 2 3 22 ]; +in + +builtins.sort + (a: b: a.key < b.key) + (builtins.genList (index: { inherit index; key = builtins.elemAt keys index; }) (builtins.length keys)) -- cgit 1.4.1