Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/ModelingToolkitBase/src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -737,12 +737,8 @@ function _poissonians(exprs...)
end)
end

# Return the variables as a tuple (or single if only one)
if length(names) == 1
return Expr(:block, assignments..., names[1])
else
return Expr(:block, assignments..., Expr(:tuple, names...))
end
# Return the variables as a Vector, consistent with @variables and @brownians
return Expr(:block, assignments..., Expr(:vect, names...))
end

## Guess ======================================================================
Expand Down
45 changes: 45 additions & 0 deletions lib/ModelingToolkitBase/test/poissonians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,51 @@ using OrdinaryDiffEq, StochasticDiffEq
@test !ispoissonian(x)
end

@testset "Return type consistency with @variables" begin
@parameters λ₁ λ₂ λ₃

# Single inline: should return a 1-element Vector
result_single = @poissonians dN_a(λ₁)
@test result_single isa Vector
@test length(result_single) == 1
@test ispoissonian(result_single[1])
@test isequal(result_single[1], dN_a)

# Multiple inline: should return a Vector
result_multi = @poissonians dN_b(λ₁) dN_c(λ₂)
@test result_multi isa Vector
@test length(result_multi) == 2
@test all(ispoissonian, result_multi)
@test isequal(result_multi[1], dN_b)
@test isequal(result_multi[2], dN_c)

# Single in block: should return a 1-element Vector
result_block_single = @poissonians begin
dN_d(λ₁)
end
@test result_block_single isa Vector
@test length(result_block_single) == 1
@test ispoissonian(result_block_single[1])
@test isequal(result_block_single[1], dN_d)

# Multiple in block: should return a Vector
result_block_multi = @poissonians begin
dN_e(λ₂)
dN_f(λ₃)
end
@test result_block_multi isa Vector
@test length(result_block_multi) == 2
@test all(ispoissonian, result_block_multi)
@test isequal(result_block_multi[1], dN_e)
@test isequal(result_block_multi[2], dN_f)

# Three inline: should return a Vector of length 3
result_three = @poissonians dN_g(λ₁) dN_h(λ₂) dN_i(λ₃)
@test result_three isa Vector
@test length(result_three) == 3
@test all(ispoissonian, result_three)
end

@testset "Error on missing rate" begin
# This should error - rate is required
@test_throws Exception @macroexpand @poissonians dN
Expand Down
Loading