conservation_laws.plt 2.69 KB
Newer Older
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
1
:- use_module(library(plunit)).
2
:- use_module(reaction_rules).
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
3

SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
4
:- begin_tests(conservation_laws).
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
5 6 7 8 9


test(
   'add_conservation adds a conservation',
   [
Thierry Martinez's avatar
Thierry Martinez committed
10 11
      setup(clear_model),
      cleanup(clear_model),
12 13
      forall(member(Input, ['a-a' + 2*'a', 'b', 'a' + 'b'])),
      true(Conservations == [Input])
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
14 15
   ]
) :-
16
   command(add_conservation(Input)),
Thierry Martinez's avatar
Thierry Martinez committed
17
   all_items([kind: conservation], Conservations).
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
18

SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
19 20
%%% FIXME should test that conservations are properly used for numerical
%%% integration
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
21 22 23 24

test(
   'delete_conservation deletes the correct conservation',
   [
25
      setup(set_some_conservations),
Thierry Martinez's avatar
Thierry Martinez committed
26
      cleanup(clear_model),
27
      true(Conservations == ['a-a'+2*a,'c-c'+2*c])
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
28 29
   ]
) :-
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
30
   command(delete_conservation(b-b + 2*b)),
Thierry Martinez's avatar
Thierry Martinez committed
31
   all_items([kind: conservation], Conservations).
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
32 33 34 35 36


test(
   'delete_conservations deletes all conservations',
   [
37
      setup(set_some_conservations),
Thierry Martinez's avatar
Thierry Martinez committed
38
      cleanup(clear_model),
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
39
      true(Conservations == [])
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
40 41 42
   ]
) :-
   command(delete_conservations),
Thierry Martinez's avatar
Thierry Martinez committed
43
   all_items([kind: conservation], Conservations).
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
44 45


46 47 48 49
test(
   'list_conservations lists all conservations',
   [
      setup(set_some_conservations),
Thierry Martinez's avatar
Thierry Martinez committed
50
      cleanup(clear_model),
51
      true(Conservations ==
52
        '[0] a-a+2*a\n[1] b-b+2*b\n[2] c-c+2*c\n')
53 54 55 56 57
   ]
) :-
  with_output_to(atom(Conservations), command(list_conservations)).


SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
58 59 60
test(
  'check_conservations is ok with trivial P-invariants',
  [
Thierry Martinez's avatar
Thierry Martinez committed
61 62
    setup((clear_model, set_prolog_flag(verbose, silent))),
    cleanup((clear_model, set_prolog_flag(verbose, normal)))
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
63 64
  ]
) :-
65 66
  command(add_reaction(a => b)),
  command(add_reaction(b => a)),
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
67
  command(add_conservation(a + b)),
68
  with_output_to(atom(_), command(check_conservations)).
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
69 70


71 72 73
test(
  'check_conservations is ok with kinetically conserved moieties',
  [
Thierry Martinez's avatar
Thierry Martinez committed
74 75
    setup((clear_model, set_prolog_flag(verbose, silent))),
    cleanup((clear_model, set_prolog_flag(verbose, normal)))
76 77
  ]
) :-
78 79
  command(add_reaction(k*[a] for a => b)),
  command(add_reaction(k*[a] for a => 2*a)),
80 81 82 83
  command(add_conservation(a)),
  with_output_to(atom(_), command(check_conservations)).


SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
84 85 86
test(
  'check_conservations is unhappy with non-conserved moieties',
  [
Thierry Martinez's avatar
Thierry Martinez committed
87 88
    setup((clear_model, set_prolog_flag(verbose, silent))),
    cleanup((clear_model, set_prolog_flag(verbose, normal))),
89
    true(Warnings == 1)
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
90 91
  ]
) :-
92 93 94
  set_counter(warnings, 0),
  command(add_reaction(2*a => b)),
  command(add_reaction(a => b)),
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
95
  command(add_conservation(a + 2*b)),
96 97 98 99 100
  with_output_to(atom(_), command(check_conservations)),
  count(warnings, Warnings).


:- end_tests(conservation_laws).
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
101 102


103
set_some_conservations :-
Thierry Martinez's avatar
Thierry Martinez committed
104
  clear_model,
105 106 107
  command(add_conservation(a-a + 2*a)),
  command(add_conservation(b-b + 2*b)),
  command(add_conservation(c-c + 2*c)).
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
108

SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
109 110

% vi: set ts=2 sts=2 sw=2