Files
mercury/tests/hard_coded/test_cord3.m
Julien Fischer 5f5c67b281 Add more operations on cords.
library/cord.m:
    Add is_singleton/2, foldr2/6 and foldr3/8.

NEWS:
     Announce the above additions.

tests/hard_coded/Mmakefile:
tests/hard_coded/test_cord3.{m,exp}:
     Add a test of is_singleton/2 (and is_empty/1).
2022-06-07 16:37:45 +10:00

64 lines
2.0 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module test_cord3.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module cord.
:- import_module list.
:- import_module pair.
:- import_module string.
%---------------------------------------------------------------------------%
main(!IO) :-
list.foldl(test_is_empty, test_cords, !IO),
io.nl(!IO),
list.foldl(test_is_singleton, test_cords, !IO).
%---------------------------------------------------------------------------%
:- pred test_is_empty(pair(string, cord(int))::in, io::di, io::uo) is det.
test_is_empty(Name - Cord, !IO) :-
Result = ( if cord.is_empty(Cord) then "empty" else "not empty" ),
io.format("%s is %s.\n", [s(Name), s(Result)], !IO).
%---------------------------------------------------------------------------%
:- pred test_is_singleton(pair(string, cord(int))::in, io::di, io::uo) is det.
test_is_singleton(Name - Cord, !IO) :-
( if cord.is_singleton(Cord, Result) then
io.format("%s is a singleton with element %d.\n",
[s(Name), i(Result)], !IO)
else
io.format("%s is not a singleton.\n", [s(Name)], !IO)
).
%---------------------------------------------------------------------------%
:- func test_cords = list(pair(string, cord(int))).
test_cords = [
"Empty" - cord.empty,
"Singleton1" - cord.singleton(1),
"Singleton2" - cord.from_list([2]),
"NonSingleton1" - cord.from_list([3, 4]),
"NonSingleton2" - (cord.singleton(5) ++ cord.singleton(6))
].
%---------------------------------------------------------------------------%
:- end_module test_cord3.
%---------------------------------------------------------------------------%