Skip to content

Instantly share code, notes, and snippets.

@nurugger07
Created July 21, 2013 04:10
Show Gist options
  • Save nurugger07/6047459 to your computer and use it in GitHub Desktop.
Save nurugger07/6047459 to your computer and use it in GitHub Desktop.
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