Skip to content

Instantly share code, notes, and snippets.

@IlyaOsotov
Last active May 18, 2019 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IlyaOsotov/7cde9535b0e050a7869fd31198cd1108 to your computer and use it in GitHub Desktop.
Save IlyaOsotov/7cde9535b0e050a7869fd31198cd1108 to your computer and use it in GitHub Desktop.
factorial
defmodule Factorial do
def call(n) do
case n do
0 -> 1
_ -> n * call(n-1)
end
end
end
defmodule FactorialTest do
use ExUnit.Case
doctest Factorial
test "factorial 0" do
assert Factorial.call(0) == 1
end
test "factorial 5" do
assert Factorial.call(5) == 120
end
test "factorial 3" do
assert Factorial.call(3) == 6
end
end
# ilya@ilya-UX303LN:~/Repository/factorial$ mix test
# ...
#
# Finished in 0.03 seconds
# 3 tests, 0 failures
#
# Randomized with seed 947461
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment