@@ -180,6 +180,23 @@ resistor = getproperty(rc, :resistor; namespace = false)
180
180
181
181
@test length (equations (rc)) == 1
182
182
183
+ @testset " Constants" begin
184
+ @mtkmodel PiModel begin
185
+ @constants begin
186
+ _p:: Irrational = π, [description = " Value of Pi." ]
187
+ end
188
+ @parameters begin
189
+ p = _p, [description = " Assign constant `_p` value." ]
190
+ end
191
+ end
192
+
193
+ @named pi_model = PiModel ()
194
+
195
+ @test typeof (ModelingToolkit. getdefault (pi_model. p)) < :
196
+ SymbolicUtils. BasicSymbolic{Irrational}
197
+ @test getdefault (getdefault (pi_model. p)) == π
198
+ end
199
+
183
200
@testset " Parameters and Structural parameters in various modes" begin
184
201
@mtkmodel MockModel begin
185
202
@parameters begin
@@ -400,14 +417,19 @@ end
400
417
module PrecompilationTest
401
418
push! (LOAD_PATH , joinpath (@__DIR__ , " precompile_test" ))
402
419
using Unitful, Test, ModelParsingPrecompile, ModelingToolkit
420
+ using ModelingToolkit: getdefault, scalarize
403
421
@testset " Precompile packages with MTKModels" begin
404
422
using ModelParsingPrecompile: ModelWithComponentArray
405
423
406
424
@named model_with_component_array = ModelWithComponentArray ()
407
425
408
- @test ModelWithComponentArray. structure[:parameters ][:R ][:unit ] == u " Ω"
426
+ @test ModelWithComponentArray. structure[:parameters ][:r ][:unit ] == u " Ω"
409
427
@test lastindex (parameters (model_with_component_array)) == 3
410
428
429
+ # Test the constant `k`. Manually k's value should be kept in sync here
430
+ # and the ModelParsingPrecompile.
431
+ @test all (getdefault .(getdefault .(scalarize (model_with_component_array. r))) .== 1 )
432
+
411
433
pop! (LOAD_PATH )
412
434
end
413
435
end
0 commit comments