[mercury-users] Testing with dependent lists?
Ralph Becket
rafe at csse.unimelb.edu.au
Mon Feb 12 10:07:20 AEDT 2007
doug.auclair at logicaltypes.com, Saturday, 10 February 2007:
> Dear all,
>
> I'm testing the behavior of a 'switch' I've built as a mercury module.
> The switch is on for some preconditions and off for others (and
> is programmable), so I store the on/off answers in an even-length
> list (I cribbed some code from Zoltan that defines such an inst). The
> test is as follows:
>
> -----
>
> :- inst even_len_list(I) ---> []; [I|bound([I|even_len_list(I)])].
> :- mode even_len_list_in(I) == even_len_list(I) >> even_len_list(I).
Note that this mode saves you typing just one character compared to
`in(even_len_list(I))'.
> :- pred for_each_switch(list(switch), list(float), list(float),
> list(float), list(float),
> io, io).
> :- mode for_each_switch(in, in, in, even_len_list_in(ground),
> even_len_list_in(ground), di, uo) is det.
> for_each_switch([], _, _, _, _) --> [].
> for_each_switch([_|_], _, _, [], _) -->
> { error("Answers depend on switches") }.
> for_each_switch([_|_], _, _, _, []) -->
> { error("Expectations depend on switches") }.
These two clauses are not mutually exclusive, which is your problem.
> for_each_switch([N|Ns], OnPres, OffPres, [A1, A2|Rest1], [E1, E2|REst2]) -->
> print("For switch " ++ string(N) ++ ":\n\t"),
> print_test_result(OnPres, A1, E1),
> print_test_result(OffPres, A2, E2),
> for_each_switch(Ns, OnPres, OffPres, Rest1, REst2).
[Please don't use DCGs for passing the IO state! Use state variables.]
-- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list