Skip to content

Commit

Permalink
Fixes and better tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Burd committed Jun 20, 2012
1 parent d30133a commit dd05cff
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 142 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -80,7 +80,7 @@ proper-compile: compile-proper

eunit: eunit-compile
@echo "eunit testing: $(RELPKG) ..."
$(REBAR) eunit recursive=false
$(REBAR) eunit skip_deps=true

eqc: eqc-compile
@echo "eqc testing: $(RELPKG) ... not implemented yet"
Expand Down
6 changes: 5 additions & 1 deletion rebar.config
Expand Up @@ -2,9 +2,13 @@
{cover_enabled, true}.

{clean_files, ["*.eunit", "ebin/*.beam"]}.
{eunit_opts, [verbose, {report, {eunit_surefire, [{dir, "."}]}}]}.
{eunit_opts, [verbose,
{report, {eunit_surefire, [{dir, "."},
{parse_transform, lager_transform}
]}}]}.

{deps, [ {edown, "0.3.*", {git, "git://github.com/esl/edown.git", {branch, "master"}}}
, {lager, ".*", {git, "git://github.com/basho/lager", {branch, "master"}}}
, {asciiedoc, "0.1.*", {git, "git://github.com/norton/asciiedoc.git", {branch, "master"}}}
, {triq, ".*", {git, "git://github.com/krestenkrab/triq.git", {branch, "master"}}}
]}.
Expand Down
2 changes: 1 addition & 1 deletion src/bloom.erl
Expand Up @@ -37,7 +37,7 @@ new(N, E) when N > 0, is_float(E), E > 0, E =< 1 ->
%% @doc Creates a new empty Bloom filter from an existing one.
-spec clear(#bloom{}) -> #bloom{}.
clear(#bloom{bitmap=Bitmap} = B) ->
B#bloom{bitmap = <<0:(erlang:bit_size(Bitmap))>>, n=0}.
B#bloom{bitmap = <<0:(erlang:bit_size(Bitmap))>>, n=0, keys=0}.

%% @doc Returns the number of elements encoded into this Bloom filter.
-spec count(#bloom{}) -> non_neg_integer().
Expand Down
20 changes: 14 additions & 6 deletions src/bloomerl.app.src
@@ -1,12 +1,20 @@

{application, bloomerl,
[
{description, "Bloom filters"},
{vsn, "1.0.0"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{applications, [kernel, stdlib ]},
{mod, {bloomerl_app, []}},
{env, []}
]}.
{env, [
{lager, [
{handlers, [
{lager_console_backend, info},
{lager_file_backend, [
{"error.log", error, 10485760, "$D0", 5},
{"console.log", info, 10485760, "$D0", 5}
]}
]}
]}
]}
]}.
88 changes: 0 additions & 88 deletions src/ebloom.erl

This file was deleted.

7 changes: 0 additions & 7 deletions test/bloom_SUITE.erl

This file was deleted.

54 changes: 54 additions & 0 deletions test/bloom_tests.erl
@@ -0,0 +1,54 @@
%% @hidden
-module(bloom_tests).
-compile(export_all).

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

all_my_test_() ->
[ {"Should create a bloom filter", fun should_create_a_bloom_filter/0}
, {"Should be sized correctly", fun should_be_sized_correctly/0}
, {"Should contain one element", fun should_contain_one_element/0}
].

should_create_a_bloom_filter() ->
Bloom = bloom:new(5, 0.001),
true = bloom:is_bloom(Bloom),
false = bloom:is_bloom({foo}).

should_be_sized_correctly() ->
Bloom1 = bloom:new(5, 0.1),
32 = bloom:filter_size(Bloom1),
Bloom2 = bloom:new(5, 0.01),
48 = bloom:filter_size(Bloom2),
Bloom3 = bloom:new(5), % default is 0.001
72 = bloom:filter_size(Bloom3),
Bloom4 = bloom:new(5, 0.0001),
96 = bloom:filter_size(Bloom4).

should_contain_one_element() ->
Bloom = bloom:new(5, 0.01),
0 = bloom:count(Bloom),
Bloom1 = bloom:add_element(<<"abcdef">>, Bloom),
Bloom1 = bloom:add_element(<<"abcdef">>, Bloom),
1 = bloom:count(Bloom1),
true = bloom:is_element(<<"abcdef">>, Bloom1),
false = bloom:is_element(<<"zzzzzz">>, Bloom1),
Bloom2 = bloom:clear(Bloom1),
0 = bloom:count(Bloom2),
false = bloom:is_element(<<"abcdef">>, Bloom2),
false = bloom:is_element(<<"zzzzzz">>, Bloom2).


%% Helper functions

%% fold_lines(FileName, Fun) ->
%% {ok, Device} = file:open(FileName, [read]),
%% fold_over_lines(Device, Fun).

%% fold_over_lines(Device, Fun) ->
%% case io:get_line(Device, "") of
%% eof ->
%% file:close(Device);
%% Line ->
%% Fun(Line), fold_over_lines(Device, Fun)
%% end.
38 changes: 0 additions & 38 deletions test/ebloom_SUITE.erl

This file was deleted.

0 comments on commit dd05cff

Please sign in to comment.