diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/list_test.gleam | 24 | ||||
-rw-r--r-- | test/gleam/option_test.gleam | 3 |
2 files changed, 27 insertions, 0 deletions
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index ce865e4..68a02f8 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -1,6 +1,7 @@ import gleam/float import gleam/int import gleam/list +import gleam/map import gleam/should if erlang { @@ -94,6 +95,29 @@ pub fn rest_test() { |> should.equal(Error(Nil)) } +pub fn group_test() { + [Ok(10), Error("Wrong"), Ok(200), Ok(1)] + |> list.group(fn(i) { + case i { + Ok(_) -> "Successful" + Error(_) -> "Failed" + } + }) + |> should.equal( + map.new() + |> map.insert("Failed", [Error("Wrong")]) + |> map.insert("Successful", [Ok(1), Ok(200), Ok(10)]), + ) + + list.group([1, 2, 3, 4, 5], fn(i) { i - i / 3 * 3 }) + |> should.equal( + map.new() + |> map.insert(0, [3]) + |> map.insert(1, [4, 1]) + |> map.insert(2, [5, 2]), + ) +} + pub fn filter_test() { [] |> list.filter(fn(_) { True }) diff --git a/test/gleam/option_test.gleam b/test/gleam/option_test.gleam index ed0e61a..11bbe3e 100644 --- a/test/gleam/option_test.gleam +++ b/test/gleam/option_test.gleam @@ -5,6 +5,9 @@ pub fn all_test() { option.all([Some(1), Some(2), Some(3)]) |> should.equal(Some([1, 2, 3])) + option.all([]) + |> should.equal(Some([])) + option.all([Some(1), None, Some(3)]) |> should.equal(None) } |