Files
mercury/tests/hard_coded/comparison.m
Julien Fischer 1f6d83692a Update programming style in tests/hard_coded.
tests/hard_coded/*.m:
    Update programming style, unless doing so would change
    the meaning of the test, in particular:

    - use '.' as a module qualifier in place of '__'
    - use {write,print}_line where appropriate
    - use if-then-else in place of C -> T ; E
    - use state variables in place of DCGs

tests/hard_coded/dir_test.m:
    Document what the expected outputs correspond to.

    Use a uniform module qualifier in the output.

tests/hard_coded/dir_test.exp*:
    Conform to the above change.
2021-01-07 13:58:12 +11:00

80 lines
2.3 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% This is a test to check the correctness of the way we handle specialized
% comparison predicates for types with three or fewer function symbols.
:- module comparison.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module exception.
:- import_module list.
:- import_module std_util.
:- type t1
---> a1(int, int).
:- type t2
---> a2(int, int)
; b2(int).
:- type t3
---> a3(int, int)
; b3(int)
; c3.
main(!IO) :-
perform_comparison_test(a1(10, 20), a1(10, 21), !IO),
perform_comparison_test(a1(10, 20), a1(10, 20), !IO),
perform_comparison_test(a1(10, 20), a1( 9, 20), !IO),
perform_comparison_test(a2(10, 20), a2(10, 19), !IO),
perform_comparison_test(a2(10, 20), a2(10, 20), !IO),
perform_comparison_test(a2(10, 20), a2(11, 20), !IO),
perform_comparison_test(a2(10, 20), b2(10), !IO),
perform_comparison_test(b2(30), a2(50, 40), !IO),
perform_comparison_test(b2(30), b2(29), !IO),
perform_comparison_test(b2(30), b2(30), !IO),
perform_comparison_test(b2(30), b2(31), !IO),
perform_comparison_test(a3(10, 20), a3(10, 19), !IO),
perform_comparison_test(a3(10, 20), a3(10, 20), !IO),
perform_comparison_test(a3(10, 20), a3(11, 20), !IO),
perform_comparison_test(a3(10, 20), b3(10), !IO),
perform_comparison_test(a3(10, 20), c3, !IO),
perform_comparison_test(b3(30), a3(50, 40), !IO),
perform_comparison_test(b3(30), b3(29), !IO),
perform_comparison_test(b3(30), b3(30), !IO),
perform_comparison_test(b3(30), b3(31), !IO),
perform_comparison_test(b3(30), c3, !IO),
perform_comparison_test(c3, a3(50, 40), !IO),
perform_comparison_test(c3, b3(50), !IO),
perform_comparison_test(c3, c3, !IO).
:- pred perform_comparison_test(T::in, T::in, io::di, io::uo) is det.
perform_comparison_test(X, Y, !IO) :-
compare(R, X, Y),
io.write(X, !IO),
(
R = (<),
io.write_string(" < ", !IO)
;
R = (=),
io.write_string(" = ", !IO)
;
R = (>),
io.write_string(" > ", !IO)
),
io.write_line(Y, !IO).