1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2% Tests for list-related predicates (non-ISO)
    3
    4%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    5
    6
    7%
    8% List of test suites
    9%
   10
   11test_suites([test_member, test_append, test_length, test_reverse]).
   12
   13
   14%
   15% member/2 test
   16% - non-ISO -
   17%
   18
   19test_member_1 :- member(c, [a, b, c]).
   20test_member_2 :- member(z, [a, b, c]).
   21test_member_3(X) :- member(X, [a, b, c]).
   22test_member_4 :- member(_, [a, b, c]).
   23test_member_5(X) :- member(X, [_, _, _]).
   24test_member_6 :- member([a, c], [[a, x], [a, c], [a, z]]).
   25test_member_7(L) :- member(1, L).
   26
   27throws_exception(test_member_7). % Infinite solutions
   28
   29
   30%
   31% append/3 test
   32% - non-ISO -
   33%
   34
   35test_append_1 :- append([a, b], [c, d], [a, b, c, d]).
   36test_append_2(X) :- append(X, [c, d], [a, b, c, d]).
   37test_append_3(X) :- append([a, b], X, [a, b, c, d]).
   38test_append_4(X, Y) :- append(X, Y, [a, b, c, d]).
   39test_append_5(Z) :- append([a, b], [c, d], Z).
   40test_append_6(X) :- append(X, [c, d], [_, _, c, d]).
   41test_append_7(Y) :- append([a, b], Y, [a, b, _, _]).
   42test_append_8(X) :- append([x, y], X, [a, b, c, d]).
   43test_append_9(X) :- append(X, [x, y], [a, b, c, d]).
   44test_append_10(X, Y) :- append(X, Y, [_, _, _, _]).
   45test_append_11(X, Y) :- append(X, Y, [_, _|[_, _]]).
   46test_append_12 :- append([], [], []).
   47test_append_13(X) :- append([1, 2], X, [1, 2]).
   48test_append_14(L) :- append([], [], L).
   49test_append_15(I1, I2) :- append([a, I1], [c, d], [a, b, I2, d]).
   50test_append_16(X, Y, Z) :- append(X, Y, Z).
   51test_append_17(X, Z) :- append(X, [1, 2], Z).
   52
   53throws_exception(test_append_16). % Infinite solutions
   54throws_exception(test_append_17). % Infinite solutions
   55
   56
   57%
   58% length/2 test
   59% - non-ISO -
   60%
   61
   62test_length_1 :- length([a, b, c, d], 4).
   63test_length_2(X) :- length([a, b, c, d], X).
   64test_length_3(L) :- length(L, 4).
   65test_length_4(T) :- length([a, b|T], 4).
   66test_length_5(L, X) :- length(L, X).
   67test_length_6 :- length([a, b], foo).
   68test_length_7 :- length([a, b], 2.5).
   69test_length_8 :- length(foo, 2).
   70
   71throws_exception(test_length_5). % Infinite solutions
   72throws_exception(test_length_6).
   73throws_exception(test_length_7).
   74throws_exception(test_length_8).
   75
   76
   77%
   78% reverse/2 test
   79% - non-ISO -
   80%
   81
   82test_reverse_1 :- reverse([a, b, c], [c, b, a]).
   83test_reverse_2(X) :- reverse(X, [c, b, a]).
   84test_reverse_3(X) :- reverse([a, b, c], X).
   85test_reverse_4(T) :- reverse([a, b|T], [c, b, a]).
   86test_reverse_5 :- reverse([], []).
   87test_reverse_6(X) :- reverse([], X).
   88test_reverse_7(I1, I2) :- reverse([I1, b, c], [a, b, I2]).
   89test_reverse_8(X) :- reverse(X, X).
   90test_reverse_9(X, Y) :- reverse(X, Y).
   91
   92throws_exception(test_reverse_8). % Infinite solutions
   93throws_exception(test_reverse_9). % Infinite solutions