]> Repositorios git - scryer-prolog.git/commitdiff
add tests for issue 3048
authorSkgland <[email protected]>
Sat, 16 Aug 2025 13:29:25 +0000 (15:29 +0200)
committerBennet Bleßmann <[email protected]>
Sun, 17 Aug 2025 12:50:15 +0000 (14:50 +0200)
tests/scryer/cli/issues/issue_3048.in/compare.pl [new file with mode: 0644]
tests/scryer/cli/issues/issue_3048.in/compare_get_assoc.pl [new file with mode: 0644]
tests/scryer/cli/issues/issue_3048.in/minimize1.pl [new file with mode: 0644]
tests/scryer/cli/issues/issue_3048.in/minimize_final.pl [new file with mode: 0644]
tests/scryer/cli/issues/issue_3048.in/original.pl [new file with mode: 0644]
tests/scryer/cli/issues/issue_3048.in/original_alt.pl [new file with mode: 0644]
tests/scryer/cli/issues/issue_3048.in/pair_string_key.pl [new file with mode: 0644]
tests/scryer/cli/issues/issue_3048.md [new file with mode: 0644]
tests/scryer/main.rs

diff --git a/tests/scryer/cli/issues/issue_3048.in/compare.pl b/tests/scryer/cli/issues/issue_3048.in/compare.pl
new file mode 100644 (file)
index 0000000..a86f6ee
--- /dev/null
@@ -0,0 +1,8 @@
+:- use_module(library(format)).
+
+
+test :- compare(_, ("0"-'2'), ("1"-'1')).
+
+?- test.
+   false, unexpected.
+   true.
diff --git a/tests/scryer/cli/issues/issue_3048.in/compare_get_assoc.pl b/tests/scryer/cli/issues/issue_3048.in/compare_get_assoc.pl
new file mode 100644 (file)
index 0000000..11900d7
--- /dev/null
@@ -0,0 +1,12 @@
+get_assoc(Key, t(K,V,_,L,R), Val) :-
+    compare(Rel, Key, K),
+    get_assoc(Rel, Key, V, L, R, Val).
+
+get_assoc(=, _, Val, _, _, Val).
+get_assoc(>, Key, _, _, Tree, Val) :- get_assoc(Key, Tree, Val).
+
+test :- get_assoc("1"-'0', t("0"-'2',_, _, t(_,_,_,t,t), t("1"-'0',_,_,t,t)), _).
+
+?- test.
+   false, unexpected.
+   true.
diff --git a/tests/scryer/cli/issues/issue_3048.in/minimize1.pl b/tests/scryer/cli/issues/issue_3048.in/minimize1.pl
new file mode 100644 (file)
index 0000000..c7de16e
--- /dev/null
@@ -0,0 +1,39 @@
+:- use_module(library(format)).
+
+% is_assoc copied from library(assoc) and renamed to is_assoc_
+% and `% format("~w~n", [is_assoc_(R,RMin,Max,RDepth)]),` added
+
+is_assoc_(Assoc) :-
+    is_assoc_(Assoc, _Min, _Max, _Depth).
+
+is_assoc_(t,X,X,0) :- !.
+is_assoc_(t(K,_,-,t,t),K,K,1) :- !, ground(K).
+is_assoc_(t(K,_,>,t,t(RK,_,-,t,t)),K,RK,2) :-
+    % Ensure right side Key is 'greater' than K
+    !, ground((K,RK)), K @< RK.
+
+is_assoc_(t(K,_,<,t(LK,_,-,t,t),t),LK,K,2) :-
+    % Ensure left side Key is 'less' than K
+    !, ground((LK,K)), LK @< K.
+
+is_assoc_(t(K,_,B,L,R),Min,Max,Depth) :-
+    is_assoc_(L,Min,LMax,LDepth),
+    % format("~w~n", [is_assoc_(R,RMin,Max,RDepth)]),
+    is_assoc_(R,RMin,Max,RDepth),
+    % Ensure Balance matches depth
+    compare(Rel,RDepth,LDepth),
+    balance(Rel,B),
+    % Ensure ordering
+    ground((LMax,K,RMin)),
+    LMax @< K,
+    K @< RMin,
+    Depth is max(LDepth, RDepth)+1.
+
+balance(=,-).
+balance(>,>).
+balance(<,<).
+
+test :- is_assoc_(t(2,1,-,t(1,1,-,t,t),t(3,1,-,t,t))).
+
+?- test.
+   true.
diff --git a/tests/scryer/cli/issues/issue_3048.in/minimize_final.pl b/tests/scryer/cli/issues/issue_3048.in/minimize_final.pl
new file mode 100644 (file)
index 0000000..949e858
--- /dev/null
@@ -0,0 +1,6 @@
+a(t(K),K) :- ground(K).
+
+test :- a(t(3), M), M=M.
+
+?- test.
+   true.
diff --git a/tests/scryer/cli/issues/issue_3048.in/original.pl b/tests/scryer/cli/issues/issue_3048.in/original.pl
new file mode 100644 (file)
index 0000000..7035a51
--- /dev/null
@@ -0,0 +1,24 @@
+:- use_module(library(assoc)).
+:- use_module(library(lists)).
+:- use_module(library(iso_ext)).
+
+put([_], _).
+put([Old, New | Tail], Idx) :-
+  put_assoc(Idx, Old, 1, New),
+  IdxP is Idx +1,
+  put([New |Tail], IdxP).
+
+run(Max, Bad) :- 
+  empty_assoc(A),
+  length(As, Max),
+  put([A|As], 1),
+  findall(Idx, (nth0(Idx, [A|As], Assoc), \+ is_assoc(Assoc)), Bad).
+
+
+?- N = 20, run(N, Bad).
+   N = 20, Bad = [3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], unexpected
+   ; false.
+   N = 20, Bad = []
+   ; false.
+
+test :- run(20, []).
diff --git a/tests/scryer/cli/issues/issue_3048.in/original_alt.pl b/tests/scryer/cli/issues/issue_3048.in/original_alt.pl
new file mode 100644 (file)
index 0000000..718b360
--- /dev/null
@@ -0,0 +1,22 @@
+:- use_module(library(assoc)).
+:- use_module(library(lists)).
+:- use_module(library(iso_ext)).
+:- use_module(library(between)).
+
+p(Idx, Idx-1).
+
+test(N) :- 
+  numlist(N, As),
+  maplist(p, As, Bs),
+  list_to_assoc(Bs, Assoc),
+  is_assoc(Assoc).
+
+run(Max, Bad) :-
+  numlist(Max, Num),
+  findall(N, (member(N, [0|Num]), \+ test(N)), Bad).
+
+?- N = 20, run(N, Bad).
+   Bad = [3,4,6,7,8,9,10,12,13,14,15,16,17,18,19,20], unexpected.
+   N = 20, Bad = [].
+
+test :- run(20, []).
diff --git a/tests/scryer/cli/issues/issue_3048.in/pair_string_key.pl b/tests/scryer/cli/issues/issue_3048.in/pair_string_key.pl
new file mode 100644 (file)
index 0000000..739c7c4
--- /dev/null
@@ -0,0 +1,12 @@
+:- use_module(library(assoc)).
+
+test :-
+  empty_assoc(A1),
+  put_assoc(([a]-1), A1, 1, A2),
+  put_assoc(([a]-2), A2, 1, A3),
+  put_assoc(([b]-1), A3, 1, _).
+  
+
+?- test.
+   false, unexpected.
+   true.
diff --git a/tests/scryer/cli/issues/issue_3048.md b/tests/scryer/cli/issues/issue_3048.md
new file mode 100644 (file)
index 0000000..67fefad
--- /dev/null
@@ -0,0 +1,36 @@
+Bound Variables are sometimes not considered ground even though they should be ground.
+
+```trycmd
+$ scryer-prolog -f --no-add-history original.pl -g test -g halt
+
+```
+
+```trycmd
+$ scryer-prolog -f --no-add-history original_alt.pl -g test -g halt
+
+```
+
+```trycmd
+$ scryer-prolog -f --no-add-history minimize1.pl -g test -g halt
+
+```
+
+```trycmd
+$ scryer-prolog -f --no-add-history minimize_final.pl -g test -g halt
+
+```
+
+```trycmd
+$ scryer-prolog -f --no-add-history pair_string_key.pl -g test -g halt
+
+```
+
+```trycmd
+$ scryer-prolog -f --no-add-history compare.pl -g test -g halt
+
+```
+
+```trycmd
+$ scryer-prolog -f --no-add-history compare_get_assoc.pl -g test -g halt
+
+```
\ No newline at end of file
index c4430400de0ee29fe32b84e4f9fa79085380ebd6..e2ad1b6157490df0b47f6bda023d3a7af202f22b 100644 (file)
@@ -25,6 +25,7 @@ fn cli_tests() {
     cases
         .default_bin_name("scryer-prolog")
         .case("tests/scryer/cli/issues/*.toml")
+        .case("tests/scryer/cli/issues/*.md")
         .case("tests/scryer/cli/src_tests/*.toml")
         .case("tests/scryer/cli/src_tests/*.md");