diff options
author | Julian Schurhammer <julian.schurhammer@gmail.com> | 2022-10-20 22:35:26 +1300 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-10-20 11:18:29 +0100 |
commit | 495cf2599b2ccb01cc4991cba7021dc2e1456e5e (patch) | |
tree | 052336663e25f494d9bfd767bd1a40e5e38d2695 | |
parent | a44c3e48200079845a2bf60ebccafc39950b4f74 (diff) | |
download | gleam_stdlib-495cf2599b2ccb01cc4991cba7021dc2e1456e5e.tar.gz gleam_stdlib-495cf2599b2ccb01cc4991cba7021dc2e1456e5e.zip |
test list.sort stability
-rw-r--r-- | test/gleam/list_test.gleam | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index e02ef87..26489ee 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -448,6 +448,22 @@ pub fn unique_test() { } pub fn sort_test() { + [] + |> list.sort(int.compare) + |> should.equal([]) + + [1] + |> list.sort(int.compare) + |> should.equal([1]) + + [2, 1] + |> list.sort(int.compare) + |> should.equal([1, 2]) + + [3, 1, 2] + |> list.sort(int.compare) + |> should.equal([1, 2, 3]) + [4, 3, 6, 5, 4] |> list.sort(int.compare) |> should.equal([3, 4, 4, 5, 6]) @@ -459,10 +475,49 @@ pub fn sort_test() { [4.1, 3.1, 6.1, 5.1, 4.1] |> list.sort(float.compare) |> should.equal([3.1, 4.1, 4.1, 5.1, 6.1]) +} - [] - |> list.sort(int.compare) - |> should.equal([]) +pub fn sort_stability_test() { + let sorted_cards = [ + #(1, 1), + #(2, 1), + #(3, 1), + #(4, 1), + #(1, 2), + #(2, 2), + #(3, 2), + #(4, 2), + #(1, 3), + #(2, 3), + #(3, 3), + #(4, 3), + #(1, 4), + #(2, 4), + #(3, 4), + #(4, 4), + ] + let shuffled_cards = [ + #(3, 2), + #(1, 4), + #(2, 1), + #(3, 3), + #(4, 1), + #(3, 4), + #(1, 2), + #(4, 4), + #(3, 1), + #(1, 1), + #(2, 2), + #(2, 4), + #(4, 2), + #(4, 3), + #(1, 3), + #(2, 3), + ] + shuffled_cards + |> list.sort(fn(a, b) { int.compare(a.0, b.0) }) + |> list.sort(fn(a, b) { int.compare(a.1, b.1) }) + |> should.equal(sorted_cards) } pub fn index_map_test() { |