Add quick check test for order and handle variants.

This commit is contained in:
Erik Stenman 2019-05-31 14:42:00 +02:00
parent cb8e2b07a4
commit 58daf1bb5c
3 changed files with 39 additions and 2 deletions

View File

@ -22,5 +22,6 @@ quickcheck_test_() ->
{setup, fun() -> eqc:start() end,
[ ?EQC_EUNIT(aefate_eqc, prop_roundtrip, 500),
?EQC_EUNIT(aefate_eqc, prop_format_scan, 2000),
?EQC_EUNIT(aefate_eqc, prop_order, 2000),
?EQC_EUNIT(aefate_eqc, prop_fuzz, 2000)
]}.

View File

@ -63,6 +63,27 @@ prop_fuzz() ->
true
end))).
prop_order() ->
?FORALL({FateData1, FateData2, FateData3}, {fate_data(), fate_data(), fate_data()},
case aeb_fate_data:lt(FateData1, FateData2) of
true ->
case aeb_fate_data:lt(FateData2, FateData3) of
true ->
equals(aeb_fate_data:lt(FateData1, FateData3), true);
false ->
equals(aeb_fate_data:lt(FateData2, FateData1), false)
end;
false ->
case aeb_fate_data:lt(FateData1, FateData3) of
true ->
equals(aeb_fate_data:lt(FateData2, FateData3), true);
false ->
equals(aeb_fate_data:elt(FateData2, FateData1), true)
end
end).
fate_data() ->
?SIZED(Size, ?LET(Data, fate_data(Size, [map, variant]), eqc_symbolic:eval(Data))).

View File

@ -201,7 +201,7 @@ format_kvs(List) ->
%% Total order of FATE terms.
%% Integers < Booleans < Address < Channel < Contract < Name < Oracle
%% < Hash < Signature < Bits < String < Tuple < Map < List
%% < Hash < Signature < Bits < String < Tuple < Map < List < Variant
-spec ordinal(fate_type()) -> integer().
ordinal(T) when ?IS_FATE_INTEGER(T) -> 0;
ordinal(T) when ?IS_FATE_BOOLEAN(T) -> 1;
@ -216,7 +216,8 @@ ordinal(T) when ?IS_FATE_BITS(T) -> 9;
ordinal(T) when ?IS_FATE_STRING(T) -> 10;
ordinal(T) when ?IS_FATE_TUPLE(T) -> 11;
ordinal(T) when ?IS_FATE_MAP(T) -> 12;
ordinal(T) when ?IS_FATE_LIST(T) -> 13.
ordinal(T) when ?IS_FATE_LIST(T) -> 13;
ordinal(T) when ?IS_FATE_VARIANT(T) -> 14.
-spec lt(fate_type(), fate_type()) -> boolean().
@ -274,6 +275,20 @@ lt(13, ?FATE_LIST_VALUE([A|RA]), ?FATE_LIST_VALUE([B|RB])) ->
if O1 == O2 -> lt(RA, RB);
true -> O1 < O2
end;
lt(14, ?FATE_VARIANT(AritiesA, TagA, TA),
?FATE_VARIANT(AritiesB, TagB, TB)) ->
if length(AritiesA) < length(AritiesB) -> true;
length(AritiesB) > length(AritiesA) -> false;
true ->
if AritiesA < AritiesB -> true;
AritiesB < AritiesA -> false;
true ->
if TagA < TagB -> true;
TagB < TagA -> false;
true -> lt(make_tuple(TA), make_tuple(TB))
end
end
end;
lt(_, A, B) -> A < B.
tuple_elements_lt(N,_A,_B, N) ->