Chih-Hung Hsieh bde955c276 Prolog Example Unit Tests
These small examples are designed to run quickly
with the Gerrit prolog-shell, but not depending
on a local Gerrit repository server.

Change-Id: I8f58a6740c6f2c79ae1314f2ae593409ee60440d
2019-04-22 18:01:29 -07:00

30 lines
734 B
Prolog

% An example source file to be tested.
% Add common rules missing in Prolog Cafe.
memberchk(X, [H|T]) :-
(X = H) -> true ; memberchk(X, T).
% A rule that can succeed/backtrack multiple times.
super_users(1001).
super_users(1002).
% Deterministic rule that pass/fail only once.
is_super_user(X) :- memberchk(X, [1001, 1002]).
% Another rule that can pass 5 times.
multi_users(101).
multi_users(102).
multi_users(103).
multi_users(104).
multi_users(105).
% Okay, single deterministic fact.
single_user(abc).
% Wrap calls to gerrit repository, to be redefined in tests.
change_owner(X) :- gerrit:change_owner(X).
% To test is_owner without gerrit:change_owner,
% we should redefine change_owner.
is_owner(X) :- change_owner(X).