mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 04:43:53 +00:00
tests/accumulator/*.m:
tests/analysis_*/*.m:
tests/benchmarks*/*.m:
tests/debugger*/*.{m,exp,inp}:
tests/declarative_debugger*/*.{m,exp,inp}:
tests/dppd*/*.m:
tests/exceptions*/*.m:
tests/general*/*.m:
tests/grade_subdirs*/*.m:
tests/hard_coded*/*.m:
Make these tests use four-space indentation, and ensure that
each module is imported on its own line. (I intend to use the latter
to figure out which subdirectories' tests can be executed in parallel.)
These changes usually move code to different lines. For the debugger tests,
specify the new line numbers in .inp files and expect them in .exp files.
57 lines
1.3 KiB
Mathematica
57 lines
1.3 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
:- module promise_equivalent_clauses.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list.
|
|
:- import_module solutions.
|
|
|
|
main(!IO) :-
|
|
SortedList = [1, 2, 3],
|
|
solutions(rev_sort(SortedList), RawLists),
|
|
list.foldl(test, RawLists, !IO).
|
|
|
|
:- pred test(list(T)::in, io::di, io::uo) is det.
|
|
|
|
test(RawList, !IO) :-
|
|
io.write(RawList, !IO),
|
|
io.write_string(" ", !IO),
|
|
rsort(RawList, SortedList),
|
|
io.write(SortedList, !IO),
|
|
io.nl(!IO).
|
|
|
|
:- pred rev_sort(list(T)::in, list(T)::out) is nondet.
|
|
|
|
rev_sort(SortedList, RawList) :-
|
|
rsort(RawList, SortedList).
|
|
|
|
:- pred rsort(list(T), list(T)).
|
|
:- mode rsort(in, out) is det.
|
|
:- mode rsort(out, in) is nondet.
|
|
:- pragma promise_equivalent_clauses(rsort/2).
|
|
|
|
rsort(Raw::in, Sorted::out) :-
|
|
list.sort(Raw, Sorted).
|
|
|
|
rsort(Raw::out, Sorted::in) :-
|
|
is_sorted(Sorted),
|
|
list.perm(Sorted, Raw).
|
|
|
|
:- pred is_sorted(list(T)::in) is semidet.
|
|
|
|
is_sorted([]).
|
|
is_sorted([_]).
|
|
is_sorted([A, B | Rest]) :-
|
|
compare(R, A, B),
|
|
( R = (<) ; R = (=) ),
|
|
is_sorted([B | Rest]).
|