Created
July 21, 2013 04:10
-
-
Save nurugger07/6047459 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Math do | |
def sum([]), do: 0 | |
def sum([head | tail]), do: head + sum(tail) | |
def square([]), do: [] | |
def square([head | tail]), do: [head * head | square(tail)] | |
end | |
ExUnit.start | |
defmodule MathTest do | |
use ExUnit.Case | |
test :sum_list_of_values_equal_to_8 do | |
assert Math.sum([1,4,3]) == 8 | |
end | |
test :sum_list_of_values_equal_to_6 do | |
assert Math.sum([1,2,3]) == 6 | |
end | |
test :square_list do | |
assert Math.square([2,4,6]) == [4,16,36] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment