|
| 1 | +using DynamicPPL |
| 2 | +using DynamicPPL: apply_dotted, getargs_dottilde, getargs_tilde |
| 3 | + |
| 4 | +using Test |
| 5 | + |
| 6 | +@testset "apply_dotted" begin |
| 7 | + # Some things that are not expressions. |
| 8 | + @test apply_dotted(:x) === :x |
| 9 | + @test apply_dotted(1.0) === 1.0 |
| 10 | + @test apply_dotted([1.0, 2.0, 4.0]) == [1.0, 2.0, 4.0] |
| 11 | + |
| 12 | + # Some expressions. |
| 13 | + @test apply_dotted(:(x ~ Normal(μ, σ))) == :(x ~ Normal(μ, σ)) |
| 14 | + @test apply_dotted(:((.~)(x, Normal(μ, σ)))) == :((.~)(x, Normal(μ, σ))) |
| 15 | + @test apply_dotted(:((~).(x, Normal(μ, σ)))) == :((~).(x, Normal(μ, σ))) |
| 16 | + @test apply_dotted(:(@. x ~ Normal(μ, σ))) == :((~).(x, Normal.(μ, σ))) |
| 17 | + @test apply_dotted(:(@. x ~ Normal(μ, $(Expr(:$, :(sqrt(v))))))) == |
| 18 | + :((~).(x, Normal.(μ, sqrt(v)))) |
| 19 | + @test apply_dotted(:(@~ Normal.(μ, σ))) == :(@~ Normal.(μ, σ)) |
| 20 | +end |
| 21 | + |
| 22 | +@testset "getargs_dottilde" begin |
| 23 | + # Some things that are not expressions. |
| 24 | + @test getargs_dottilde(:x) === nothing |
| 25 | + @test getargs_dottilde(1.0) === nothing |
| 26 | + @test getargs_dottilde([1.0, 2.0, 4.0]) === nothing |
| 27 | + |
| 28 | + # Some expressions. |
| 29 | + @test getargs_dottilde(:(x ~ Normal(μ, σ))) === nothing |
| 30 | + @test getargs_dottilde(:((.~)(x, Normal(μ, σ)))) == (:x, :(Normal(μ, σ))) |
| 31 | + @test getargs_dottilde(:((~).(x, Normal(μ, σ)))) == (:x, :(Normal(μ, σ))) |
| 32 | + @test getargs_dottilde(:(@. x ~ Normal(μ, σ))) === nothing |
| 33 | + @test getargs_dottilde(:(@. x ~ Normal(μ, $(Expr(:$, :(sqrt(v))))))) === nothing |
| 34 | + @test getargs_dottilde(:(@~ Normal.(μ, σ))) === nothing |
| 35 | +end |
| 36 | + |
| 37 | +@testset "getargs_tilde" begin |
| 38 | + # Some things that are not expressions. |
| 39 | + @test getargs_tilde(:x) === nothing |
| 40 | + @test getargs_tilde(1.0) === nothing |
| 41 | + @test getargs_tilde([1.0, 2.0, 4.0]) === nothing |
| 42 | + |
| 43 | + # Some expressions. |
| 44 | + @test getargs_tilde(:(x ~ Normal(μ, σ))) == (:x, :(Normal(μ, σ))) |
| 45 | + @test getargs_tilde(:((.~)(x, Normal(μ, σ)))) === nothing |
| 46 | + @test getargs_tilde(:((~).(x, Normal(μ, σ)))) === nothing |
| 47 | + @test getargs_tilde(:(@. x ~ Normal(μ, σ))) === nothing |
| 48 | + @test getargs_tilde(:(@. x ~ Normal(μ, $(Expr(:$, :(sqrt(v))))))) === nothing |
| 49 | + @test getargs_tilde(:(@~ Normal.(μ, σ))) === nothing |
| 50 | +end |
0 commit comments