Update the style of some tests.

This commit is contained in:
Zoltan Somogyi
2019-06-18 00:08:10 +02:00
parent 0c1068ef56
commit 15df6f9323
2 changed files with 57 additions and 55 deletions

View File

@@ -6,6 +6,7 @@
% whose conditions include nondet disjunctions, looking for problems caused % whose conditions include nondet disjunctions, looking for problems caused
% by the disjunction's clobbering some of the same redoip/redofr slots used % by the disjunction's clobbering some of the same redoip/redofr slots used
% for the soft cut in the if-then-else. % for the soft cut in the if-then-else.
%
:- module semi_fail_in_non_ite. :- module semi_fail_in_non_ite.
@@ -13,7 +14,7 @@
:- import_module io. :- import_module io.
:- pred main(io__state::di, io__state::uo) is det. :- pred main(io::di, io::uo) is det.
:- implementation. :- implementation.
@@ -21,9 +22,9 @@
:- import_module list. :- import_module list.
:- import_module solutions. :- import_module solutions.
main --> main(!IO) :-
{ solutions(p1, Xs1) }, solutions(p1, Xs1),
print_list(Xs1). print_list(Xs1, !IO).
:- pred p1(int::out) is nondet. :- pred p1(int::out) is nondet.
@@ -43,10 +44,13 @@ p3(X) :-
:- pred p(int::in, int::out) is nondet. :- pred p(int::in, int::out) is nondet.
p(A, X) :- p(A, X) :-
% The first if-then-else can hijack the redoip/redofr slots % The first if-then-else can hijack the redoip/redofr slots of p's frame.
% of p's frame.
( if ( if
some [B] ( q(A, B) ; r(A, B) ) some [B] (
q(A, B)
;
r(A, B)
)
then then
C = B * 10 C = B * 10
% s(B, C) % s(B, C)
@@ -55,8 +59,8 @@ p(A, X) :-
% s(A, C) % s(A, C)
), ),
% The second if-then-else cannot hijack the redoip/redofr slots % The second if-then-else cannot hijack the redoip/redofr slots
% of p's frame, since this may not be (and usually won't be) % of p's frame, since this may not be (and usually won't be) on top
% on top when execution gets here. % when execution gets here.
( if ( if
some [D] ( some [D] (
q(C, D) q(C, D)
@@ -102,31 +106,28 @@ s(F, G) :-
G = 10 * F + 1 G = 10 * F + 1
). ).
:- pred print_list(list(int), io__state, io__state). :- pred print_list(list(int)::in, io::di, io::uo) is det.
:- mode print_list(in, di, uo) is det.
print_list(Xs) --> print_list(Xs, !IO) :-
( (
{ Xs = [] } Xs = [],
-> io.write_string("[]\n", !IO)
io__write_string("[]\n")
; ;
io__write_string("["), Xs = [_ | _],
print_list_2(Xs), io.write_string("[", !IO),
io__write_string("]\n") print_list_2(Xs, !IO),
io.write_string("]\n", !IO)
). ).
:- pred print_list_2(list(int), io__state, io__state). :- pred print_list_2(list(int)::in, io::di, io::uo) is det.
:- mode print_list_2(in, di, uo) is det.
print_list_2([]) --> []. print_list_2([], !IO).
print_list_2([X | Xs]) --> print_list_2([X | Xs], !IO) :-
io__write_int(X), io.write_int(X, !IO),
( (
{ Xs = [] } Xs = []
->
[]
; ;
io__write_string(", "), Xs = [_ | _],
print_list_2(Xs) io.write_string(", ", !IO),
print_list_2(Xs, !IO)
). ).

View File

@@ -9,6 +9,7 @@
% Unfortunately, we cannot just specify --use-trail for semi_fail_in_non_ite % Unfortunately, we cannot just specify --use-trail for semi_fail_in_non_ite
% in tests/general, since that would cause a link error in the usual case % in tests/general, since that would cause a link error in the usual case
% that the runtime being linked with is not in a trailing grade. % that the runtime being linked with is not in a trailing grade.
%
:- module semi_fail_in_non_ite. :- module semi_fail_in_non_ite.
@@ -24,9 +25,9 @@
:- import_module list. :- import_module list.
:- import_module solutions. :- import_module solutions.
main --> main(!IO) :-
{ solutions(p1, Xs1) }, solutions(p1, Xs1),
print_list(Xs1). print_list(Xs1, !IO).
:- pred p1(int::out) is nondet. :- pred p1(int::out) is nondet.
@@ -46,10 +47,13 @@ p3(X) :-
:- pred p(int::in, int::out) is nondet. :- pred p(int::in, int::out) is nondet.
p(A, X) :- p(A, X) :-
% The first if-then-else can hijack the redoip/redofr slots % The first if-then-else can hijack the redoip/redofr slots of p's frame.
% of p's frame.
( if ( if
some [B] ( q(A, B) ; r(A, B) ) some [B] (
q(A, B)
;
r(A, B)
)
then then
C = B * 10 C = B * 10
% s(B, C) % s(B, C)
@@ -58,8 +62,8 @@ p(A, X) :-
% s(A, C) % s(A, C)
), ),
% The second if-then-else cannot hijack the redoip/redofr slots % The second if-then-else cannot hijack the redoip/redofr slots
% of p's frame, since this may not be (and usually won't be) % of p's frame, since this may not be (and usually won't be) on top
% on top when execution gets here. % when execution gets here.
( if ( if
some [D] ( some [D] (
q(C, D) q(C, D)
@@ -105,31 +109,28 @@ s(F, G) :-
G = 10 * F + 1 G = 10 * F + 1
). ).
:- pred print_list(list(int), io__state, io__state). :- pred print_list(list(int)::in, io::di, io::uo) is det.
:- mode print_list(in, di, uo) is det.
print_list(Xs) --> print_list(Xs, !IO) :-
( (
{ Xs = [] } Xs = [],
-> io.write_string("[]\n", !IO)
io__write_string("[]\n")
; ;
io__write_string("["), Xs = [_ | _],
print_list_2(Xs), io.write_string("[", !IO),
io__write_string("]\n") print_list_2(Xs, !IO),
io.write_string("]\n", !IO)
). ).
:- pred print_list_2(list(int), io__state, io__state). :- pred print_list_2(list(int)::in, io::di, io::uo) is det.
:- mode print_list_2(in, di, uo) is det.
print_list_2([]) --> []. print_list_2([], !IO).
print_list_2([X | Xs]) --> print_list_2([X | Xs], !IO) :-
io__write_int(X), io.write_int(X, !IO),
( (
{ Xs = [] } Xs = []
->
[]
; ;
io__write_string(", "), Xs = [_ | _],
print_list_2(Xs) io.write_string(", ", !IO),
print_list_2(Xs, !IO)
). ).