Skip to content

Commit 3e74ca3

Browse files
committed
TST: Tests added for higher order reactions
1 parent c384f07 commit 3e74ca3

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

test/higher_order_reactions.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using DiffEqBiological, DiffEqJump, DiffEqBase, OrdinaryDiffEq
2+
3+
k = rand()
4+
# First order
5+
r1 = Reaction(k,[1],((1,-1),(2,1)))
6+
jump = build_jumps_from_reaction(r1)
7+
@test jump.rate(0.0,[1,0]) == k
8+
9+
10+
# Second order
11+
r2 = Reaction(k,[1,1],((1,-2),(2,1)))
12+
jump2 = build_jumps_from_reaction(r2)
13+
@test jump2.rate(0.0,[1,0]) == 0
14+
@test jump2.rate(0.0,[2,0]) == k*2*1
15+
16+
# Thrid order
17+
r3 = Reaction(k,[1,1,1],((1,-3),(2,1)))
18+
jump3 = build_jumps_from_reaction(r3)
19+
@test jump3.rate(0.0,[1,0]) == 0
20+
@test jump3.rate(0.0,[2,0]) == 0
21+
@test jump3.rate(0.0,[3,0]) == k*3*2*1
22+
23+
# Mixed Third order
24+
r21 = Reaction(k ,[1,1,2],((1,-2),(2,-1)))
25+
jump21 = build_jumps_from_reaction(r21)
26+
@test jump21.rate(0.0,[1,1]) == 0
27+
@test jump21.rate(0.0,[2,1]) == k*2*1*1
28+
29+
# Mixed Third order different order
30+
r12 = Reaction(k ,[2,1,1],((1,-2),(2,-1)))
31+
jump12 = build_jumps_from_reaction(r12)
32+
jump12.rate(0.0,[1,1]) == 0
33+
@test jump12.rate(0.0,[2,1]) == k*2*1*1
34+
35+
36+
# Solve the dimerization problem
37+
prob = DiscreteProblem([1,0],(0.0,250.0))
38+
jump_prob = GillespieProblem(prob,Direct(),r2)
39+
sol = solve(jump_prob,Discrete())
40+
@test find( x-> x!=0 ,[u[2] for u in sol.u]) == []

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ tic()
55
@time @testset "Gillespie Tests" begin include("gillespie.jl") end
66
@time @testset "Variable Rate Reaction Tests" begin include("variable_rate_reactions.jl") end
77
@time @testset "@reaction_network Tests" begin include("reaction_network.jl") end
8+
@time @testset "Higher order reaction Tests" begin include("higher_order_reactions.jl") end
89
toc()

0 commit comments

Comments
 (0)