add tests for issue 3048
This commit is contained in:
8
tests/scryer/cli/issues/issue_3048.in/compare.pl
Normal file
8
tests/scryer/cli/issues/issue_3048.in/compare.pl
Normal file
@@ -0,0 +1,8 @@
|
||||
:- use_module(library(format)).
|
||||
|
||||
|
||||
test :- compare(_, ("0"-'2'), ("1"-'1')).
|
||||
|
||||
?- test.
|
||||
false, unexpected.
|
||||
true.
|
||||
12
tests/scryer/cli/issues/issue_3048.in/compare_get_assoc.pl
Normal file
12
tests/scryer/cli/issues/issue_3048.in/compare_get_assoc.pl
Normal file
@@ -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.
|
||||
39
tests/scryer/cli/issues/issue_3048.in/minimize1.pl
Normal file
39
tests/scryer/cli/issues/issue_3048.in/minimize1.pl
Normal file
@@ -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.
|
||||
6
tests/scryer/cli/issues/issue_3048.in/minimize_final.pl
Normal file
6
tests/scryer/cli/issues/issue_3048.in/minimize_final.pl
Normal file
@@ -0,0 +1,6 @@
|
||||
a(t(K),K) :- ground(K).
|
||||
|
||||
test :- a(t(3), M), M=M.
|
||||
|
||||
?- test.
|
||||
true.
|
||||
24
tests/scryer/cli/issues/issue_3048.in/original.pl
Normal file
24
tests/scryer/cli/issues/issue_3048.in/original.pl
Normal file
@@ -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, []).
|
||||
22
tests/scryer/cli/issues/issue_3048.in/original_alt.pl
Normal file
22
tests/scryer/cli/issues/issue_3048.in/original_alt.pl
Normal file
@@ -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, []).
|
||||
12
tests/scryer/cli/issues/issue_3048.in/pair_string_key.pl
Normal file
12
tests/scryer/cli/issues/issue_3048.in/pair_string_key.pl
Normal file
@@ -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.
|
||||
Reference in New Issue
Block a user