aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2019-12-11 08:10:40 +0000
committerLouis Pilfold <louis@lpil.uk>2020-05-26 19:19:29 +0100
commit85fdfb298d7c9328c41a90e0da02a211785c0aa6 (patch)
tree90f041d863c545d55cf510c784173249232ebc49 /test
parent21e774dea2d678b90d5eb872eb9f0d9924c818ab (diff)
downloadgleam_stdlib-85fdfb298d7c9328c41a90e0da02a211785c0aa6.tar.gz
gleam_stdlib-85fdfb298d7c9328c41a90e0da02a211785c0aa6.zip
fold test
Diffstat (limited to 'test')
-rw-r--r--test/gleam/iterator_test.gleam16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/gleam/iterator_test.gleam b/test/gleam/iterator_test.gleam
index 2d9ee3f..46ac65a 100644
--- a/test/gleam/iterator_test.gleam
+++ b/test/gleam/iterator_test.gleam
@@ -39,3 +39,19 @@ pub fn take_test() {
test(2, [0, 1, 2, 3, 4])
test(22, [0, 1, 2, 3, 4])
}
+
+// a |> from_list |> fold(_, a, f) == a |> list.fold(_, a, f)
+pub fn fold_test() {
+ let test = fn(subject, acc, f) {
+ subject
+ |> iterator.from_list
+ |> iterator.fold(_, acc, f)
+ |> expect.equal(_, list.fold(subject, acc, f))
+ }
+
+ let f = fn(e, acc) { [e | acc] }
+ test([], [], f)
+ test([1], [], f)
+ test([1, 2, 3], [], f)
+ test([1, 2, 3, 4, 5, 6, 7, 8], [], f)
+}