[m-rev.] Addendum: state vars test case.

Ralph Becket rafe at cs.mu.OZ.AU
Tue Apr 9 12:03:45 AEST 2002


Estimated hours taken: 1
Branches: main

tests/general/Mmakefile:
tests/general/state_vars_tests.m:
tests/general/state_vars_tests.exp:
	Added test case for the state variable transformation.

Index: Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/general/Mmakefile,v
retrieving revision 1.39
diff -u -r1.39 Mmakefile
--- Mmakefile	26 Feb 2002 02:52:33 -0000	1.39
+++ Mmakefile	9 Apr 2002 02:00:00 -0000
@@ -61,6 +61,7 @@
 		read_line_as_string \
 		semidet_map \
 		set_test \
+		state_vars_tests \
 		string_format_test \
 		string_format_test_2 \
 		string_format_test_3 \
Index: state_vars_tests.exp
===================================================================
RCS file: state_vars_tests.exp
diff -N state_vars_tests.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ state_vars_tests.exp	9 Apr 2002 01:54:57 -0000
@@ -0,0 +1 @@
+[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]
Index: state_vars_tests.m
===================================================================
RCS file: state_vars_tests.m
diff -N state_vars_tests.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ state_vars_tests.m	9 Apr 2002 01:58:56 -0000
@@ -0,0 +1,179 @@
+%------------------------------------------------------------------------------%
+% state_vars_tests.m
+% Ralph Becket <rafe at cs.mu.oz.au>
+% Wed Apr  3 14:19:02 EST 2002
+% vim: ft=mercury ff=unix ts=4 sw=4 et wm=0 tw=0
+%
+%------------------------------------------------------------------------------%
+
+:- module foo.
+
+:- interface.
+
+:- import_module io.
+
+
+
+:- pred main(io::di, io::uo) is cc_multi.
+
+%------------------------------------------------------------------------------%
+%------------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module std_util, string, int, list.
+
+%------------------------------------------------------------------------------%
+
+main(!IO) :-
+    unsorted_solutions(test, S),
+    io__print(list__reverse(S) `with_type` list(int), !IO),
+    io__nl(!IO).
+
+%------------------------------------------------------------------------------%
+
+:- pred add(int::in, int::in, int::out) is det.
+
+add(N, X, X + N).
+
+:- pred t(int::in, int::out) is semidet.
+
+t(!X) :-
+    !:X = !.X + 1.
+
+:- pred f(int::in, int::out) is semidet.
+
+f(!X) :-
+    X0  = !.X,
+    !:X = !.X + 1,
+    !.X = X0.
+
+:- func fn_a(int, int) = int.
+
+fn_a(N, !.X) = !:X :-
+    !:X = !.X + N.
+
+:- func fn_b(int, int) = int.
+
+fn_b(N, !.X) = !.X + N.
+
+%------------------------------------------------------------------------------%
+
+:- pred test(int::out) is multi.
+
+test(X) :- add(1, 0, X).
+
+test(X) :- add(2, 0, !:A), X = !.A.
+
+test(X) :- !:A = 0, add(3, !A), X = !.A.
+
+test(X) :- !:A = 4, not fail, X = !.A.
+
+test(X) :- !:A = 5, not (add(1, !A), !.A = 5), X = !.A.
+
+test(X) :- !:A = 1, !:B = 1, add(1, !A), add(2, !B), X = !.A * !.B.
+
+test(X) :- ( if true then !:A = 7 else !:A = -1 ), X = !.A.
+
+test(X) :- ( if fail then !:A = -1 else !:A = 8 ), X = !.A.
+
+test(X) :- !:A = 0, ( if t(!.A, _) then !:A = 9 else !:A = -1 ), X = !.A.
+
+test(X) :- !:A = 0, ( if f(!.A, _) then !:A = -1 else !:A = 10 ), X = !.A.
+
+test(X) :-
+    !:A = 0,
+    ( if ( f(!A) ; t(!A) ), !.A = 1 then !:A = 11 else !:A = -1 ),
+    X   = !.A.
+
+test(X) :-
+    !:A = 0,
+    ( if ( t(!A) ; f(!A) ), !.A = 1 then !:A = 12 else !:A = -1 ),
+    X   = !.A.
+
+test(X) :-
+    !:A = 0,
+    ( add(13, !A) ; add(14, !A) ),
+    X   = !.A.
+
+test(X) :-
+    !:A = 1,
+    !:B = 1,
+    ( add(14, !A) ; add(15, !B) ),
+    X   = !.A * !.B.
+
+test(X) :-
+    !.A = 0,
+    !:A = fn_a(17, !.A),
+    X   = !.A.
+
+test(X) :-
+    !.A = 0,
+    !:A = fn_b(18, !.A),
+    X   = !.A.
+
+test(X) :-
+    !.A = 0,
+    F   = ( func(!.B) = !:B :- !:B = !.B + 19 ),
+    !:A = F(!.A),
+    X   = !.A.
+
+test(X) :-
+    !.A = 0,
+    F   = ( func(!.B) = !.B + 20 ),
+    !:A = F(!.A),
+    X   = !.A.
+
+test(X) :-
+    !.A = 0,
+    F   = ( func(!.A) = !:A :- !:A = !.A + 21 ),
+    !:A = F(!.A),
+    X   = !.A.
+
+test(X) :-
+    !.A = 0,
+    F   = ( func(!.A) = !.A + 22 ),
+    !:A = F(!.A),
+    X   = !.A.
+
+test(X) :-
+    !.A = 0,
+    P   = ( pred(!.B :: in, !:B :: out) is det :- !:B = !.B + 23 ),
+    P(!A),
+    X   = !.A.
+
+test(X) :-
+    !.A = 0,
+    P   = ( pred(!.B :: in, (!.B + 24) :: out) is det ),
+    P(!A),
+    X   = !.A.
+
+test(X) :-
+    !.A = 0,
+    P   = ( pred(!.A :: in, !:A :: out) is det :- !:A = !.A + 25 ),
+    P(!A),
+    X   = !.A.
+
+test(X) :-
+    !.A = 0,
+    P   = ( pred(!.A :: in, (!.A + 26) :: out) is det ),
+    P(!A),
+    X   = !.A.
+
+test(!:A * !:B) :-
+    !.A = 2,
+    add(1, !A),
+    !.B = 8,
+    add(1, !B).
+
+    % The compiler correctly rejects the following:
+    %
+% test(X) :-
+%     !.A = 0,
+%     F   = ( func(!.B) = !.B + !.A ),
+%     !:A = F(!.A),
+%     X   = !.A.
+
+%------------------------------------------------------------------------------%
+%------------------------------------------------------------------------------%
+
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list