mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 12:53:47 +00:00
tests/hard_coded/*.m:
Rename modules as mentioned above.
In a few cases, where the main module's name itself had a suffix,
such as "_mod_a" or "_main", remove that suffix. This entails
renaming the .exp file as well. (In some cases, this meant that
the name of a helper module was "taken over" by the main module
of the test case.)
Update all references to the moved modules.
General updates to programming style, such as
- replacing DCG notation with state var notation
- replacing (C->T;E) with (if C then T else E)
- moving pred/func declarations to just before their code
- replacing io.write/io.nl sequences with io.write_line
- replacing io.print/io.nl sequences with io.print_line
- fixing too-long lines
- fixing grammar errors in comments
tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
Update all references to the moved modules.
Enable the constant_prop_int test case. The fact that it wasn't enabled
before is probably an accident. (When constant_prop_int.m was created,
the test case was added to a list in the Mmakefile, but that list
was later removed due to never being referenced.)
tests/hard_coded/constant_prop_int.{m,exp}:
Delete the calls to shift operations with negative shift amounts,
since we have added a compile-time error for these since the test
was originally created.
130 lines
3.4 KiB
Mathematica
130 lines
3.4 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_line(Cord, !IO),
|
|
|
|
List = list(Cord),
|
|
io.write_line(List, !IO),
|
|
|
|
RevList = rev_list(Cord),
|
|
io.write_line(RevList, !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]
|
|
)
|
|
)
|
|
).
|