Skip to content

Instantly share code, notes, and snippets.

@dmitriid
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitriid/3f02e615da0fcda5939e to your computer and use it in GitHub Desktop.
Save dmitriid/3f02e615da0fcda5939e to your computer and use it in GitHub Desktop.
%% Original property, based on docs
prop_seq() ->
?FORALL({From, To, Incr}
, {int(), int(), int()}
, begin
try
%% According to docs
length(lists:seq(From, To, Incr)) == (To - From + Incr) div Incr
catch
%% if we fail, these are supposed to be the only conditions why we fail
_:_ -> (To < From - Incr andalso Incr > 0) orelse
(To > From - Incr andalso Incr < 0) orelse
(Incr == 0 andalso From /= To)
end
end).
> eqc:quickcheck(eqc:prop_seq()).
Failed! After 1 tests.
{0,0,0}
false
%% Nope :) Works for lists:seq(0, 0, 0) and it shouldn't. Let's update our conditions
prop_seq() ->
?FORALL({From, To, Incr}
, {int(), int(), int()}
, begin
try
%% According to docs + update
case {From, To, Incr} of
{0, 0, 0} -> equals([0], lists:seq(From, To, Incr));
_ ->length(lists:seq(From, To, Incr)) == (To - From + Incr) div Incr
end
catch
%% if we fail, these are supposed to be the only conditions why we fail
_:_ ->
(To < From - Incr andalso Incr > 0) orelse
(To > From - Incr andalso Incr < 0) orelse
(Incr == 0 andalso From /= To)
end
end).
47> eqc:quickcheck(jesse_eqc:prop_seq()).
....................................................................................................
OK, passed 100 tests
true
48> eqc:quickcheck(jesse_eqc:prop_seq()).
....................................................................................................
OK, passed 100 tests
true
49> eqc:quickcheck(jesse_eqc:prop_seq()).
...Failed! After 4 tests.
{-1,-1,0}
Shrinking xxxx(0 times)
{-1,-1,0}
false
%%% oooops :) Wrong again :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment