From f66ad5672d061bbaba0af9458da6f1f4fe0211d9 Mon Sep 17 00:00:00 2001 From: Giacomo Cavalieri Date: Tue, 21 May 2024 09:45:35 +0200 Subject: The `dict` module gains the `combine` function --- test/gleam/dict_test.gleam | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test') diff --git a/test/gleam/dict_test.gleam b/test/gleam/dict_test.gleam index ca77bb9..0bcb334 100644 --- a/test/gleam/dict_test.gleam +++ b/test/gleam/dict_test.gleam @@ -403,3 +403,29 @@ pub fn extra_keys_equality_test() { should.be_false(map1 == map2) should.be_false(map2 == map1) } + +pub fn combine_test() { + let map1 = dict.from_list([#("a", 3), #("b", 2)]) + let map2 = dict.from_list([#("a", 2), #("c", 3), #("d", 4)]) + + dict.combine(map1, map2, fn(one, other) { one - other }) + |> should.equal(dict.from_list([#("a", 1), #("b", 2), #("c", 3), #("d", 4)])) +} + +pub fn combine_with_empty_test() { + let map1 = dict.from_list([#("a", 3), #("b", 2)]) + + dict.combine(map1, dict.new(), fn(one, _) { one }) + |> should.equal(map1) + + dict.combine(dict.new(), map1, fn(one, _) { one }) + |> should.equal(map1) +} + +pub fn combine_with_no_overlapping_keys_test() { + let map1 = dict.from_list([#("a", 1), #("b", 2)]) + let map2 = dict.from_list([#("c", 3), #("d", 4)]) + + dict.combine(map1, map2, fn(one, _) { one }) + |> should.equal(dict.from_list([#("a", 1), #("b", 2), #("c", 3), #("d", 4)])) +} -- cgit v1.2.3