Skip to content
Permalink
Browse files
dont take the log of a negative number dummy
  • Loading branch information
Joe Williams committed Nov 5, 2013
1 parent bb739b2 commit 6c19d6a2ee031512fca9916dd7cca2fc7ea2a38e
Showing 2 changed files with 12 additions and 0 deletions.
@@ -373,6 +373,8 @@ math_log(0) ->
1;
math_log(0.0) ->
1.0;
math_log(X) when X < 0 ->
0; % it's not possible to take a log of a negative number, return 0
math_log(X) ->
math:log(X).

@@ -244,6 +244,16 @@ full_subset_test() ->
Stats = bear:get_statistics(bear:test_values()),
match_values2(Stats).

negative_test() ->
%% make sure things don't blow up with a negative value
Values = [1,-1,-2,3,3,4,5,6,7],
[{min, -2}] = bear:get_statistics_subset(Values, [min]).

negative2_test() ->
%% make sure things don't blow up with a negative value
Values = [-1,-1,-2,-2,-3,-5,-6,-10],
[{min, -10}] = bear:get_statistics_subset(Values, [min]).

match_values([H|T]) ->
Res = bear:get_statistics_subset(bear:test_values(), [mk_item(H)]),
Res = [H],

0 comments on commit 6c19d6a

Please sign in to comment.