Sorting should be idempotent

This commit is contained in:
Thomas Arts 2019-06-03 14:49:02 +02:00
parent ffebc13d08
commit 985e5358c9
2 changed files with 10 additions and 1 deletions

View File

@ -21,5 +21,6 @@
quickcheck_test_() -> quickcheck_test_() ->
{setup, fun() -> eqc:start() end, {setup, fun() -> eqc:start() end,
[ ?EQC_EUNIT(aefate_type_eqc, prop_roundtrip, 1000), [ ?EQC_EUNIT(aefate_type_eqc, prop_roundtrip, 1000),
?EQC_EUNIT(aefate_eqc, prop_serializes, 1000) ?EQC_EUNIT(aefate_eqc, prop_serializes, 1000),
?EQC_EUNIT(aefate_eqc, prop_idempotent, 1000)
]}. ]}.

View File

@ -88,10 +88,18 @@ lt_max([X, Y | Rest]) ->
end; end;
lt_max([X]) -> X. lt_max([X]) -> X.
prop_idempotent() ->
?FORALL(Items, list({fate_data_key(), fate_data()}),
equals(aeb_fate_encoding:sort(Items),
aeb_fate_encoding:sort(aeb_fate_encoding:sort(Items)))).
fate_data() -> fate_data() ->
?SIZED(Size, ?LET(Data, fate_data(Size, [map, variant]), eqc_symbolic:eval(Data))). ?SIZED(Size, ?LET(Data, fate_data(Size, [map, variant]), eqc_symbolic:eval(Data))).
fate_data_key() ->
?SIZED(Size, ?LET(Data, fate_data(Size div 4, []), eqc_symbolic:eval(Data))).
fate_data(0, _Options) -> fate_data(0, _Options) ->
?LAZY( ?LAZY(
oneof([fate_integer(), oneof([fate_integer(),