From 985e5358c97b836e9813a5286573af2488d7b72e Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Mon, 3 Jun 2019 14:49:02 +0200 Subject: [PATCH] Sorting should be idempotent --- quickcheck/aeb_fate_encoding_tests.erl | 3 ++- quickcheck/aefate_eqc.erl | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/quickcheck/aeb_fate_encoding_tests.erl b/quickcheck/aeb_fate_encoding_tests.erl index 6bc94d2..1bd8e1e 100644 --- a/quickcheck/aeb_fate_encoding_tests.erl +++ b/quickcheck/aeb_fate_encoding_tests.erl @@ -21,5 +21,6 @@ quickcheck_test_() -> {setup, fun() -> eqc:start() end, [ ?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) ]}. diff --git a/quickcheck/aefate_eqc.erl b/quickcheck/aefate_eqc.erl index e67d07a..49df042 100644 --- a/quickcheck/aefate_eqc.erl +++ b/quickcheck/aefate_eqc.erl @@ -88,10 +88,18 @@ lt_max([X, Y | Rest]) -> end; 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() -> ?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) -> ?LAZY( oneof([fate_integer(),