influence_editor.plt 2.1 KB
Newer Older
Thierry Martinez's avatar
Thierry Martinez committed
1 2 3 4 5 6 7 8
:- use_module(library(plunit)).


:- begin_tests(influence_editor).


test(
  'add_influence',
9
  [Influences == [((a, b) / c -> d), (b -< c), (/ a -< a)]]
Thierry Martinez's avatar
Thierry Martinez committed
10 11
) :-
  clear_model,
Thierry Martinez's avatar
Thierry Martinez committed
12
  command((a, b / c -> d)),
13
  command(b -< c),
14
  command(/ a -< a),
Thierry Martinez's avatar
Thierry Martinez committed
15 16 17 18 19 20 21
  all_items([kind: influence], Influences).

test(
  'add_influence fails on reaction models',
  [error(not_an_influence_model)]
) :-
  clear_model,
22 23 24 25 26 27 28 29 30
  command(a => b),
  command(a -> b).

test(
  'influence_model',
  [
    Influences
    ==
    [
31 32
      (a, b -< b), (a, b -< a),
      (a, b -> c), (a, b -> d)
33 34 35 36 37 38 39
    ]
  ]
) :-
  clear_model,
  command(a + b => c + d),
  influence_model,
  all_items([kind: influence], Influences).
Thierry Martinez's avatar
Thierry Martinez committed
40 41 42

test(
  'influence builds',
43
  [Influence == (2 for (a, b) / c -> d)]
Thierry Martinez's avatar
Thierry Martinez committed
44
) :-
Thierry Martinez's avatar
Thierry Martinez committed
45
  influence(Influence, 2, [a, b], [c], +, d).
Thierry Martinez's avatar
Thierry Martinez committed
46 47 48 49 50

test(
  'influence builds with positive inputs',
  [Influence == (b -< c)]
) :-
51
  influence(Influence, 'MA'(1), [b], [], -, c).
Thierry Martinez's avatar
Thierry Martinez committed
52 53 54

test(
  'influence builds with negative inputs',
55
  [Influence == (/ a -< a)]
Thierry Martinez's avatar
Thierry Martinez committed
56
) :-
57
  influence(Influence, 'MA'(1), [], [a], -, a).
Thierry Martinez's avatar
Thierry Martinez committed
58 59 60 61 62

test(
  'influence builds with no inputs',
  [Influence == ('_' -> a)]
) :-
63
  influence(Influence, 'MA'(1), [], [], +, a).
Thierry Martinez's avatar
Thierry Martinez committed
64 65 66 67

test(
  'influence destructs',
  [
Thierry Martinez's avatar
Thierry Martinez committed
68
    result(Force, PositiveInputs, NegativeInputs, Sign, Output)
Thierry Martinez's avatar
Thierry Martinez committed
69
    ==
Thierry Martinez's avatar
Thierry Martinez committed
70
    result(2, [a, b], [c], +, d)
Thierry Martinez's avatar
Thierry Martinez committed
71 72
  ]
) :-
73
  influence(
74
    (2 for (a, b) / c -> d),
75 76 77 78 79 80
    Force,
    PositiveInputs,
    NegativeInputs,
    Sign,
    Output
  ).
Thierry Martinez's avatar
Thierry Martinez committed
81 82 83 84

test(
  'influence destructs with positive inputs',
  [
Thierry Martinez's avatar
Thierry Martinez committed
85
    result(Force, PositiveInputs, NegativeInputs, Sign, Output)
Thierry Martinez's avatar
Thierry Martinez committed
86
    ==
87
    result('MA'(1), [b], [], -, c)
Thierry Martinez's avatar
Thierry Martinez committed
88 89
  ]
) :-
Thierry Martinez's avatar
Thierry Martinez committed
90
  influence((b -< c), Force, PositiveInputs, NegativeInputs, Sign, Output).
Thierry Martinez's avatar
Thierry Martinez committed
91 92 93 94

test(
  'influence destructs with negative inputs',
  [
Thierry Martinez's avatar
Thierry Martinez committed
95
    result(Force, PositiveInputs, NegativeInputs, Sign, Output)
Thierry Martinez's avatar
Thierry Martinez committed
96
    ==
97
    result('MA'(1), [], [a], -, a)
Thierry Martinez's avatar
Thierry Martinez committed
98 99
  ]
) :-
100
  influence((/ a -< a), Force, PositiveInputs, NegativeInputs, Sign, Output).
Thierry Martinez's avatar
Thierry Martinez committed
101

102 103 104 105 106 107 108 109 110 111 112 113
test(
  'compute_ode_for_influence_model',
  [ODEs == [d(a)/dt = -a, d(b)/dt = a]]
) :-
  clear_model,
  command(a -> b),
  command(a -< a),
  ode_system,
  all_odes(ODEs).



Thierry Martinez's avatar
Thierry Martinez committed
114
:- end_tests(influence_editor).