[m-rev.] diff 3/3: Add test case for map.equivalent/2

Julien Fischer jfischer at opturion.com
Sun Jun 30 04:37:39 AEST 2013


Hi Paul,

On Fri, 28 Jun 2013, Paul Bone wrote:

> Add test case for map.equivalent/2
>
> tests/general/map_equiv.m:
> tests/general/map_equiv.exp:
>    New test case.

...

> +%------------------------------------------------------------------------------%
> +% map_equiv.m
> +% Paul Bone
> +% vim: ft=mercury ff=unix ts=4 sw=4 et
> +%------------------------------------------------------------------------------%
> +
> +:- module map_equiv.
> +
> +:- interface.
> +
> +:- import_module io.
> +
> +:- pred main(io::di, io::uo) is det.
> +
> +%------------------------------------------------------------------------------%
> +%------------------------------------------------------------------------------%
> +
> +:- implementation.
> +
> +:- import_module list.
> +:- import_module map.
> +:- import_module pair.
> +
> +%------------------------------------------------------------------------------%
> +
> +main(!IO) :-
> +    map.from_assoc_list([1 - 1, 2 - 2, 3 - 3, 5 - 5, 6 - 6,
> +        7 - 7, 9 - 9, 10 - 10], Map1),
> +    test(Map1, Map1, !IO),
> +    set(7, 49, Map1, Map2),
> +    test(Map1, Map2, !IO),
> +
> +    List1 = [1 - 1, 2 - 2, 3 - 3, 4 - 4],
> +    map.from_assoc_list(List1, Map3),
> +    map.from_assoc_list(reverse(List1), Map4),
> +    test(Map3, Map4, !IO),
> +    ( Map3 = Map4 ->
> +        io.write_string("Same structure\n", !IO)
> +    ;
> +        io.write_string("Different structure\n", !IO)
> +    ).
> +
> +:- pred test(map(K, V)::in, map(K, V)::in, io::di, io::uo) is det.
> +
> +test(A, B, !IO) :-
> +    ( equivalent(A, B) ->
> +        io.write_string("Match\n", !IO)
> +    ;
> +        io.write_string("No match\n", !IO)
> +    ).

The above is not a very thorough test, in particular you are missing a
number of boundary conditions:

    <empty>, <empty>
    <empty>, <non-empty>
    <non-empty>, <empty>

Plus the testing$ of the case where both maps are non-empty could (and
should) be more extensive.  (As it is, I'm pretty sure you don't cover
all the execution paths in tree234.equivalent/2 and friends.)

Cheers,
Julien.



More information about the reviews mailing list