@@ -180,6 +180,23 @@ resistor = getproperty(rc, :resistor; namespace = false)
180180
181181@test length (equations (rc)) == 1
182182
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+
183200@testset " Parameters and Structural parameters in various modes" begin
184201 @mtkmodel MockModel begin
185202 @parameters begin
@@ -400,14 +417,19 @@ end
400417module PrecompilationTest
401418push! (LOAD_PATH , joinpath (@__DIR__ , " precompile_test" ))
402419using Unitful, Test, ModelParsingPrecompile, ModelingToolkit
420+ using ModelingToolkit: getdefault, scalarize
403421@testset " Precompile packages with MTKModels" begin
404422 using ModelParsingPrecompile: ModelWithComponentArray
405423
406424 @named model_with_component_array = ModelWithComponentArray ()
407425
408- @test ModelWithComponentArray. structure[:parameters ][:R ][:unit ] == u " Ω"
426+ @test ModelWithComponentArray. structure[:parameters ][:r ][:unit ] == u " Ω"
409427 @test lastindex (parameters (model_with_component_array)) == 3
410428
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+
411433 pop! (LOAD_PATH )
412434end
413435end
0 commit comments