From 10af1307dddc5cb89596c92d3fbb5a8c4491eec1 Mon Sep 17 00:00:00 2001 From: RJ Dellecese Date: Mon, 30 Dec 2019 14:06:52 -0500 Subject: Rename generic module as function module --- test/gleam/function_test.gleam | 54 ++++++++++++++++++++++++++++++++++++++++++ test/gleam/generic_test.gleam | 54 ------------------------------------------ 2 files changed, 54 insertions(+), 54 deletions(-) create mode 100644 test/gleam/function_test.gleam delete mode 100644 test/gleam/generic_test.gleam (limited to 'test') diff --git a/test/gleam/function_test.gleam b/test/gleam/function_test.gleam new file mode 100644 index 0000000..86ef9a6 --- /dev/null +++ b/test/gleam/function_test.gleam @@ -0,0 +1,54 @@ +import gleam/expect +import gleam/function.{flip, compose} +import gleam/int as int_mod +import gleam/list +import gleam/result +import gleam/string as string_mod + +pub fn flip_test() { + let fun = fn(string: String, int: Int) { + string + |> string_mod.append("String: '", _) + |> string_mod.append(_, "', Int: '") + |> string_mod.append(_, int_mod.to_string(int)) + |> string_mod.append(_, "'") + } + + let flipped_fun = flip(fun) + + fun("Bob", 1) + |> expect.equal(_, "String: 'Bob', Int: '1'") + + flipped_fun(2, "Alice") + |> expect.equal(_, "String: 'Alice', Int: '2'") +} + +pub fn compose_test() { + let add_two = fn(int: Int) { int + 2 } + let add_three = fn(int: Int) { int + 3 } + + let add_five = compose(add_two, add_three) + + 1 + |> add_five + |> expect.equal(_, 6) + + // Takes a list of ints and returns the head as a string (if there is one, or + // else "0" if there is not) + let head_to_string = + compose( + list.head, + fn(int_result: Result(Int, Nil)) { + result.unwrap(int_result, 0) + |> int_mod.to_string + } + ) + + [1] + |> head_to_string + |> expect.equal(_, "1") + + [] + |> head_to_string + |> expect.equal(_, "0") +} diff --git a/test/gleam/generic_test.gleam b/test/gleam/generic_test.gleam deleted file mode 100644 index 7088edb..0000000 --- a/test/gleam/generic_test.gleam +++ /dev/null @@ -1,54 +0,0 @@ -import gleam/expect -import gleam/generic.{flip, compose} -import gleam/int as int_mod -import gleam/list -import gleam/result -import gleam/string as string_mod - -pub fn flip_test() { - let fun = fn(string: String, int: Int) { - string - |> string_mod.append("String: '", _) - |> string_mod.append(_, "', Int: '") - |> string_mod.append(_, int_mod.to_string(int)) - |> string_mod.append(_, "'") - } - - let flipped_fun = flip(fun) - - fun("Bob", 1) - |> expect.equal(_, "String: 'Bob', Int: '1'") - - flipped_fun(2, "Alice") - |> expect.equal(_, "String: 'Alice', Int: '2'") -} - -pub fn compose_test() { - let add_two = fn(int: Int) { int + 2 } - let add_three = fn(int: Int) { int + 3 } - - let add_five = compose(add_two, add_three) - - 1 - |> add_five - |> expect.equal(_, 6) - - // Takes a list of ints and returns the head as a string (if there is one, or - // else "0" if there is not) - let head_to_string = - compose( - list.head, - fn(int_result: Result(Int, Nil)) { - result.unwrap(int_result, 0) - |> int_mod.to_string - } - ) - - [1] - |> head_to_string - |> expect.equal(_, "1") - - [] - |> head_to_string - |> expect.equal(_, "0") -} -- cgit v1.2.3