mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 11:54:02 +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.
133 lines
3.5 KiB
Mathematica
133 lines
3.5 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module test_cord2.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module cord.
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module require.
|
|
:- import_module solutions.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
io.write_string("Test list and rev_list\n", !IO),
|
|
solutions(gen_cord3, Cords),
|
|
list.foldl(test_list_and_rev_list, Cords, !IO),
|
|
|
|
io.write_string("\nTest folds\n", !IO),
|
|
list.foldl(test_folds, Cords, !IO),
|
|
io.write_string("done.\n", !IO),
|
|
|
|
io.write_string("\nTest cord_list_to_cord and cord_list_to_list\n", !IO),
|
|
solutions(gen_cord_list, CordLists),
|
|
list.foldl(test_cord_list_funcs, CordLists, !IO),
|
|
io.write_string("done.\n", !IO).
|
|
|
|
:- pred test_list_and_rev_list(cord(int)::in, io::di, io::uo) is det.
|
|
|
|
test_list_and_rev_list(Cord, !IO) :-
|
|
io.write(Cord, !IO),
|
|
io.nl(!IO),
|
|
|
|
List = list(Cord),
|
|
io.write(List, !IO),
|
|
io.nl(!IO),
|
|
|
|
RevList = rev_list(Cord),
|
|
io.write(RevList, !IO),
|
|
io.nl(!IO),
|
|
|
|
expect(unify(length(List), length(Cord)),
|
|
$module, $pred, "length(List) != length(Cord)"),
|
|
|
|
expect(unify(List, reverse(RevList)),
|
|
$module, $pred, "List != reverse(RevList)").
|
|
|
|
:- pred test_folds((cord(int))::in, io::di, io::uo) is det.
|
|
|
|
test_folds(Cord, !IO) :-
|
|
List = cord.list(Cord),
|
|
RevList = cord.rev_list(Cord),
|
|
|
|
cord.foldl(list.cons, Cord, []) = FoldlResultA,
|
|
cord.foldl_pred(list.cons, Cord, [], FoldlResultB),
|
|
expect(unify(FoldlResultA, RevList), $module, $pred, "foldl wrong"),
|
|
expect(unify(FoldlResultB, RevList), $module, $pred, "foldl_pred wrong"),
|
|
|
|
cord.foldr(list.cons, Cord, []) = FoldrResultA,
|
|
cord.foldr_pred(list.cons, Cord, [], FoldrResultB),
|
|
expect(unify(FoldrResultA, List), $module, $pred, "foldr wrong"),
|
|
expect(unify(FoldrResultB, List), $module, $pred, "foldr_pred wrong").
|
|
|
|
:- pred test_cord_list_funcs(list(cord(int))::in, io::di, io::uo) is det.
|
|
|
|
test_cord_list_funcs(Cords, !IO) :-
|
|
List1 = cord_list_to_list(Cords),
|
|
List2 = list(cord_list_to_cord(Cords)),
|
|
List3 = condense(map(list, Cords)),
|
|
expect(unify(List1, List2), $module, $pred, "List1 != List2"),
|
|
expect(unify(List1, List3), $module, $pred, "List1 != List3").
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pred gen_cord1(cord(int)::out) is multi.
|
|
|
|
gen_cord1(empty).
|
|
gen_cord1(singleton(1)).
|
|
gen_cord1(from_list([2, 3, 4])).
|
|
|
|
:- pred gen_cord2(cord(int)::out) is multi.
|
|
|
|
gen_cord2(C) :-
|
|
(
|
|
gen_cord1(C)
|
|
;
|
|
gen_cord1(A),
|
|
gen_cord1(B),
|
|
C = A ++ B
|
|
).
|
|
|
|
:- pred gen_cord3(cord(int)::out) is multi.
|
|
|
|
gen_cord3(C) :-
|
|
(
|
|
gen_cord2(C)
|
|
;
|
|
gen_cord2(A),
|
|
gen_cord2(B),
|
|
C = A ++ B
|
|
).
|
|
|
|
:- pred gen_cord_list(list(cord(int))::out) is multi.
|
|
|
|
gen_cord_list(L) :-
|
|
(
|
|
L = []
|
|
;
|
|
gen_cord2(A),
|
|
(
|
|
L = [A]
|
|
;
|
|
gen_cord2(B),
|
|
(
|
|
L = [A, B]
|
|
;
|
|
gen_cord2(C),
|
|
L = [A, B, C]
|
|
)
|
|
)
|
|
).
|