Skip to content

Commit 98889f8

Browse files
test: test properly scoped discovery of parameters
1 parent 95e3d29 commit 98889f8

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

test/variable_scope.jl

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using ModelingToolkit
2-
using ModelingToolkit: SymScope
3-
using Symbolics: arguments, value
2+
using ModelingToolkit: SymScope, t_nounits as t, D_nounits as D
3+
using Symbolics: arguments, value, getname
44
using Test
55

6-
@independent_variables t
76
@variables a b(t) c d e(t)
87

98
b = ParentScope(b)
@@ -52,7 +51,6 @@ end
5251
@test renamed([:foo :bar :baz], c) == Symbol("foo₊c")
5352
@test renamed([:foo :bar :baz], d) == :d
5453

55-
@independent_variables t
5654
@parameters a b c d e f
5755
p = [a
5856
ParentScope(b)
@@ -84,3 +82,22 @@ arr1 = ODESystem(Equation[], t, [], []; name = :arr1) ∘ arr0
8482
arr_ps = ModelingToolkit.getname.(parameters(arr1))
8583
@test isequal(arr_ps[1], Symbol("xx"))
8684
@test isequal(arr_ps[2], Symbol("arr0₊xx"))
85+
86+
function Foo(; name, p = 1)
87+
@parameters p = p
88+
@variables x(t)
89+
return ODESystem(D(x) ~ p, t; name)
90+
end
91+
function Bar(; name, p = 2)
92+
@parameters p = p
93+
@variables x(t)
94+
@named foo = Foo(; p)
95+
return ODESystem(D(x) ~ p + t, t; systems = [foo], name)
96+
end
97+
@named bar = Bar()
98+
bar = complete(bar)
99+
@test length(parameters(bar)) == 2
100+
@test sort(getname.(parameters(bar))) == [:foo₊p, :p]
101+
defs = ModelingToolkit.defaults(bar)
102+
@test defs[bar.p] == 2
103+
@test isequal(defs[bar.foo.p], bar.p)

0 commit comments

Comments
 (0)