Skip to content

Commit

Permalink
Test error cases of default compositions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukem12345 committed Jun 26, 2024
1 parent 38a1576 commit 4826421
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/composition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ If `only_states_terminals` is `true`, only expose state and terminal variables.
Note that composing immediately with [`oapply`](@ref) will fail if types do not match (e.g. (:infer, :Form0) or (:Form0, :Form1)).
"""
function default_composition_diagram(podes::Vector{D}, names::Vector{Symbol}, only_states_terminals=false) where {D<:SummationDecapode}
length(podes) == length(names) || error("$(length(podes)) models given, but $(length(names)) names provided.")
non_lit_names = map(podes) do pode
pode[findall(!=(:Literal), pode[:type]), :name]
end
Expand Down
49 changes: 49 additions & 0 deletions test/composition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,55 @@ end
[GlensLaw, HalfarsEquation],
[:GlensLaw, :HalfarsEquation],
true))

# Test an error is thrown when # of models ≠ # of names.
Diffusion = @decapode begin
C::Form0
ϕ₁::Form1
ϕ₁ == (k, d₀)(C)
end
Advection = @decapode begin
C::Form0
(V, ϕ₂)::Form1
ϕ₂ == (C,V)
end
Superposition = @decapode begin
(C, Ċ)::Form0
(ϕ, ϕ₁, ϕ₂)::Form1
ϕ == ϕ₁ + ϕ₂
Ċ == (₀⁻¹, dual_d₁, ₁)(ϕ)
∂ₜ(C) == Ċ
end
@test_throws "3 models given, but 2 names provided." default_composition_diagram(
[Diffusion, Advection, Superposition],
[:Diffusion, :Advection])

# Test an error is thrown when a single model contains duplicate names.
Diffusion = @decapode begin
C::Form0
ϕ₁::Form1
ϕ₁ == (k, d₀)(C)
end
AdvectionDuplicates = @acset SummationDecapode{Any, Any, Symbol} begin
Var = 4
type = [:Form0, :Form1, :Form1, :Form1]
name = [:C, :V, :ϕ₂, :ϕ₂]
Op2 = 1
proj1 = [1]
proj2 = [2]
res = [3]
op2 = [:₀₁]
end
Superposition = @decapode begin
(C, Ċ)::Form0
(ϕ, ϕ₁, ϕ₂)::Form1
ϕ == ϕ₁ + ϕ₂
Ċ == (₀⁻¹, dual_d₁, ₁)(ϕ)
∂ₜ(C) == Ċ
end
@test_throws "Decapode AdvectionDuplicates contains repeated variable names: Set([:ϕ₂])." default_composition_diagram(
[Diffusion, AdvectionDuplicates, Superposition],
[:Diffusion, :AdvectionDuplicates, :Superposition])
end

# end

0 comments on commit 4826421

Please sign in to comment.