Commit 83fa1501 authored by Mathieu Hemery's avatar Mathieu Hemery
Browse files

Move is_present in the util module and add atest suite

parent d3b2a56e
......@@ -1357,11 +1357,11 @@ formal_inhibitor(Mol, _Reactants/Inhibitors => _Products) :- !,
% is_present(Mol, Expr)
is_present(A, A) :- !.
is_present(A, _K*A) :- !.
is_present(A, _Tail+A) :- !.
is_present(A, _Tail+_K*A) :- !.
is_present(A, Tail+_H) :- is_present(A, Tail).
% is_present(A, A) :- !.
% is_present(A, _K*A) :- !.
% is_present(A, _Tail+A) :- !.
% is_present(A, _Tail+_K*A) :- !.
% is_present(A, Tail+_H) :- is_present(A, Tail).
%! test_wellformed(+List_Molecule, +Reaction)
......
:- module(
util,
[
multiset_inclusion/2,
add_list/3,
multiset_inclusion/2,
add_list/3,
multiply_list/3,
name_variables_and_anonymous/2,
camel_case/2,
......@@ -58,7 +58,8 @@
normal_random/1,
expand_polynomial/2,
atom_to_int/2,
realsetof/3
realsetof/3,
is_present/2
]).
:- use_module(library(process)).
......@@ -969,4 +970,16 @@ realsetof(X, Goal, List):-
List=[]
).
% is_present(+Term, +Expression)
%
% succeed if Term is present in Expression
is_present(Term, Term) :- !.
is_present(Term, Expression) :-
Expression =.. [_Functor| Termlist],
is_present_list(Term, Termlist).
is_present_list(Term, [Expr|_Tail]) :-
is_present(Term, Expr),
!.
is_present_list(Term, [_Other|Tail]) :-
is_present_list(Term, Tail).
......@@ -19,4 +19,13 @@ test('expand_polynomial') :-
expand_polynomial(p*r1*n1*(1-(n0+n1+n2)/k)/co, p/co*r1*n1*1-p/co*r1*n1*(n0/k)-p/co*r1*n1*(n1/k)-p/co*r1*n1*(n2/k)),
expand_polynomial(bb/e*(pa+ -1)*db, bb/e*pa*db + bb/e*(-1)*db).
test('is_present') :-
is_present(a, b*f(a)),
is_present(a, b*f(a/c)),
is_present(a, f(a*b)/c),
is_present(a*b, f(a*b)/c),
is_present(c, a*b/c^2),
\+( is_present(b-c, b*y-c) ),
\+( is_present(a, b*y-c) ).
:- end_tests(util).
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment