diff options
author | Louis Pilfold <louis@lpil.uk> | 2020-05-22 12:11:31 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2020-05-26 19:19:29 +0100 |
commit | 3fefc3fc5efccbedacbf16a52b9531efa0d9ab30 (patch) | |
tree | 4d6e5424af42e1e9f1eca5b3c0b3cf8eee162d1f /test | |
parent | c8d393929ae233e80684b9063b3aaeae97291811 (diff) | |
download | gleam_stdlib-3fefc3fc5efccbedacbf16a52b9531efa0d9ab30.tar.gz gleam_stdlib-3fefc3fc5efccbedacbf16a52b9531efa0d9ab30.zip |
Update iterator for next Gleam
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/iterator_test.gleam | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/test/gleam/iterator_test.gleam b/test/gleam/iterator_test.gleam index 936621e..ec1eac3 100644 --- a/test/gleam/iterator_test.gleam +++ b/test/gleam/iterator_test.gleam @@ -1,16 +1,15 @@ -import gleam/expect +import gleam/should import gleam/iterator import gleam/list // TODO: Property tests - // a |> from_list |> to_list == a pub fn to_from_list_test() { let test = fn(subject) { subject |> iterator.from_list |> iterator.to_list - |> expect.equal(_, subject) + |> should.equal(subject) } test([]) @@ -19,13 +18,13 @@ pub fn to_from_list_test() { test([1, 2, 4, 8]) } -// a |> from_list |> take(_, n) == a |> list.take(_, n) +// a |> from_list |> take(n) == a |> list.take(_, n) pub fn take_test() { let test = fn(n, subject) { subject |> iterator.from_list - |> iterator.take(_, n) - |> expect.equal(_, list.take(subject, n)) + |> iterator.take(n) + |> should.equal(list.take(subject, n)) } test(0, []) @@ -40,30 +39,30 @@ pub fn take_test() { test(22, [0, 1, 2, 3, 4]) } -// a |> from_list |> fold(_, a, f) == a |> list.fold(_, a, f) +// 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)) + |> iterator.fold(acc, f) + |> should.equal(list.fold(subject, acc, f)) } - let f = fn(e, acc) { [e | acc] } + 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) } -// a |> from_list |> map(_, f) |> to_list == a |> list.map(_, f) +// a |> from_list |> map(f) |> to_list == a |> list.map(_, f) pub fn map_test() { let test = fn(subject, f) { subject |> iterator.from_list - |> iterator.map(_, f) + |> iterator.map(f) |> iterator.to_list - |> expect.equal(_, list.map(subject, f)) + |> should.equal(list.map(subject, f)) } let f = fn(e) { e * 2 } @@ -73,14 +72,14 @@ pub fn map_test() { test([1, 2, 3, 4, 5, 6, 7, 8], f) } -// a |> from_list |> filter(_, f) |> to_list == a |> list.filter(_, f) +// a |> from_list |> filter(f) |> to_list == a |> list.filter(_, f) pub fn filter_test() { let test = fn(subject, f) { subject |> iterator.from_list - |> iterator.filter(_, f) + |> iterator.filter(f) |> iterator.to_list - |> expect.equal(_, list.filter(subject, f)) + |> should.equal(list.filter(subject, f)) } let even = fn(x) { x % 2 == 0 } @@ -96,33 +95,33 @@ pub fn filter_test() { pub fn repeat_test() { 1 |> iterator.repeat - |> iterator.take(_, 5) - |> expect.equal(_, [1, 1, 1, 1, 1]) + |> iterator.take(5) + |> should.equal([1, 1, 1, 1, 1]) } pub fn cycle_test() { [1, 2, 3] |> iterator.from_list |> iterator.cycle - |> iterator.take(_, 9) - |> expect.equal(_, [1, 2, 3, 1, 2, 3, 1, 2, 3]) + |> iterator.take(9) + |> should.equal([1, 2, 3, 1, 2, 3, 1, 2, 3]) } pub fn unfold_test() { iterator.unfold(2, fn(acc) { iterator.Next(acc, acc * 2) }) - |> iterator.take(_, 5) - |> expect.equal(_, [2, 4, 8, 16, 32]) + |> iterator.take(5) + |> should.equal([2, 4, 8, 16, 32]) iterator.unfold(2, fn(_) { iterator.Done }) - |> iterator.take(_, 5) - |> expect.equal(_, []) + |> iterator.take(5) + |> should.equal([]) } pub fn range_test() { let test = fn(a, b, expected) { iterator.range(a, b) |> iterator.to_list - |> expect.equal(_, expected) + |> should.equal(expected) } test(0, 0, []) @@ -135,7 +134,7 @@ pub fn range_test() { pub fn drop_test() { iterator.range(0, 10) - |> iterator.drop(_, 5) + |> iterator.drop(5) |> iterator.to_list - |> expect.equal(_, [5, 6, 7, 8, 9]) + |> should.equal([5, 6, 7, 8, 9]) } |