Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-deterministic test needs a little ?SOMETIMES #13

Merged
merged 1 commit into from
Feb 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/basho_stats_histogram.erl
Original file line number Diff line number Diff line change
Expand Up @@ -245,23 +245,28 @@ prop_quantile() ->
%% XXX since we try to generate the quantile from the histogram, not the
%% original data, our results and Rs don't always agree and this means the
%% test will occasionally fail. There's not an easy way to fix this.
?FORALL({Min, Bins, Xlen, Q}, {choose(1, 99), choose(50, 200), choose(100, 500),
choose(0,100)},
?LET(Max, choose(Min+1, 100),
?LET(Xs, vector(Xlen, choose(Min, Max)),
?WHENFAIL(
begin
io:format("Min ~p, Max ~p, Bins ~p, Q ~p, Xs ~w~n",
[Min, Max, Bins, Q, Xs]),
Command = ?FMT("quantile(x, ~4.2f, type=4)", [Q * 0.01]),
InputStr = [integer_to_list(I) || I <- Xs],
io:format(?FMT("x <- c(~s)\n", [string:join(InputStr, ",")])),
io:format(?FMT("write(~s, ncolumns=1, file=stdout())\n", [Command]))
end,
qc_quantile_check(Q, Min, Max, Bins, Xs))))).
?SOMETIMES(3,
%% as the comment above states, this is
%% non-deterministic, but it should _never_ fail 3
%% times of 3
?FORALL({Min, Bins, Xlen, Q}, {choose(1, 99), choose(50, 200), choose(100, 500),
choose(0,100)},
?LET(Max, choose(Min+1, 100),
?LET(Xs, vector(Xlen, choose(Min, Max)),
?WHENFAIL(
begin
io:format("Min ~p, Max ~p, Bins ~p, Q ~p, Xs ~w~n",
[Min, Max, Bins, Q, Xs]),
Command = ?FMT("quantile(x, ~4.2f, type=4)", [Q * 0.01]),
InputStr = [integer_to_list(I) || I <- Xs],
io:format(?FMT("x <- c(~s)\n", [string:join(InputStr, ",")])),
io:format(?FMT("write(~s, ncolumns=1, file=stdout())\n", [Command]))
end,

qc_quantile_check(Q, Min, Max, Bins, Xs)))))).

qc_quantile_test() ->
true = eqc:quickcheck(prop_quantile()).

-endif.
-endif.
-endif.