Here is a simple valid constraint for a diagonal line
line(X,Y) :-
X #= Y.
The constraint works as expected.
:- use_module(library(clpfd)).
?- line(X,Y).
X = '$VAR'('Y'),
'$VAR'('Y')in inf..sup.
?- findall((X,Y),(between(-5,5,X),line(X,Y)),Line).
Line = [(-5, -5), (-4, -4), (-3, -3), (-2, -2), (-1, -1), (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5)].
Now in writing test cases I find it easier to let the system output the correct answer and then I copy it into the test case, e.g.
:- begin_tests(simple_constraints).
test(1) :-
X = 5,
assertion( X == x ).
:- end_tests(simple_constraints).
When the test is run it outputs a result, which I then verify is the correct result before coping back into the test. In this case x = 5
ERROR: c:/xyz.pl:40:
test 4: assertion failed
Assertion: 5==x
:- begin_tests(simple_constraints).
test(1) :-
X = 5,
assertion( X == 5 ).
:- end_tests(simple_constraints).
and re-run the test.
?- make.
% c:/xyz compiled 0.00 sec, -2 clauses
% PL-Unit: simple_constraints ... done
% All 3 tests passed
true.
Doing the same for the constraint does not work.
:- begin_tests(simple_constraints).
test(2) :-
line(X,Y),
assertion( X == x ),
assertion( Y == y ).
:- end_tests(simple_constraints).
Running of the test
?- make.
% c:/xyz compiled 0.00 sec, 2 clauses
% PL-Unit: simple_constraints ..
ERROR: c:/xyz.pl:35:
test 3: assertion failed
Assertion: _10244==x
ERROR: c:/xyz.pl:35:
test 3: assertion failed
Assertion: _10244==y
A. done
% 2 assertions failed
% 1 test failed
% 3 tests passed
true.
Instead of
_10244==x
I was hoping for something like
'$VAR'('Y') == x