Wiki Discussion: Using SWI-Prolog unit tests

This is a topic to discuss the Wiki

Using SWI-Prolog unit tests

One of the primary items that should be in the Wiki are examples of how to use the various options.


Example of

set (AnswerTerm Cmp Instances)

Similar to all(AnswerTerm Cmp Instances) , but before testing both the bindings of AnswerTerm and Instances are sorted using sort/2. This removes duplicates and places both sets in the same order.2

add_element(X,L1,L2) :-
    append([X],L1,L0),
    permutation(L0,L2).

:- begin_tests(add_element).

add_element_test(success,0,[1,2],[[0,1,2],[0,2,1],[1,0,2],[1,2,0],[2,0,1],[2,1,0]]).

test(add_element_success,[forall(add_element_test(success,X,L1,Expected_result)),set(L2 == Expected_result )]) :-
    add_element(X,L1,L2).

:- end_tests(add_element).