Compare commits

...

3 Commits

3 changed files with 70 additions and 0 deletions

17
erlang.iml Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="ERLANG_MODULE" version="4">
<component name="FacetManager">
<facet type="erlang" name="Erlang">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="jdk" jdkName="Erlang 25" jdkType="Erlang SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

12
src/fib.erl Normal file
View File

@ -0,0 +1,12 @@
-module(fib).
-export([fib_p/1]).
% Сопоставление с образцом
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).

41
test/fib_test.erl Normal file
View File

@ -0,0 +1,41 @@
%%%-------------------------------------------------------------------
%%% @author ivan
%%% @copyright (C) 2023, self
%%% @doc
%%%
%%% @end
%%% Created : 09. Feb 2023 23:52
%%%-------------------------------------------------------------------
-module(fib_test).
-include_lib("eunit/include/eunit.hrl").
fib_test_() -> [
{"Test fib_p", fun test_fib_p/0 },
{"Test fib_g", fun test_fib_g/0 }
].
test_fib_p() ->
?assertEqual(0, fib:fib_p(0)),
?assertEqual(1, fib:fib_p(1)),
?assertEqual(1, fib:fib_p(2)),
?assertEqual(2, fib:fib_p(3)),
?assertEqual(3, fib:fib_p(4)),
?assertEqual(5, fib:fib_p(5)),
?assertEqual(8, fib:fib_p(6)),
?assertEqual(13, fib:fib_p(7)),
?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)).