From e4d09202ab7d3b0a4bc52213858ce939b0a2a6dd Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 17 Dec 2020 14:57:08 +1100 Subject: Add list.permutations --- test/gleam/list_test.gleam | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test') diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index ff94c3b..d9a4285 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -481,3 +481,26 @@ pub fn partition_test() { |> list.partition(int.is_odd) |> should.equal(tuple([1, 3, 5, 7], [2, 4, 6])) } + +pub fn permutations_test() { + [1, 2] + |> list.permutations + |> should.equal([[1, 2], [2, 1]]) + + let expected = [ + [1, 2, 3], + [1, 3, 2], + [2, 1, 3], + [2, 3, 1], + [3, 1, 2], + [3, 2, 1], + ] + + [1, 2, 3] + |> list.permutations + |> should.equal(expected) + + ["a", "b"] + |> list.permutations + |> should.equal([["a", "b"], ["b", "a"]]) +} -- cgit v1.2.3