Skip to content

Instantly share code, notes, and snippets.

@IlyaOsotov
Last active May 18, 2019 20:23
Show Gist options
  • Save IlyaOsotov/7cde9535b0e050a7869fd31198cd1108 to your computer and use it in GitHub Desktop.
Save IlyaOsotov/7cde9535b0e050a7869fd31198cd1108 to your computer and use it in GitHub Desktop.

Revisions

  1. IlyaOsotov revised this gist May 18, 2019. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions factorial_test.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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
  2. IlyaOsotov created this gist May 18, 2019.
    8 changes: 8 additions & 0 deletions factorial.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    defmodule Factorial do
    def call(n) do
    case n do
    0 -> 1
    _ -> n * call(n-1)
    end
    end
    end