Skip to content

Commit 69f6f63

Browse files
committed
add some additional tests
1 parent 9eeead5 commit 69f6f63

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/miscellaneous_tests/stability_computation.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,23 @@ let
3030
# Generates random parameter values (which can generate all steady states cases).
3131
p = [:v => 1.0 + 3*rand(rng), :K => 0.5 + 2*rand(rng), :n => rand(rng,[1,2,3,4]), :d => 0.5 + rand(rng)]
3232

33+
# Computes stability using various jacobian options.
3334
sss = hc_steady_states(rn, p)
3435
stabs_1 = steady_state_stability(sss, rn, p)
3536
stabs_2 = steady_state_stability(sss, rn, p; sparse=true)
3637
stabs_3 = steady_state_stability(sss, rn, p; ss_jac=ss_jac)
3738
stabs_4 = steady_state_stability(sss, rn, p; ss_jac=ss_jac_sparse)
3839

40+
# Confirms stability using simulations.
3941
for (idx,ss) in enumerate(sss)
4042
oprob = ODEProblem(rn, [1.001, 0.999] .* ss, (0.0,1000.0), p)
4143
sol_end = solve(oprob, Rosenbrock23())[end]
4244
stabs_5 = ss sol_end
4345
@test stabs_1[idx] == stabs_2[idx] == stabs_3[idx] == stabs_4[idx] == stabs_5
46+
47+
# Checks stability when steady state is given on a pair form ([:X => x_val, :Y => y_val]).
48+
stabs_6 = steady_state_stability(Pair.(states(rn),ss), rn, p)
49+
@test stabs_5 == stabs_6
4450
end
4551
end
4652
end
@@ -49,13 +55,16 @@ end
4955
# Tests for system with conservation laws.
5056
# Tests for various input forms of u0 and ps.
5157
let
58+
# Creates model.
5259
rn = complete(@reaction_network begin
5360
k1+Z, Y --> 2X
5461
k2, 2X --> X + Y
5562
k3, X + Y --> Y
5663
k4, X --> 0
5764
(kD1+X, kD2), 2Z <--> Z2
5865
end)
66+
67+
# Creates various forms of input.
5968
@unpack k1, k2, k3, k4, kD1, kD2, X, Y, Z, Z2 = rn
6069
u0_1 = [X => 1.0, Y => 1.0, Z => 1.0, Z2 => 1.0]
6170
u0_2 = [:X => 1.0, :Y => 1.0, :Z => 1.0, :Z2 => 1.0]
@@ -66,6 +75,7 @@ let
6675
ps_3 = [rn.k1 => 8.0, rn.k2 => 2.0, rn.k3 => 1.0, rn.k4 => 1.5, rn.kD1 => 0.5, rn.kD2 => 4.0]
6776
ps_4 = [8.0, 2.0, 1.0, 1.5, 0.5, 4.0]
6877

78+
# Computes stability using various input forms, and checks that the output is correct.
6979
sss = hc_steady_states(rn, ps_1; u0=u0_1)
7080
for u0 in [u0_1, u0_2, u0_3, u0_4], ps in [ps_1, ps_2, ps_3, ps_4]
7181
stab_1 = steady_state_stability(sss, rn, ps)
@@ -77,4 +87,7 @@ let
7787
@test length(stab_2) == 3
7888
@test count(stab_2) == 2
7989
end
90+
91+
# Confirms error when computing Jacobian with wrong length of u0.
92+
@test_throws Exception steady_state_jac(rn; u0=[1.0, 1.0])
8093
end

0 commit comments

Comments
 (0)