Skip to content

Commit 9c5bdb1

Browse files
committed
Remove bad test and add more unit tests
1 parent c399d46 commit 9c5bdb1

File tree

1 file changed

+54
-22
lines changed

1 file changed

+54
-22
lines changed

src/tests/reif.pl

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
:- use_module(library(lists)).
55
:- use_module(library(dif)).
66
:- use_module(library(loader)).
7+
:- use_module(library(format)).
78
:- use_module(test_framework).
89

9-
% Those tests are just sanity checks – examples from the paper, to make sure
10-
% I haven't messed up.
10+
/*
11+
Those tests are just sanity checks – examples from the paper, to make sure I
12+
haven't messed up.
13+
*/
1114
test("indexing dif/2 p6#1", (
1215
findall(X-Fs, tfilter(=(X),[1,2,3,2,3,3],Fs), [1-[1], 2-[2,2], 3-[3,3,3], Y-[]]),
1316
maplist(dif(Y), [1,2,3])
@@ -45,30 +48,59 @@
4548
X == Y
4649
)).
4750

48-
% This test fails, and I don't know if goal_expanded/2 should be recursive or not,
49-
% and what properties it shall maintain (is idempotence even desirable?).
50-
%test("second expansion doesnt modify goal", (
51-
% findall(G==Gxx, test_expand_goal_twice(G,Gxx), Goals),
52-
% maplist(call, Goals)
53-
%)).
51+
/*
52+
Following tests capture current results of goal expansion
53+
TODO: Investigate if if_/3 can be further expanded, and if it will be beneficial
54+
*/
55+
test("goal_expansion (=)", (
56+
subsumes_full_expansion(if_(1=2,a,b), (
57+
1 \= 2 -> b
58+
; 1 == 2 -> a
59+
; 1 = 2, a
60+
; dif(1,2), b)))).
5461

55-
test("ge1", (
56-
loader:goal_expansion(if_(1=2,false,true), reif_tests, _)
57-
)).
62+
test("goal_expansion (;)", (
63+
subsumes_full_expansion(if_((1=2;3=3),a,b), (
64+
1 \= 2 -> if_(3=3,a,b)
65+
; 1 == 2 -> a
66+
; 1 = 2, a
67+
; dif(1,2), if_(3=3,a,b))))).
68+
69+
test("goal_expansion (,)", (
70+
subsumes_full_expansion(if_((1=2,3=3),a,b), (
71+
1 \= 2 -> b
72+
; 1 == 2 -> if_(3=3,a,b)
73+
; 1 = 2, if_(3=3,a,b)
74+
; dif(1,2), b)))).
75+
76+
test("goal_expansion memberd_t", (
77+
subsumes_full_expansion(if_(memberd_t(f,"abcdefgh"),t,f), (
78+
call(memberd_t(f,"abcdefgh"),A),
79+
( A == true -> t
80+
; A == false -> f
81+
; nonvar(A) -> throw(error(type_error(boolean,A),_))
82+
; throw(error(instantiation_error,_))))))).
83+
84+
test("goal_expansion cond_t", (
85+
subsumes_full_expansion(if_(cond_t(a,b),t,f), (
86+
call(cond_t(a,b),A),
87+
( A == true -> t
88+
; A == false -> f
89+
; nonvar(A) -> throw(error(type_error(boolean,A),_))
90+
; throw(error(instantiation_error,_))))))).
5891

59-
test_expand_goal_twice(G, Gxx) :-
60-
test_goal(G),
61-
reif:goal_expanded(G,Gx),
62-
reif:goal_expanded(Gx, Gxx).
92+
% Expand goal until fix point is found
93+
full_expansion(G, X) :-
94+
user:goal_expansion(G, Gx) -> full_expansion(Gx, X); G = X.
6395

64-
test_goal(_).
65-
test_goal(call(a)).
66-
test_goal(call(a:b(1))).
67-
test_goal(call(a:b,c)).
68-
test_goal(call(call(a))).
69-
test_goal(call(call(a:b))).
96+
% X is more general than fully expanded goal G
97+
subsumes_full_expansion(G, X) :-
98+
full_expansion(G, Y),
99+
subsumes_term(X, Y).
70100

71-
% Extra predicates from the paper
101+
/*
102+
Extra predicates from the paper
103+
*/
72104
duplicate(X, Xs) :-
73105
tfilter(=(X), Xs, [_,_|_]).
74106

0 commit comments

Comments
 (0)