Skip to content

Commit f25e052

Browse files
committed
Non-diagonal dispatch tests for connectors
1 parent 4647911 commit f25e052

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

test/connectors.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Test, ModelingToolkit
2+
3+
@parameters t
4+
5+
@connector function Foo(;name)
6+
@variables x(t)
7+
ODESystem(Equation[], t, [x], [], defaults=Dict(x=>1.0))
8+
end
9+
10+
@connector function Goo(;name)
11+
@variables x(t)
12+
@parameters p
13+
ODESystem(Equation[], t, [x], [p], defaults=Dict(x=>1.0, p=>1.0))
14+
end
15+
16+
ModelingToolkit.connect(::Type{<:Foo}, sys1, sys2) = [sys1.x ~ sys2.x]
17+
@named f1 = Foo()
18+
@named f2 = Foo()
19+
@named g = Goo()
20+
21+
@test isequal(connect(f1, f2), [f1.x ~ f2.x])
22+
@test_throws ArgumentError connect(f1, g)
23+
24+
# Note that since there're overloadings, these tests are not re-runable.
25+
ModelingToolkit.promote_connect_rule(::Type{<:Foo}, ::Type{<:Goo}) = Foo
26+
@test isequal(connect(f1, g), [f1.x ~ g.x])
27+
ModelingToolkit.promote_connect_rule(::Type{<:Goo}, ::Type{<:Foo}) = Foo
28+
@test isequal(connect(f1, g), [f1.x ~ g.x])
29+
# test conflict
30+
ModelingToolkit.promote_connect_rule(::Type{<:Goo}, ::Type{<:Foo}) = Goo
31+
@test_throws ArgumentError connect(f1, g)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ println("Last test requires gcc available in the path!")
3636
@safetestset "StructuralTransformations" begin include("structural_transformation/runtests.jl") end
3737
@testset "Serialization" begin include("serialization.jl") end
3838
@safetestset "print_tree" begin include("print_tree.jl") end
39+
@safetestset "connectors" begin include("connectors.jl") end

0 commit comments

Comments
 (0)