From cf7831f278423bab72f5d9433771e5a16ce44cac Mon Sep 17 00:00:00 2001 From: Brett Snyder Date: Wed, 2 Oct 2019 10:49:43 -0500 Subject: add pair:map_first and pair:map_second --- test/gleam/pair_test.gleam | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'test') diff --git a/test/gleam/pair_test.gleam b/test/gleam/pair_test.gleam index 54a12af..5dd2690 100644 --- a/test/gleam/pair_test.gleam +++ b/test/gleam/pair_test.gleam @@ -26,3 +26,37 @@ pub fn swap_test() { |> pair.swap |> expect.equal(_, pair.Pair("2", 1)) } + +pub fn map_first_test() { + let inc = fn(a) { + a + 1 + } + pair.map_first(pair.Pair(1, 2), inc) + |> expect.equal(_, pair.Pair(2, 2)) + + pair.map_first(pair.Pair(8,2), inc) + |> expect.equal(_, pair.Pair(9, 2)) + + pair.map_first(pair.Pair(0,-2), inc) + |> expect.equal(_, pair.Pair(1, -2)) + + pair.map_first(pair.Pair(-10, 20), inc) + |> expect.equal(_, pair.Pair(-9, 20)) +} + +pub fn map_second_test() { + let dec = fn(a) { + a - 1 + } + pair.map_second(pair.Pair(1, 2), dec) + |> expect.equal(_, pair.Pair(1, 1)) + + pair.map_second(pair.Pair(8,2), dec) + |> expect.equal(_, pair.Pair(8, 1)) + + pair.map_second(pair.Pair(0,-2), dec) + |> expect.equal(_, pair.Pair(0, -3)) + + pair.map_second(pair.Pair(-10, 20), dec) + |> expect.equal(_, pair.Pair(-10, 19)) +} -- cgit v1.2.3