Files
mercury/tests/hard_coded/list_split_take_drop.exp
Julien Fischer 9961043a2c Make split_list/4, drop/3 and take/3 consistent.
Improve documentation and test coverage for the same.

library/list.m:
    Change the behaviour of take/3 and drop/3 so they fail if their
    first argument is negative.  This makes them consistent with
    the behaviour of split_list/4 and is arguably less surprising than
    their current behaviour.

    Make split_list/4 more efficient by not doing two comparison
    operations per recursive call.

    Re-implement det_drop/3 in terms of drop/3.

    Fix the documentation of the failure condition of split_list/4,
    take/3 and drop/3; all three omitted the description of what
    happens if their first argument is negative.

    Use 'N' rather than 'Len' for the name of the first argument
    in the comments describing the above predicates; the latter
    is ambiguous.

NEWS:
    Announce the change in behaviour of take/3 and drop/3.

tests/hard_coded/list_split_take_drop.{m,exp}:
     Test the behaviour of the above predicates and also check that the
     expected relationships between them hold.

tests/hard_coded/Mmakefile:
      Add the new test.
2016-06-04 23:02:38 +10:00

77 lines
2.0 KiB
Plaintext

split_list(int.min_int, []) ===> <<FALSE>>
drop(int.min_int, []) ===> <<FALSE>>
take(int.min_int, []) ===> <<FALSE>>
split_list(int.min_int, [111]) ===> <<FALSE>>
drop(int.min_int, [111]) ===> <<FALSE>>
take(int.min_int, [111]) ===> <<FALSE>>
split_list(int.min_int, [111, 222]) ===> <<FALSE>>
drop(int.min_int, [111, 222]) ===> <<FALSE>>
take(int.min_int, [111, 222]) ===> <<FALSE>>
split_list(-1, []) ===> <<FALSE>>
drop(-1, []) ===> <<FALSE>>
take(-1, []) ===> <<FALSE>>
split_list(-1, [111]) ===> <<FALSE>>
drop(-1, [111]) ===> <<FALSE>>
take(-1, [111]) ===> <<FALSE>>
split_list(-1, [111, 222]) ===> <<FALSE>>
drop(-1, [111, 222]) ===> <<FALSE>>
take(-1, [111, 222]) ===> <<FALSE>>
split_list(0, []) ===> ([], [])
drop(0, []) ===> []
take(0, []) ===> []
split_list(0, [111]) ===> ([], [111])
drop(0, [111]) ===> [111]
take(0, [111]) ===> []
split_list(0, [111, 222]) ===> ([], [111, 222])
drop(0, [111, 222]) ===> [111, 222]
take(0, [111, 222]) ===> []
split_list(1, []) ===> <<FALSE>>
drop(1, []) ===> <<FALSE>>
take(1, []) ===> <<FALSE>>
split_list(1, [111]) ===> ([111], [])
drop(1, [111]) ===> []
take(1, [111]) ===> [111]
split_list(1, [111, 222]) ===> ([111], [222])
drop(1, [111, 222]) ===> [222]
take(1, [111, 222]) ===> [111]
split_list(2, []) ===> <<FALSE>>
drop(2, []) ===> <<FALSE>>
take(2, []) ===> <<FALSE>>
split_list(2, [111]) ===> <<FALSE>>
drop(2, [111]) ===> <<FALSE>>
take(2, [111]) ===> <<FALSE>>
split_list(2, [111, 222]) ===> ([111, 222], [])
drop(2, [111, 222]) ===> []
take(2, [111, 222]) ===> [111, 222]
split_list(2, [111, 222, 333]) ===> ([111, 222], [333])
drop(2, [111, 222, 333]) ===> [333]
take(2, [111, 222, 333]) ===> [111, 222]
split_list(int.max_int, []) ===> <<FALSE>>
drop(int.max_int, []) ===> <<FALSE>>
take(int.max_int, []) ===> <<FALSE>>
split_list(int.max_int, [111]) ===> <<FALSE>>
drop(int.max_int, [111]) ===> <<FALSE>>
take(int.max_int, [111]) ===> <<FALSE>>
split_list(int.max_int, [111, 222]) ===> <<FALSE>>
drop(int.max_int, [111, 222]) ===> <<FALSE>>
take(int.max_int, [111, 222]) ===> <<FALSE>>