[m-dev.] test for pragma fact_table

David Matthew OVERTON dmo at students.cs.mu.oz.au
Thu Feb 27 16:56:25 AEDT 1997


Hi,

Could someone (Fergus maybe?) please review these changes.

David.
 
 
Estimated hours taken: 3
 
Added a new test for `pragma fact_table's.

Modified files:

	tests/hard_coded/Mmake:
		Added `pragma_fact_table' to the list of tests.
 
Added files:

	tests/hard_coded/pragma_fact_table.m:
		Test program for `pragma fact_table's.

	tests/hard_coded/pragma_fact_table.exp:
		Expected results from `pragma_fact_table.m'.

	tests/hard_coded/fact.facts:
	tests/hard_coded/fact2.facts:
		Fact table data files used by `pragma_fact_table.m'.

	
 
Index: hard_coded/Mmake
===================================================================
RCS file: /home/staff/zs/imp/tests/hard_coded/Mmake,v
retrieving revision 1.34
diff -u -r1.34 Mmake
--- Mmake	1997/02/26 09:37:07	1.34
+++ Mmake	1997/02/27 01:27:39
@@ -13,7 +13,7 @@
 	cc_nondet_disj bidirectional address_of_builtins \
 	reverse_arith curry curry2 higher_order_syntax \
 	ho_func_reg float_reg write expand ho_solns write_reg1 \
-	ho_univ_to_type elim_special_pred
+	ho_univ_to_type elim_special_pred pragma_fact_table
 
 #-----------------------------------------------------------------------------#
===================================================================
pragma_fact_table.m
===================================================================
 
%  Test `pragma fact_table's.
:- module pragma_fact_table.

:- interface.

:- import_module io.

:- pred main(io__state::di, io__state::uo) is cc_multi.

:- implementation.

:- import_module string, list, std_util.

:- type f ---> f(string, int, float).

main -->
	{ Pred0 = lambda([Out0::out] is nondet, fact(Out0, _, 8.0)) },
	{ Pred1 = lambda([Out1::out] is nondet, fact("ld", -163, Out1)) },

	% test (out, out, in) primary nondet mode
	{ solutions(Pred0, Solutions0) },
	(
		{ Solutions0 = ["foo", "foobar", "ld"] }
	->
		yes
	;
		no
	),

	% test (in, in, out) secondary nondet mode
	{ solutions(Pred1, Solutions1) },
	(
		{ Solutions1 =  [3.14159265358979, 7.0, 8.0] }
	->
		yes
	;
		no
	),

	% test (out, out, out) multidet mode.
	(
		{ get_fact(f("kc", 42, 331.15)) }
	->
		yes
	;
		no
	),

	% test (out, out, out) cc_multi mode.
	{ fact2(A, B, C) },
	(
		{ A = 1, B = 2, C = 3 }
	->
		yes
	;
		no
	),

	% test (in, in, in) semidet mode.
	(
		{ fact2(4, 5, 1) }
	->
		yes
	;
		no
	),
	(
		{ fact2(4, 5, 7) }
	->
		no
	;
		yes
	),

	% test (in, in, out) semidet mode.
	(
		{ fact2(5, 1, X) },
		{ X = 3 }
	->
		yes
	;
		no
	),
	(
		{ fact2(5, 2, _) }
	->
		no
	;
		yes
	).

:- pred fact(string, int, float).
:- mode fact(out, out, in) is nondet.
:- mode fact(in, in, out) is nondet.
:- mode fact(out, out, out) is multi.

:- pragma fact_table(fact/3, "fact.facts").

:- pred fact2(int, int, int).
:- mode fact2(out, out, out) is cc_multi.
:- mode fact2(in, in, in) is semidet.
:- mode fact2(in, in, out) is semidet.

:- pragma fact_table(fact2/3, "fact2.facts").

:- pred get_fact(f::out) is multidet.

get_fact(f(S, I, F)) :- fact(S, I, F).

%--------------------------------------------------------------------------%

:- pred yes(io__state::di, io__state::uo) is det.

yes --> io__write_string("yes\n").

:- pred no(io__state::di, io__state::uo) is det.

no --> io__write_string("no\n").
===================================================================
pragma_fact_table.exp
===================================================================
yes
yes
yes
yes
yes
yes
yes
yes
===================================================================
fact.facts
===================================================================
% Facts for testing `pragma fact_table'

fact("ld", -163, 7.0).
fact("mab", 1, 1.1e-29).
fact("nd", 2, 1.4e57).
fact("kc", 42, 331.15).
fact("ld", -163, 8.0).
fact("foo", 79, 8.0).
fact("foobar", 78, 8.0).
fact("ld", -163, 3.14159265358979).
fact("ld", 178, 0.0).
===================================================================
fact2.facts
===================================================================
% Facts for testing `pragma fact_table'

fact2(1, 2, 3).
fact2(2, 3, 4).
fact2(3, 4, 5).
fact2(4, 5, 1).
fact2(5, 1, 3).



More information about the developers mailing list