aboutsummaryrefslogtreecommitdiffstats
path: root/lib/eunit/examples/fib.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/eunit/examples/fib.erl')
-rw-r--r--lib/eunit/examples/fib.erl19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/eunit/examples/fib.erl b/lib/eunit/examples/fib.erl
new file mode 100644
index 0000000000..1df02cebfc
--- /dev/null
+++ b/lib/eunit/examples/fib.erl
@@ -0,0 +1,19 @@
+
+-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)
+ ].