Skip to content

Instantly share code, notes, and snippets.

@allenyang79
Created February 5, 2018 18:05
Show Gist options
  • Save allenyang79/ee03f42e55b31b613b2ee078af6a151b to your computer and use it in GitHub Desktop.
Save allenyang79/ee03f42e55b31b613b2ee078af6a151b to your computer and use it in GitHub Desktop.
ExUnit.start
defmodule Test do
use ExUnit.Case
@moduledoc """
Run with test
## Examples
elixir test.exs
"""
defp is_odd?(n), do: rem(n, 2) == 1
defp is_even?(n), do: rem(n, 2) == 0
def my_filter(:is_odd, arr) do
Enum.filter(arr, &is_odd?/1)
end
def my_filter(:is_even, arr) do
Enum.filter(arr, &is_even?/1)
end
test "assert is_odd" do
my_filter(:is_odd, [1,2,3,4]) == [1, 3]
end
test "assert is_even" do
my_filter(:is_even, [1,2,3,4]) == [2, 4]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment