@@ -39,3 +39,87 @@ jumps = JumpSet(rj)
3939prob = DiscreteProblem ([999 , 1 , 0 ], (0.0 , 250.0 ))
4040jump_prob = JumpProblem (prob, Direct (), rj; rng = rng)
4141sol = solve (jump_prob, SimpleTauLeaping (); dt = 1.0 )
42+
43+ # Test PureLeaping aggregator functionality
44+ @testset " PureLeaping Aggregator Tests" begin
45+ # Test with MassActionJump
46+ u0 = [10 , 5 , 0 ]
47+ tspan = (0.0 , 10.0 )
48+ p = [0.1 , 0.2 ]
49+ prob = DiscreteProblem (u0, p, tspan)
50+
51+ # Create MassActionJump
52+ reactant_stoich = [[1 => 1 ], [1 => 2 ]]
53+ net_stoich = [[1 => - 1 , 2 => 1 ], [1 => - 2 , 3 => 1 ]]
54+ rates = [0.1 , 0.05 ]
55+ maj = MassActionJump (rates, reactant_stoich, net_stoich)
56+
57+ # Test PureLeaping JumpProblem creation
58+ jp_pure = JumpProblem (prob, PureLeaping (), JumpSet (maj))
59+ @test jp_pure. aggregator isa PureLeaping
60+ @test jp_pure. discrete_jump_aggregation === nothing
61+ @test jp_pure. massaction_jump != = nothing
62+ @test length (jp_pure. jump_callback. discrete_callbacks) == 0
63+
64+ # Test with ConstantRateJump
65+ rate (u, p, t) = p[1 ] * u[1 ]
66+ affect! (integrator) = (integrator. u[1 ] -= 1 ; integrator. u[3 ] += 1 )
67+ crj = ConstantRateJump (rate, affect!)
68+
69+ jp_pure_crj = JumpProblem (prob, PureLeaping (), JumpSet (crj))
70+ @test jp_pure_crj. aggregator isa PureLeaping
71+ @test jp_pure_crj. discrete_jump_aggregation === nothing
72+ @test length (jp_pure_crj. constant_jumps) == 1
73+
74+ # Test with VariableRateJump
75+ vrate (u, p, t) = t * p[1 ] * u[1 ]
76+ vaffect! (integrator) = (integrator. u[1 ] -= 1 ; integrator. u[3 ] += 1 )
77+ vrj = VariableRateJump (vrate, vaffect!)
78+
79+ jp_pure_vrj = JumpProblem (prob, PureLeaping (), JumpSet (vrj))
80+ @test jp_pure_vrj. aggregator isa PureLeaping
81+ @test jp_pure_vrj. discrete_jump_aggregation === nothing
82+ @test length (jp_pure_vrj. variable_jumps) == 1
83+
84+ # Test with RegularJump
85+ function rj_rate (out, u, p, t)
86+ out[1 ] = p[1 ] * u[1 ]
87+ end
88+
89+ function rj_c (dc, u, p, t, mark)
90+ dc[1 , 1 ] = - 1
91+ dc[3 , 1 ] = 1
92+ end
93+
94+ rj_dc = zeros (3 , 1 )
95+ regj = RegularJump (rj_rate, rj_c, rj_dc; constant_c = true )
96+
97+ jp_pure_regj = JumpProblem (prob, PureLeaping (), JumpSet (regj))
98+ @test jp_pure_regj. aggregator isa PureLeaping
99+ @test jp_pure_regj. discrete_jump_aggregation === nothing
100+ @test jp_pure_regj. regular_jump != = nothing
101+
102+ # Test mixed jump types
103+ mixed_jumps = JumpSet (maj, crj, vrj, regj)
104+ jp_pure_mixed = JumpProblem (prob, PureLeaping (), mixed_jumps)
105+ @test jp_pure_mixed. aggregator isa PureLeaping
106+ @test jp_pure_mixed. discrete_jump_aggregation === nothing
107+ @test jp_pure_mixed. massaction_jump != = nothing
108+ @test length (jp_pure_mixed. constant_jumps) == 1
109+ @test length (jp_pure_mixed. variable_jumps) == 1
110+ @test jp_pure_mixed. regular_jump != = nothing
111+
112+ # Test spatial system error
113+ spatial_sys = CartesianGrid ((2 , 2 ))
114+ hopping_consts = [1.0 ]
115+ @test_throws ErrorException JumpProblem (prob, PureLeaping (), JumpSet (maj);
116+ spatial_system = spatial_sys)
117+ @test_throws ErrorException JumpProblem (prob, PureLeaping (), JumpSet (maj);
118+ hopping_constants = hopping_consts)
119+
120+ # Test MassActionJump with parameter mapping
121+ param_mapper = MassActionJumpParamMapper ([1 , 2 ])
122+ maj_params = MassActionJump (reactant_stoich, net_stoich, param_mapper)
123+ jp_params = JumpProblem (prob, PureLeaping (), JumpSet (maj_params))
124+ @test jp_params. massaction_jump. scaled_rates == p
125+ end
0 commit comments