1/*  Part of SWI-Prolog
2
3    Author:        Jan Wielemaker
4    E-mail:        J.Wielemaker@vu.nl
5    WWW:           http://www.swi-prolog.org
6    Copyright (c)  2017-2019, University of Amsterdam
7                              VU University Amsterdam
8			      CWI, Amsterdam
9    All rights reserved.
10
11    Redistribution and use in source and binary forms, with or without
12    modification, are permitted provided that the following conditions
13    are met:
14
15    1. Redistributions of source code must retain the above copyright
16       notice, this list of conditions and the following disclaimer.
17
18    2. Redistributions in binary form must reproduce the above copyright
19       notice, this list of conditions and the following disclaimer in
20       the documentation and/or other materials provided with the
21       distribution.
22
23    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34    POSSIBILITY OF SUCH DAMAGE.
35*/
36
37:- module(test_wfs,
38	  [ test_wfs/0
39	  ]).
40:- use_module(library(plunit)).
41:- use_module(library(wfs)).
42
43test_wfs :-
44	run_tests([ wfs_delays
45		  ]).
46
47:- begin_tests(wfs_delays).
48:- use_module(library(dialect/xsb)).
49
50:- table p/0, q/0, a/1.
51
52x :- q.
53
54p :- tnot(q).
55q :- tnot(p).
56
57a(true).
58
59:- table puas(_,lattice(join(_X,_Y,_Z))).
60join(X,Y,Z) :- Z is max(X,Y).
61
62puas(1,X) :-
63    not_exists(puas(1,X)).
64
65test(delays, D == q) :-
66    call_delays(q, D).
67test(delays, D == q) :-
68    call_delays(x, D).
69test(delays, D == tnot(q)) :-
70    call_delays(tnot(q), D).
71test(delays, D == true) :-
72    call_delays(a(_), D).
73test(delays, D == test_wfs:mp) :-
74    call_delays(mp, D).
75test(residual, D == [(q:-tnot(p)),(p:-tnot(q))]) :-
76    call_residual_program(q, D).
77test(as, D =@= [(puas(1,_) :- tnot(tabled_call(plunit_wfs_delays:puas(1,B)))),
78		(tabled_call(plunit_wfs_delays:puas(1,B)):-puas(1,B))]) :-
79    call_residual_program(puas(1,_), D).
80
81:- end_tests(wfs_delays).
82
83% Use imported definitions to test qualification
84
85:- table mp/0, mq/0.
86
87mp :- tnot(mq).
88mq :- tnot(mp).
89
90