Skip to content

Instantly share code, notes, and snippets.

@dmitriid
Last active Aug 29, 2015
Embed
What would you like to do?
%% 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