diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-03-03 00:09:46 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-03 00:09:46 -0300 |
| commit | 24e5e531134fbb8757151a68438d0b8426c91c4c (patch) | |
| tree | db53b9fb5392541a71f8df02282bb392ec80914c /test/constraint_2op_tests.erl | |
| parent | baca3a79cded23329ba8555afefb5590b679c955 (diff) | |
| download | Sakura-24e5e531134fbb8757151a68438d0b8426c91c4c.tar.gz Sakura-24e5e531134fbb8757151a68438d0b8426c91c4c.zip | |
2OP Constraints and manipulation
Diffstat (limited to 'test/constraint_2op_tests.erl')
| -rw-r--r-- | test/constraint_2op_tests.erl | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/constraint_2op_tests.erl b/test/constraint_2op_tests.erl new file mode 100644 index 0000000..11e3af5 --- /dev/null +++ b/test/constraint_2op_tests.erl @@ -0,0 +1,52 @@ +-module(constraint_2op_tests). + +-include_lib("eunit/include/eunit.hrl"). +-include("../include/operations.hrl"). + +exists_quantifier_inference_plus_test() -> + main:setup(), + DB0 = operations:create_database(test_db), + {DB1, _} = operations:create_relation(DB0, employees, #{a => integer, b => integer, c => integer}), + + TupleConstraint = constraint:create_2op(a_gt_b_plus_c, + [ + {exists, s, integer, + {'and', [ + {member_of, plus, #{a => {var, b}, b => {var, c}, sum => {var, s}}}, + {member_of, greater_than, #{left => {var, a}, right => {var, s}}} + ]}} + ]), + + Constraints = constraint:add_tuple_constraint(undefined, TupleConstraint), + {DB2, _} = operations:update_relation_constraints(DB1, employees, Constraints), + + {DB3, _} = operations:create_tuple(DB2, employees, #{a => 10, b => 3, c => 4}), + Rejected = operations:create_tuple(DB3, employees, #{a => 6, b => 3, c => 4}), + + ?assertMatch({error, {constraint_violation, {tuple_constraint_violations, [_ | _]}}}, Rejected), + + {error, {constraint_violation, {tuple_constraint_violations, [Violation | _]}}} = Rejected, + Diagnostics = maps:get(diagnostics, Violation, []), + + ?assert(lists:any(fun(D) -> maps:get(kind, D, undefined) =:= quantified_by_inference end, Diagnostics)), + ?assert(lists:any(fun(D) -> maps:get(kind, D, undefined) =:= member_of_false end, Diagnostics)). + +forall_infinite_domain_rejected_test() -> + main:setup(), + DB0 = operations:create_database(test_db), + {DB1, _} = operations:create_relation(DB0, employees, #{a => integer, b => integer, c => integer}), + + TupleConstraint = constraint:create_2op(forall_integer_rejected, + [ + {forall, s, integer, + {member_of, greater_than, #{left => {var, a}, right => {var, s}}}} + ]), + + Constraints = constraint:add_tuple_constraint(undefined, TupleConstraint), + {DB2, _} = operations:update_relation_constraints(DB1, employees, Constraints), + Rejected = operations:create_tuple(DB2, employees, #{a => 10, b => 3, c => 4}), + + ?assertMatch({error, {constraint_violation, {tuple_constraint_violations, [_ | _]}}}, Rejected), + {error, {constraint_violation, {tuple_constraint_violations, [Violation | _]}}} = Rejected, + Diagnostics = maps:get(diagnostics, Violation, []), + ?assert(lists:any(fun(D) -> maps:get(kind, D, undefined) =:= unbounded_quantifier end, Diagnostics)). |
