aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDennis Schröder <42579679+dennisschroeder@users.noreply.github.com>2023-02-01 18:25:18 +0100
committerGitHub <noreply@github.com>2023-02-01 17:25:18 +0000
commit9795db26afb557e8b028f62aca1c2f8f6a753658 (patch)
tree2526bde6d2c7bd63767f02939effc2143ffdee8e /test
parent3d088abfa0d7745a887028fdd9b2ff4216fa1d2b (diff)
downloadgleam_stdlib-9795db26afb557e8b028f62aca1c2f8f6a753658.tar.gz
gleam_stdlib-9795db26afb557e8b028f62aca1c2f8f6a753658.zip
implements the list group function (#400)
Diffstat (limited to 'test')
-rw-r--r--test/gleam/list_test.gleam24
-rw-r--r--test/gleam/option_test.gleam3
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)
}