Skip to content

Commit d2328ab

Browse files
test: test @mtkmodel array variables, default namespacing
1 parent ac88d49 commit d2328ab

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

test/model_parsing.jl

+26-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using ModelingToolkit: get_connector_type, get_defaults, get_gui_metadata,
33
get_systems, get_ps, getdefault, getname, readable_code,
44
scalarize, symtype, VariableDescription, RegularConnector,
55
get_unit
6+
using SymbolicIndexingInterface
67
using URIs: URI
78
using Distributions
89
using DynamicQuantities, OrdinaryDiffEq
@@ -245,7 +246,7 @@ end
245246
kval = 5
246247
@named model = MockModel(; b2 = [1, 3], kval, cval = 1, func = identity)
247248

248-
@test lastindex(parameters(model)) == 31
249+
@test lastindex(parameters(model)) == 21
249250

250251
@test all(getdescription.([model.e2...]) .== "e2")
251252
@test all(getdescription.([model.h2...]) .== "h2(t)")
@@ -475,7 +476,7 @@ using ModelingToolkit: getdefault, scalarize
475476
@named model_with_component_array = ModelWithComponentArray()
476477

477478
@test eval(ModelWithComponentArray.structure[:parameters][:r][:unit]) == eval(u"")
478-
@test lastindex(parameters(model_with_component_array)) == 3
479+
@test lastindex(parameters(model_with_component_array)) == 1
479480

480481
# Test the constant `k`. Manually k's value should be kept in sync here
481482
# and the ModelParsingPrecompile.
@@ -876,3 +877,26 @@ end
876877
end),
877878
false)
878879
end
880+
881+
@testset "Array parameters and subcomponent defaults" begin
882+
@mtkmodel Foo begin
883+
@parameters begin
884+
p[1:3]
885+
end
886+
end
887+
@mtkmodel Bar begin
888+
@parameters begin
889+
q[1:3]
890+
end
891+
@components begin
892+
foo = Foo(p = q)
893+
end
894+
end
895+
@named model = Bar()
896+
model = complete(model)
897+
# non-scalarized versions are parameters
898+
@test is_parameter(model, model.q)
899+
@test is_parameter(model, model.foo.p)
900+
# default is correctly (not) namespaced
901+
@test isequal(ModelingToolkit.defaults(model)[model.foo.p], model.q)
902+
end

0 commit comments

Comments
 (0)