diff options
author | inoas <mail@inoas.com> | 2022-10-27 21:36:34 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-27 22:36:34 +0100 |
commit | 5cd94fd14ae3d674b679542f56c73247dd7a2e77 (patch) | |
tree | 42690732b3337c8b1360422e51289a0fe3df6a13 /test | |
parent | 93c3223e8e5d5f9ba2a4020b18bed5802c63bdff (diff) | |
download | gleam_stdlib-5cd94fd14ae3d674b679542f56c73247dd7a2e77.tar.gz gleam_stdlib-5cd94fd14ae3d674b679542f56c73247dd7a2e77.zip |
fix list.permutation on lists with non unique item values (#358)
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/list_test.gleam | 99 |
1 files changed, 85 insertions, 14 deletions
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index ec95af4..83cf60d 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -848,33 +848,104 @@ pub fn permutations_test() { |> list.permutations |> should.equal([[1, 2], [2, 1]]) - let expected = [ + [1, 2, 3] + |> list.permutations + |> should.equal([ [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1], - ] + ]) - [1, 2, 3] + [1, 2, 3, 4] |> list.permutations - |> should.equal(expected) + |> should.equal([ + [1, 2, 3, 4], + [1, 2, 4, 3], + [1, 3, 2, 4], + [1, 3, 4, 2], + [1, 4, 2, 3], + [1, 4, 3, 2], + [2, 1, 3, 4], + [2, 1, 4, 3], + [2, 3, 1, 4], + [2, 3, 4, 1], + [2, 4, 1, 3], + [2, 4, 3, 1], + [3, 1, 2, 4], + [3, 1, 4, 2], + [3, 2, 1, 4], + [3, 2, 4, 1], + [3, 4, 1, 2], + [3, 4, 2, 1], + [4, 1, 2, 3], + [4, 1, 3, 2], + [4, 2, 1, 3], + [4, 2, 3, 1], + [4, 3, 1, 2], + [4, 3, 2, 1], + ]) ["a", "b"] |> list.permutations |> should.equal([["a", "b"], ["b", "a"]]) - // TCO test - case recursion_test_cycles > 2 { - // Permutation count: - // 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 = 40_320 - // 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 = 362_800 - True -> - [1, 2, 3, 4, 5, 6, 7, 8, 9] - |> list.permutations - False -> [[]] - } + [1, 1] + |> list.permutations + |> should.equal([[1, 1], [1, 1]]) + + [1, 1, 1] + |> list.permutations + |> should.equal([ + [1, 1, 1], + [1, 1, 1], + [1, 1, 1], + [1, 1, 1], + [1, 1, 1], + [1, 1, 1], + ]) + + [1, 2, 2] + |> list.permutations + |> should.equal([ + [1, 2, 2], + [1, 2, 2], + [2, 1, 2], + [2, 2, 1], + [2, 1, 2], + [2, 2, 1], + ]) + + ["a", "a", "a", "a"] + |> list.permutations + |> should.equal([ + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ["a", "a", "a", "a"], + ]) } pub fn window_test() { |