Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacsas committed Jan 21, 2025
1 parent b89c3db commit d758f63
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions test/reactionsystem_core/reactionsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,12 @@ let
end

########## tests related to hybrid systems ##########

massactionjumps(js::JumpSystem) = equations(js).x[1]
constantratejumps(js::JumpSystem) = equations(js).x[2]
variableratejumps(js::JumpSystem) = equations(js).x[3]
odeeqs(js::JumpSystem) = equations(js).x[4]

let
t = default_t()
D = default_time_deriv()
Expand All @@ -1018,15 +1024,41 @@ let
cevents = [[V ~ 2.0] => [V ~ V/2, A ~ A/2]]
@named rs = ReactionSystem(vcat(rxs, eqs), t; continuous_events = cevents)
rs = complete(rs)
jinput = JumpInputs(rn, [:A => 0, :V => 1.0], (0.0, 10.0), [:k => 1.0, => .4])
jinput = JumpInputs(rs, [:A => 0, :B => 1, :C => 1, :V => 1.0], (0.0, 10.0), [:k => 1.0, => .4])
@test jinput.prob isa ODEProblem
sys = jinput.sys
@test sys isa JumpSystem
@test MT.has_equations(sys)
@test length(massactionjumps(sys)) == 1
@test isempty(constantratejumps(sys))
@test length(variableratejumps(sys)) == 3
@test length(odeeqs(sys)) == 4
@test length(continuous_events(sys)) == 1
end

let
t = default_t()
D = default_time_deriv()
@parameters λ k
@variables V(t)
@species A(t) B(t) C(t)
metadata = [:physical_scale => PhysicalScale.ODE]
rxs = [Reaction(k*V, [], [A]), Reaction*A, [B], nothing; metadata),
Reaction(k, [A, B], nothing), Reaction(λ, [C], [A])]
eqs = [D(V) ~ λ*V*C]
cevents = [[V ~ 2.0] => [V ~ V/2, A ~ A/2]]
@named rs = ReactionSystem(vcat(rxs, eqs), t; continuous_events = cevents)
rs = complete(rs)
jinput = JumpInputs(rs, [:A => 0, :B => 1, :C => 1, :V => 1.0], (0.0, 10.0), [:k => 1.0, => .4])
@test jinput.prob isa ODEProblem
sys = jinput.sys
@test sys isa JumpSystem
@test MT.has_equations(sys)
eqs = MT.equations(sys)
@test isempty(eqs.x[1])
@test isempty(eqs.x[2])
@test length(eqs.x[3]) == 1
@test length(eqs.x[4]) == 2 # dA/dt and dV/dt
@test length(massactionjumps(sys)) == 1
@test isempty(constantratejumps(sys))
@test length(variableratejumps(sys)) == 2
@test length(odeeqs(sys)) == 4
odes = union(eqs, [D(A) ~ 0, D(B) ~ -λ*A*B, D(C) ~ 0])
@test issetequal(odes, odeeqs(sys))
@test length(continuous_events(sys)) == 1
end

0 comments on commit d758f63

Please sign in to comment.