begin migrating tests to pure prolog, correct bug in toplevel
This commit is contained in:
64
src/tests/builtins.pl
Normal file
64
src/tests/builtins.pl
Normal file
@@ -0,0 +1,64 @@
|
||||
|
||||
:- use_module(library(lists)).
|
||||
|
||||
test_queries_on_builtins :-
|
||||
\+ atom(_),
|
||||
atom(a),
|
||||
\+ atom("string"),
|
||||
atom([]),
|
||||
\+ atom(1),
|
||||
\+ atom(0),
|
||||
\+ atom(0.0),
|
||||
\+ atom([a,b,c]),
|
||||
\+ atom(atop(the_trees)),
|
||||
\+ atomic(_),
|
||||
atomic(a),
|
||||
atomic("string"),
|
||||
atomic([]),
|
||||
atomic(1),
|
||||
atomic(0),
|
||||
atomic(0.0),
|
||||
\+ atomic([a,b,c]),
|
||||
\+ atomic(atop(the_trees)),
|
||||
( var(X), X = 3, atomic(X) ),
|
||||
\+ ( var(X), X = 3, var(X) ),
|
||||
arg(1, f(a,b,c,d), a),
|
||||
arg(2, f(a,b,c,d), b),
|
||||
arg(3, f(a,b,c,d), c),
|
||||
arg(4, f(a,b,c,d), d),
|
||||
catch(arg(_, f, _), error(instantiation_error, _), true),
|
||||
\+ arg(1, f(arg, not_arg, not_arg), not_arg),
|
||||
arg(2, f(arg, not_arg, not_arg), not_arg),
|
||||
arg(3, f(arg, not_arg, not_arg), not_arg),
|
||||
functor(f(a,b,c), f, 3),
|
||||
catch(functor(_,"sdf",3),error(type_error(atom,[s,d,f]),_),true),
|
||||
f(1,2,3) =.. [f,1,2,3],
|
||||
length([a,b,c], 3),
|
||||
copy_term([[[[X,Y],Y],X]],[[[[Z,V],V],Z]]),
|
||||
\+ ( X = g(X,Y), Y = f(X), copy_term(Y,g(Z)) ),
|
||||
(X = g(X,Y), Y = f(X), copy_term(Y,f(Z))),
|
||||
float(3.14159269),
|
||||
\+ float(3),
|
||||
\+ float("sdfsa"),
|
||||
\+ float(structure(functor)),
|
||||
\+ float([1,2,3]),
|
||||
\+ float([1,2,_]),
|
||||
\+ (X is 3 rdiv 4, float(X)),
|
||||
( X is 3 rdiv 4, rational(X) ),
|
||||
\+ rational(3),
|
||||
\+ rational(f(_)),
|
||||
\+ rational("sdfa"),
|
||||
\+ rational(atom),
|
||||
\+ rational(structure(f)),
|
||||
\+ rational([1,2,3]),
|
||||
\+ rational([1,2,_]),
|
||||
compound(functor(compound)),
|
||||
compound(f(_)),
|
||||
compound([1,2,3]),
|
||||
\+ compound([]),
|
||||
\+ compound(3.14159269),
|
||||
\+ compound(3),
|
||||
\+ compound("sdfsa"),
|
||||
\+ compound(atom).
|
||||
|
||||
:- initialization(test_queries_on_builtins).
|
||||
26
src/tests/facts.pl
Normal file
26
src/tests/facts.pl
Normal file
@@ -0,0 +1,26 @@
|
||||
:- dynamic(p/2).
|
||||
:- dynamic(p/3).
|
||||
|
||||
p(Z, Z).
|
||||
clouds(are, nice).
|
||||
p(Z, h(Z, W), f(W)).
|
||||
|
||||
test_queries_on_facts :-
|
||||
findall(Z, p(Z, Z), [Z]),
|
||||
findall(Z, p(Z, z), [z]),
|
||||
findall(Z, p(Z, w), [w]),
|
||||
\+ p(z, w),
|
||||
p(w, w),
|
||||
\+ clouds(Z, Z),
|
||||
findall(Z, clouds(are, Z), [nice]),
|
||||
\+ p(z, h(z, z), f(w)),
|
||||
p(z, h(z, w), f(w)),
|
||||
findall(W, p(z, h(z, W), f(w)), [w]),
|
||||
findall(Z, p(Z, h(Z, w), f(Z)), [w]),
|
||||
\+ p(z, h(Z, w), f(Z)),
|
||||
retract(p(_,_,_)),
|
||||
assertz(p(Z, h(Z, W), f(W))),
|
||||
p(f(f(a)), h(f(f(a)), f(a)), f(f(a))),
|
||||
retract(p(Z, h(Z, W), f(W))).
|
||||
|
||||
:- initialization(test_queries_on_facts).
|
||||
37
src/tests/predicates.pl
Normal file
37
src/tests/predicates.pl
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
:- dynamic(p/2).
|
||||
:- dynamic(p/3).
|
||||
|
||||
:- dynamic(q/1).
|
||||
|
||||
p(_, a).
|
||||
p(b, _).
|
||||
|
||||
test_queries_on_predicates :-
|
||||
findall(Y, p(x, Y), [a]),
|
||||
findall(X, p(X, a), [_,b]),
|
||||
findall(X, p(b, X), [a,_]),
|
||||
findall(X, p(X, X), [a,b]),
|
||||
p(b, a),
|
||||
\+ p(a, b),
|
||||
retract(p(_,a)),
|
||||
retract(p(b,_)),
|
||||
assertz(p(_, _,a)),
|
||||
assertz(p(_,a,_)),
|
||||
assertz(p(_,_,a)),
|
||||
findall(X, p(c,d,X), [a,a]),
|
||||
findall(X, p(a,a,a), [a,a,a]),
|
||||
\+ p(b,c,d),
|
||||
findall(., retract(p(_,_,_)), _),
|
||||
assertz(p(_, a)),
|
||||
assertz(q(z)),
|
||||
findall(Y, p(_,Y), [a]),
|
||||
p(x,a),
|
||||
p(_,a),
|
||||
\+ p(_,b),
|
||||
assertz((p(X, Y) :- q(Z), p(X, X))),
|
||||
once(p(X,b)),
|
||||
retract((p(X, Y) :- q(Z), p(X, X))),
|
||||
retract(q(z)).
|
||||
|
||||
:- initialization(test_queries_on_predicates).
|
||||
55
src/tests/rules.pl
Normal file
55
src/tests/rules.pl
Normal file
@@ -0,0 +1,55 @@
|
||||
:- dynamic(p/3).
|
||||
:- dynamic(p/2).
|
||||
:- dynamic(q/2).
|
||||
:- dynamic(r/2).
|
||||
:- dynamic(r/1).
|
||||
:- dynamic(h/1).
|
||||
|
||||
p(X, Y) :- q(X, Z), r(Z, Y).
|
||||
q(q, s).
|
||||
r(s, t).
|
||||
|
||||
test_queries_on_rules :-
|
||||
findall([X,Y], p(X, Y), [[q, t]]),
|
||||
p(q, t),
|
||||
\+ p(t, q),
|
||||
findall(T, p(q, T), [t]),
|
||||
\+ p(t, t),
|
||||
retract((p(X,Y) :- q(X,Z), r(Z, Y))),
|
||||
retract(q(_,_)),
|
||||
assertz((p(X,_) :- q(f(f(X)), _), r(_, _))),
|
||||
assertz(q(f(f(X)), r)),
|
||||
p(_,_),
|
||||
retract(q(_,_)),
|
||||
assertz(q(f(f(x)), r)),
|
||||
findall(X, p(X,_), [x]),
|
||||
retract((p(X,_) :- q(f(f(X)), _), r(_, _))),
|
||||
retract(q(_,_)),
|
||||
assertz((p(X, Y) :- q(X, Y), r(X, Y))),
|
||||
assertz(q(s, t)),
|
||||
retract(r(_,_)),
|
||||
assertz((r(X, Y) :- r(a))),
|
||||
assertz(r(a)),
|
||||
findall([X,Y], p(X, Y), [[s,t]]),
|
||||
\+ p(t, _),
|
||||
findall(T, p(s, T), [t]),
|
||||
findall(S, p(S, t), [s]),
|
||||
assertz((p(f(f(a), g(b), X), g(b), h) :- q(X, Y))),
|
||||
retract(q(_,_)),
|
||||
assertz(q(_,_)),
|
||||
findall([X,Y,Z], p(f(X, Y, Z), g(b), h), [[f(a), g(b), _]]),
|
||||
\+ p(f(X, g(_), Z), g(Z), X),
|
||||
findall([X,Y,Z], p(f(X, g(Y), Z), g(Z), h), [[f(a), b, b]]),
|
||||
findall([X,Y,Z], p(Z, Y, X), [[h, g(b), f(f(a),g(b),_)]]),
|
||||
findall([X,Y,Z], p(f(X, Y, Z), Y, h), [[f(a), g(b), _]]),
|
||||
retract((p(X, Y) :- q(X, Y), r(X, Y))),
|
||||
retract((p(f(f(a), g(b), X), g(b), h) :- q(X, _))),
|
||||
assertz((p(_, f(_, Y, _)) :- h(Y))),
|
||||
assertz(h(y)),
|
||||
findall(Y, p(_, f(_, Y, _)), [y]).
|
||||
p(_, f(_, y, _)),
|
||||
\+ p(_, f(_, z, _)),
|
||||
retract((p(_, f(_, Y, _)) :- h(Y))).
|
||||
|
||||
:- initialization(test_queries_on_rules).
|
||||
|
||||
Reference in New Issue
Block a user