TD-416: Ensure partially reduced predicate is valid predicate (#23)

* Simplify combination consisting of single predicate
* Add extra testcases
* Enable coveralls
This commit is contained in:
Andrew Mayorov 2022-10-03 13:54:20 +03:00 committed by GitHub
parent bbbeae5006
commit 1c7f97d16c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 19 deletions

View File

@ -30,11 +30,12 @@ jobs:
run:
name: Run checks
needs: setup
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.3
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.9
with:
otp-version: ${{ needs.setup.outputs.otp-version }}
rebar-version: ${{ needs.setup.outputs.rebar-version }}
use-thrift: true
thrift-version: ${{ needs.setup.outputs.thrift-version }}
run-ct-with-compose: true
use-coveralls: true
cache-version: v2

View File

@ -48,7 +48,6 @@
}.
-type predicate() :: dmsl_domain_thrift:'Predicate'().
-type criterion() :: dmsl_domain_thrift:'Criterion'().
-export_type([varset/0]).
@ -101,9 +100,7 @@ reduce_decisions([], _, _) ->
[].
-spec reduce_predicate(predicate(), varset(), pm_domain:revision()) ->
predicate()
% for a partially reduced criterion
| {criterion, criterion()}.
predicate().
reduce_predicate(?const(B), _, _) ->
?const(B);
reduce_predicate({condition, C0}, VS, Rev) ->
@ -126,11 +123,14 @@ reduce_predicate({any_of, Ps}, VS, Rev) ->
reduce_combination(any_of, true, Ps, VS, Rev, []);
reduce_predicate({criterion, CriterionRef = #domain_CriterionRef{}}, VS, Rev) ->
Criterion = pm_domain:get(Rev, {criterion, CriterionRef}),
case reduce_predicate(Criterion#domain_Criterion.predicate, VS, Rev) of
Predicate = Criterion#domain_Criterion.predicate,
case reduce_predicate(Predicate, VS, Rev) of
?const(B) ->
?const(B);
P1 ->
{criterion, Criterion#domain_Criterion{predicate = P1}}
Predicate ->
{criterion, CriterionRef};
NewPredicate ->
NewPredicate
end.
reduce_combination(Type, Fix, [P | Ps], VS, Rev, PAcc) ->
@ -144,6 +144,8 @@ reduce_combination(Type, Fix, [P | Ps], VS, Rev, PAcc) ->
end;
reduce_combination(_, Fix, [], _, _, []) ->
?const(not Fix);
reduce_combination(_, _, [], _, _, [P]) ->
P;
reduce_combination(Type, _, [], _, _, PAcc) ->
{Type, lists:reverse(PAcc)}.

View File

@ -107,10 +107,12 @@
-export([compute_provider_terminal_not_found/1]).
-export([compute_globals_ok/1]).
-export([compute_payment_routing_ruleset_ok/1]).
-export([compute_payment_routing_ruleset_unreducable/1]).
-export([compute_payment_routing_ruleset_irreducible/1]).
-export([compute_payment_routing_ruleset_not_found/1]).
-export([compute_pred_w_partial_all_of/1]).
-export([compute_pred_w_irreducible_criterion/1]).
-export([compute_pred_w_partially_irreducible_criterion/1]).
-export([compute_terms_w_criteria/1]).
-export([check_all_payment_methods/1]).
-export([check_all_withdrawal_methods/1]).
@ -274,12 +276,14 @@ groups() ->
compute_provider_terminal_not_found,
compute_globals_ok,
compute_payment_routing_ruleset_ok,
compute_payment_routing_ruleset_unreducable,
compute_payment_routing_ruleset_irreducible,
compute_payment_routing_ruleset_not_found
]},
{terms, [sequence], [
party_creation,
compute_pred_w_partial_all_of,
compute_pred_w_irreducible_criterion,
compute_pred_w_partially_irreducible_criterion,
compute_terms_w_criteria,
check_all_payment_methods,
check_all_withdrawal_methods
@ -508,10 +512,12 @@ end_per_testcase(_Name, _C) ->
-spec compute_provider_terminal_not_found(config()) -> _ | no_return().
-spec compute_globals_ok(config()) -> _ | no_return().
-spec compute_payment_routing_ruleset_ok(config()) -> _ | no_return().
-spec compute_payment_routing_ruleset_unreducable(config()) -> _ | no_return().
-spec compute_payment_routing_ruleset_irreducible(config()) -> _ | no_return().
-spec compute_payment_routing_ruleset_not_found(config()) -> _ | no_return().
-spec compute_pred_w_partial_all_of(config()) -> _ | no_return().
-spec compute_pred_w_irreducible_criterion(config()) -> _ | no_return().
-spec compute_pred_w_partially_irreducible_criterion(config()) -> _ | no_return().
-spec compute_terms_w_criteria(config()) -> _ | no_return().
party_creation(C) ->
@ -1847,7 +1853,7 @@ compute_payment_routing_ruleset_ok(C) ->
]}
} = pm_client_party:compute_routing_ruleset(?ruleset(1), DomainRevision, Varset, Client).
compute_payment_routing_ruleset_unreducable(C) ->
compute_payment_routing_ruleset_irreducible(C) ->
Client = cfg(client, C),
DomainRevision = pm_domain:head(),
Varset = #payproc_Varset{},
@ -1878,14 +1884,49 @@ compute_payment_routing_ruleset_not_found(C) ->
%%
compute_pred_w_partial_all_of(_) ->
Revision = pm_domain:head(),
Predicate =
{all_of, [
{constant, true},
{condition, {currency_is, ?cur(<<"CNY">>)}},
Cond1 = {condition, {category_is, ?cat(42)}},
Cond2 = {condition, {shop_location_is, {url, <<"https://thisiswhyimbroke.com">>}}}
]},
?assertMatch(
{all_of, [Cond1, Cond2]},
pm_selector:reduce_predicate(
Predicate,
#{currency => ?cur(<<"CNY">>)},
Revision
)
).
compute_pred_w_irreducible_criterion(_) ->
CritRef = ?crit(1),
CritName = <<"HAHA GOT ME">>,
CriterionRef = ?crit(1),
pm_ct_domain:with(
[
pm_ct_fixture:construct_criterion(
CritRef,
CritName,
CriterionRef,
<<"HAHA">>,
{condition, {currency_is, ?cur(<<"KZT">>)}}
)
],
fun(Revision) ->
?assertMatch(
{criterion, CriterionRef},
pm_selector:reduce_predicate({criterion, CriterionRef}, #{}, Revision)
)
end
).
compute_pred_w_partially_irreducible_criterion(_) ->
CriterionRef = ?crit(1),
pm_ct_domain:with(
[
pm_ct_fixture:construct_criterion(
CriterionRef,
<<"HAHA GOT ME">>,
{all_of, [
{constant, true},
{is_not, {condition, {currency_is, ?cur(<<"KZT">>)}}}
@ -1894,8 +1935,8 @@ compute_pred_w_irreducible_criterion(_) ->
],
fun(Revision) ->
?assertMatch(
{criterion, #domain_Criterion{name = CritName, predicate = {all_of, [_]}}},
pm_selector:reduce_predicate({criterion, CritRef}, #{}, Revision)
{is_not, {condition, {currency_is, ?cur(<<"KZT">>)}}},
pm_selector:reduce_predicate({criterion, CriterionRef}, #{}, Revision)
)
end
).

View File

@ -104,7 +104,8 @@
{project_plugins, [
{rebar3_lint, "1.0.1"},
{covertool, "2.0.4"},
{erlfmt, "1.0.0"}
{erlfmt, "1.0.0"},
{rebar3_lcov, {git, "https://github.com/valitydev/rebar3-lcov.git", {tag, "0.1"}}}
]}.
{erlfmt, [