File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 313
313
@test A. structure[:kwargs ] == Dict (:p => nothing , :v => nothing )
314
314
@test A. structure[:components ] == [[:cc , :C ]]
315
315
end
316
+
317
+ @testset " Conditional components, equations and parameters" begin
318
+ @mtkmodel C begin
319
+ @parameters begin
320
+ val
321
+ end
322
+ end
323
+
324
+ # Conditional statements inside @components, @equations
325
+ # Conditional default value
326
+ @mtkmodel A begin
327
+ @parameters begin
328
+ eq
329
+ end
330
+ @structural_parameters begin
331
+ eq_flag = true
332
+ c_flag = 1
333
+ end
334
+ @parameters begin
335
+ eq = eq_flag ? 1 : 2
336
+ end
337
+ @components begin
338
+ c0 = C (; val = 0 )
339
+ if c_flag == 1
340
+ c = C (; val = 1 )
341
+ elseif c_flag == 2
342
+ c = C (; val = 2 )
343
+ else
344
+ c = C (; val = 3 )
345
+ end
346
+ end
347
+ @equations begin
348
+ eq ~ 0
349
+ if eq_flag isa Int
350
+ eq ~ 1
351
+ elseif eq_flag
352
+ eq ~ 2
353
+ else
354
+ eq ~ 3
355
+ end
356
+ end
357
+ end
358
+
359
+ @mtkbuild a1 = A (eq_flag = 1 )
360
+ @test getdefault (a1. c. val) == 1
361
+ @test all ([a1. eq ~ 0 , a1. eq ~ 1 ] .∈ [equations (a1)])
362
+
363
+ @mtkbuild a2 = A (c_flag = 2 )
364
+ @test getdefault (a2. c. val) == 2
365
+ @test all ([a2. eq ~ 0 , a2. eq ~ 2 ] .∈ [equations (a2)])
366
+
367
+ @test all (:comp0 .∈ [nameof .(a1. systems), nameof .(a2. systems)])
368
+
369
+ @mtkbuild a3 = A (eq_flag = false , c_flag = 3 )
370
+ @test getdefault (a3. c. val) == 3
371
+ @test all ([a3. eq ~ 0 , a3. eq ~ 3 ] .∈ [equations (a3)])
372
+ end
You can’t perform that action at this time.
0 commit comments