Skip to content

Commit

Permalink
finish the application
Browse files Browse the repository at this point in the history
  • Loading branch information
eshubin committed Apr 16, 2013
1 parent d977935 commit a74277a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/interval.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
stdlib
]},
{mod, { interval_app, []}},
{env, []}
{env, [{filename, "priv/orig_intervals"}]}
]}.
37 changes: 37 additions & 0 deletions src/interval.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%% Copyright
-module(interval).
-author("eshubin").

%% API
-export([find/1]).


find(N) when is_integer(N) ->
interval_srv:find(N).


-include_lib("eunit/include/eunit.hrl").

interval_test_() ->
{
setup,
fun() ->
ok = application:load(interval),
ok = application:set_env(interval, filename, "../priv/two_intervals"),
ok = application:start(interval)
end,
fun(_) ->
application:stop(interval)
end,
fun(_) ->
[
?_assertEqual(not_found, find(4)),
?_assertEqual(not_found, find(365916480007)),
?_assertEqual(not_found, find(506822291477)),
?_assertEqual({{401297465489,406822291477}, 0.5527523660317453}, find(401298465489)),
?_assertEqual({{13935775370,365916480006}, 0.8678967605514785}, find(13935775371)),
?_assertEqual({{13935775370,365916480006}, 0.8678967605514785}, find(365916480006)),
?_assertEqual({{13935775370,365916480006}, 0.8678967605514785}, find(13935775370))
]
end
}.
3 changes: 2 additions & 1 deletion src/interval_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
%% ===================================================================

start(_StartType, _StartArgs) ->
interval_sup:start_link().
{ok, FileName} = application:get_env(filename),
interval_sup:start_link(FileName).

stop(_State) ->
ok.
2 changes: 1 addition & 1 deletion src/interval_srv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interval_srv_test_() ->
{
setup,
fun() ->
start_link("../priv/two_intervals")
{ok, _} = start_link("../priv/two_intervals")
end,
fun(_) ->
[
Expand Down
12 changes: 6 additions & 6 deletions src/interval_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
-behaviour(supervisor).

%% API
-export([start_link/0]).
-export([start_link/1]).

%% Supervisor callbacks
-export([init/1]).

%% Helper macro for declaring children of supervisor
-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
-define(CHILD(I, Type, Args), {I, {I, start_link, Args}, permanent, 5000, Type, [I]}).

%% ===================================================================
%% API functions
%% ===================================================================

start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
start_link(FileName) ->
supervisor:start_link({local, ?MODULE}, ?MODULE, FileName).

%% ===================================================================
%% Supervisor callbacks
%% ===================================================================

init([]) ->
{ok, { {one_for_one, 5, 10}, []} }.
init(FileName) ->
{ok, { {one_for_one, 5, 10}, [?CHILD(interval_srv, worker, [FileName])]} }.

0 comments on commit a74277a

Please sign in to comment.