Skip to content

Commit 5547ac7

Browse files
committed
Add test cases demonstrating the external registration.
1 parent 3614610 commit 5547ac7

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

test/function_registration.jl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# TEST: Function registration in a module.
2+
# ------------------------------------------------
3+
module MyModule
4+
using ModelingToolkit, DiffEqBase, LinearAlgebra, Test
5+
@parameters t x
6+
@variables u(t)
7+
@derivatives Dt'~t
8+
9+
function do_something(a)
10+
a + 10
11+
end
12+
@register do_something(a)
13+
14+
eq = Dt(u) ~ do_something(x)
15+
sys = ODESystem([eq], t, [u], [x])
16+
fun = ODEFunction(sys)
17+
18+
@test fun([0.5], [5.0], 0.) == [15.0]
19+
end
20+
21+
# TEST: Function registration in a nested module.
22+
# ------------------------------------------------
23+
module MyModule2
24+
module MyNestedModule
25+
using ModelingToolkit, DiffEqBase, LinearAlgebra, Test
26+
@parameters t x
27+
@variables u(t)
28+
@derivatives Dt'~t
29+
30+
function do_something_2(a)
31+
a + 20
32+
end
33+
@register do_something_2(a)
34+
35+
eq = Dt(u) ~ do_something_2(x)
36+
sys = ODESystem([eq], t, [u], [x])
37+
fun = ODEFunction(sys)
38+
39+
@test fun([0.5], [3.0], 0.) == [23.0]
40+
end
41+
end
42+
43+
# TEST: Function registration outside any modules.
44+
# ------------------------------------------------
45+
using ModelingToolkit, DiffEqBase, LinearAlgebra, Test
46+
@parameters t x
47+
@variables u(t)
48+
@derivatives Dt'~t
49+
50+
function do_something_3(a)
51+
a + 30
52+
end
53+
@register do_something_3(a)
54+
55+
eq = Dt(u) ~ do_something_3(x)
56+
sys = ODESystem([eq], t, [u], [x])
57+
fun = ODEFunction(sys)
58+
59+
@test fun([0.5], [7.0], 0.) == [37.0]

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using SafeTestsets, Test
2020
@safetestset "Lowering Integration Test" begin include("lowering_solving.jl") end
2121
@safetestset "Test Big System Usage" begin include("bigsystem.jl") end
2222
@safetestset "Depdendency Graph Test" begin include("dep_graphs.jl") end
23+
@safetestset "Function Registration Test" begin include("function_registration.jl") end
2324
#@testset "Latexify recipes Test" begin include("latexify.jl") end
2425
@testset "Distributed Test" begin include("distributed.jl") end
2526
@testset "Array of Array Test" begin include("build_function_arrayofarray.jl") end

0 commit comments

Comments
 (0)