Skip to content

Instantly share code, notes, and snippets.

@hpyhacking
Created November 18, 2012 15:46
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 hpyhacking/4105910 to your computer and use it in GitHub Desktop.
Save hpyhacking/4105910 to your computer and use it in GitHub Desktop.
eunit-a-lightweight-unit-demo-code
-module(fib).
-export([fib/1]).
-include_lib("eunit/include/eunit.hrl").
fib(0) -> 1;
fib(1) -> 1;
fib(N) when N > 1 -> fib(N-1) + fib(N-2).
fib_test_() ->
[?_assert(fib(0) =:= 1),
?_assert(fib(1) =:= 1),
?_assert(fib(2) =:= 2),
?_assert(fib(3) =:= 3),
?_assert(fib(4) =:= 5),
?_assert(fib(5) =:= 8),
?_assertException(error, function_clause, fib(-1)),
?_assert(fib(31) =:= 2178309)
].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment