This commit is contained in:
Ivan I. Ovchinnikov 2023-02-10 09:39:56 +03:00
parent 5bbdefb4a6
commit 90f68a083f
2 changed files with 21 additions and 2 deletions

View File

@ -5,3 +5,8 @@
fib_p(0) -> 0;
fib_p(1) -> 1;
fib_p(N) -> fib_p(N - 1) + fib_p(N - 2).
% Сторожевая последовательность
fib_g(N) when N < 1 -> 0;
fib_g(N) when N < 2 -> 1;
fib_g(N) -> fib_g(N-1) + fib_g(N-2).

View File

@ -10,7 +10,8 @@
-include_lib("eunit/include/eunit.hrl").
fib_test_() -> [
{"Test fib_p", fun test_fib_p/0 }
{"Test fib_p", fun test_fib_p/0 },
{"Test fib_g", fun test_fib_g/0 }
].
test_fib_p() ->
@ -25,3 +26,16 @@ test_fib_p() ->
?assertEqual(21, fib:fib_p(8)),
?assertEqual(34, fib:fib_p(9)),
?assertEqual(55, fib:fib_p(10)).
test_fib_g() ->
?assertEqual(0, fib:fib_g(0)),
?assertEqual(1, fib:fib_g(1)),
?assertEqual(1, fib:fib_g(2)),
?assertEqual(2, fib:fib_g(3)),
?assertEqual(3, fib:fib_g(4)),
?assertEqual(5, fib:fib_g(5)),
?assertEqual(8, fib:fib_g(6)),
?assertEqual(13, fib:fib_g(7)),
?assertEqual(21, fib:fib_g(8)),
?assertEqual(34, fib:fib_g(9)),
?assertEqual(55, fib:fib_g(10)).