euc2003
Bjorn Gustavsson
bjorn@REDACTED
Thu Nov 20 13:51:57 CET 2003
It can handle recursive generators if you limit the size of the generated
sets. At the end of this email, I've attached a module that does some
tests on the gb_sets module.
/Bjorn
Luke Gorrie <luke@REDACTED> writes:
> The online version seems a bit older than the one presented, it
> doesn't handle recursively defined generators (as the 'sets' one
> is). I'll steal the latest code for Jungerl when John gets a chance to
> put it online, and until then there's a simpler example in there.
>
--
Björn Gustavsson Ericsson Utvecklings AB
bjorn@REDACTED ÄT2/UAB/F/P
BOX 1505
+46 8 727 56 87 125 25 Älvsjö
-module(gb_sets_check).
-compile(export_all).
-include("quickcheck.hrl").
t() ->
qc:quickcheck(prop_union_commutes()),
qc:quickcheck(prop_intersection_commutes()),
qc:quickcheck(prop_subset()),
qc:quickcheck(prop_empty()),
qc:quickcheck(prop_not_empty()),
%% Intentionally failing property.
qc:quickcheck(prop_difference_commutes()),
ok.
prop_union_commutes() ->
?FORALL(X,gb_set(),
?FORALL(Y,gb_set(),
equal(gb_sets:union(X, Y), gb_sets:union(Y, X)))).
prop_intersection_commutes() ->
?FORALL(X,gb_set(),
?FORALL(Y,gb_set(),
equal(gb_sets:intersection(X, Y), gb_sets:intersection(Y, X)))).
prop_difference_commutes() ->
?FORALL(X,gb_set(),
?FORALL(Y,gb_set(),
equal(gb_sets:difference(X, Y), gb_sets:difference(Y, X)))).
prop_subset() ->
?FORALL(X,gb_set(),
?FORALL(Y,gb_set(),
begin S = gb_sets:union(X, Y),
gb_sets:is_subset(X, S) andalso gb_sets:is_subset(Y, S) end)).
prop_empty() ->
?FORALL(X,gb_set(),
?IMPLIES(gb_sets:size(X) == 0, gb_sets:is_empty(X))).
prop_not_empty() ->
?FORALL(X,gb_set(),
?IMPLIES(gb_sets:size(X) /= 0, not gb_sets:is_empty(X))).
gb_set() ->
?SIZED(N, resize(min(50, N),
frequency(
[{6,?LET(L, list(int()),
return({'@',gb_sets,from_list,[L]}))},
{6,?LET(L, list(int()),
return({'@',gb_sets,from_ordset,[{'@',ordsets,from_list,[L]}]}))},
{6,?LET(S,gb_set(),?LET(E,int(),
return({'@',gb_sets,add,[E,S]})))},
{2,return({'@',gb_sets,empty,[]})},
{2,?LET(E,int(),
return({'@',gb_sets,singleton,[E]}))},
{1,?LET(P,function(bool()),?LET(S,gb_set(),
return({'@',gb_sets,filter,[P,S]})))}
]))).
equal(X, Y) ->
gb_sets:to_list(X) =:= gb_sets:to_list(Y).
min(A, B) when A < B -> A;
min(_, B) -> B.
More information about the erlang-questions
mailing list