Last active
May 18, 2019 20:23
-
-
Save IlyaOsotov/7cde9535b0e050a7869fd31198cd1108 to your computer and use it in GitHub Desktop.
factorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Factorial do | |
def call(n) do | |
case n do | |
0 -> 1 | |
_ -> n * call(n-1) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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