Skip to content

Commit 63f853a

Browse files
committed
Fix more tests for new behavior.
1 parent db13f03 commit 63f853a

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

test/model_parsing.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using ModelingToolkit, Test
22
using ModelingToolkit: get_connector_type, get_defaults, get_gui_metadata,
33
get_systems, get_ps, getdefault, getname, readable_code,
4-
scalarize, symtype, VariableDescription, RegularConnector
4+
scalarize, symtype, VariableDescription, RegularConnector,
5+
get_unit
56
using URIs: URI
67
using Distributions
78
using DynamicQuantities, OrdinaryDiffEq
@@ -106,14 +107,14 @@ end
106107
@parameters begin
107108
C, [unit = u"F"]
108109
end
109-
@extend OnePort(; v = 0.0)
110+
@extend OnePort(; v = 0.0u"V")
110111
@icon "https://upload.wikimedia.org/wikipedia/commons/7/78/Capacitor_symbol.svg"
111112
@equations begin
112113
D(v) ~ i / C
113114
end
114115
end
115116

116-
@named capacitor = Capacitor(C = 10, v = 10.0)
117+
@named capacitor = Capacitor(C = 10u"F", v = 10.0u"V")
117118
@test getdefault(capacitor.v) == 10.0
118119

119120
@mtkmodel Voltage begin
@@ -128,9 +129,9 @@ end
128129

129130
@mtkmodel RC begin
130131
@structural_parameters begin
131-
R_val = 10
132-
C_val = 10
133-
k_val = 10
132+
R_val = 10u"Ω"
133+
C_val = 10u"F"
134+
k_val = 10u"V"
134135
end
135136
@components begin
136137
resistor = Resistor(; R = R_val)
@@ -148,9 +149,9 @@ end
148149
end
149150
end
150151

151-
C_val = 20
152-
R_val = 20
153-
res__R = 100
152+
C_val = 20u"F"
153+
R_val = 20u"Ω"
154+
res__R = 100u"Ω"
154155
@mtkbuild rc = RC(; C_val, R_val, resistor.R = res__R)
155156
prob = ODEProblem(rc, [], (0, 1e9))
156157
sol = solve(prob, Rodas5P())
@@ -161,11 +162,11 @@ resistor = getproperty(rc, :resistor; namespace = false)
161162
@test getname(rc.resistor.R) === getname(resistor.R)
162163
@test getname(rc.resistor.v) === getname(resistor.v)
163164
# Test that `resistor.R` overrides `R_val` in the argument.
164-
@test getdefault(rc.resistor.R) == res__R != R_val
165+
@test getdefault(rc.resistor.R) * get_unit(rc.resistor.R) == res__R != R_val
165166
# Test that `C_val` passed via argument is set as default of C.
166-
@test getdefault(rc.capacitor.C) == C_val
167+
@test getdefault(rc.capacitor.C) * get_unit(rc.capacitor.C) == C_val
167168
# Test that `k`'s default value is unchanged.
168-
@test getdefault(rc.constant.k) == RC.structure[:kwargs][:k_val][:value]
169+
@test getdefault(rc.constant.k) * get_unit(rc.constant.k) == eval(RC.structure[:kwargs][:k_val][:value])
169170
@test getdefault(rc.capacitor.v) == 0.0
170171

171172
@test get_gui_metadata(rc.resistor).layout == Resistor.structure[:icon] ==

0 commit comments

Comments
 (0)