]> Repositorios git - scryer-prolog.git/commitdiff
Added a test for mod in CLP(Z)
authornotoria <[email protected]>
Wed, 10 Mar 2021 20:19:47 +0000 (21:19 +0100)
committernotoria <[email protected]>
Wed, 10 Mar 2021 20:20:18 +0000 (21:20 +0100)
src/tests/clpz/test_clpz.pl
src/tests/clpz/test_clpz2.pl [new file with mode: 0644]

index 7d91f918e1aa6d442e46a1c255fc439a5629bfe7..98fd827b51ee6d6b3152a257fd1b860b01ccd5e4 100644 (file)
@@ -100,7 +100,7 @@ run :-
             Dss
         ),
         E,
-        (   write('caugth: '), write(E), nl,
+        (   write('caught: '), write(E), nl,
             portray_clause([N, Settings, Vs, Gs4, Dss]), nl,
             false
         )
diff --git a/src/tests/clpz/test_clpz2.pl b/src/tests/clpz/test_clpz2.pl
new file mode 100644 (file)
index 0000000..7ee9409
--- /dev/null
@@ -0,0 +1,80 @@
+:- use_module(library(debug)).
+:- use_module(library(clpz)).
+% :- use_module('../../lib/clpz').
+:- use_module(library(format)).
+:- use_module(library(lists)).
+:- use_module(library(time)).
+:- use_module(combination).
+:- use_module(permutation).
+
+nat(N) :-
+    nat(0, N).
+
+nat(N, N).
+nat(N0, N) :-
+    N1 is N0 + 1,
+    nat(N1, N).
+
+bound(X, L, U) :- L #=< X, X #=< U.
+
+/*
+ * This test stops only if there is an mistake in the propagator.
+ * This test is general enough to quickly test other operators.
+ * This test does not test if permutating the clause changes the final result.
+ */
+run(N) :-
+    Vs = [X0, X1, X2, L0, L1, L2, U0, U1, U2],
+
+    Xs = [X0, X1, X2],
+    Ls = [L0, L1, L2],
+    Us = [U0, U1, U2],
+
+    Bs = [L0, L1, L2, U0, U1, U2],
+
+    % maplist(#=<, Ls, Us),
+    maplist(#\=(0), [X1, L1, U1]),
+    maplist(bound, Xs, Ls, Us),
+
+    % nat(N),
+    format("~d\n", [N]),
+    NegN is -N - 1,
+    Domain = NegN..N,
+
+    I in 0..6,
+    indomain(I),
+    length(Is, I),
+    combination(Bs, Is),
+    Is ins Domain,
+    labeling([], Is),
+
+    (   % Every solution is generated and only solution.
+        X2 #= X0 mod X1,
+        Xs ins Domain,
+        labeling([], Xs),
+        (   catch(X2 is X0 mod X1, _, false) ->
+            true
+        ;   format("~q\n", [error0([N, Vs, Ys])]) % Found a non-solution.
+        )
+    ;   % Every solution is found and only solution.
+        copy_term(Xs, Ys),
+        Ys = [Y0, Y1, Y2],
+        Ys ins Domain,
+        labeling([], Ys),
+        (   catch(Y2 is Y0 mod Y1, _, false) ->
+            (   X2 #= X0 mod X1 ->
+                (   maplist(=, Ys, Xs) ->
+                    % Find a specific solution.
+                    true
+                ;   format("~q\n", [error1([N, Vs, Ys])])
+                )
+            ;   format("~q\n", [error2([N, Vs, Ys])])
+            )
+        ;   X2 #= X0 mod X1,
+            (   maplist(=, Ys, Xs) ->
+                % Found a non-solution.
+                format("~q\n", [error3([N, Vs, Ys])])
+            ;   true
+            )
+        )
+    ),
+    false.