Skip to content

Commit 8383b15

Browse files
committed
Add tests
1 parent 2969303 commit 8383b15

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

test/model_parsing.jl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using ModelingToolkit, Test
2+
3+
@connector RealInput begin u(t), [input = true] end
4+
@connector RealOutput begin u(t), [output = true] end
5+
@model Constant begin
6+
@components begin output = RealOutput() end
7+
@parameters begin k, [description = "Constant output value of block"] end
8+
@equations begin output.u ~ k end
9+
end
10+
11+
@variables t
12+
D = Differential(t)
13+
14+
@connector Pin begin
15+
v(t) = 0 # Potential at the pin [V]
16+
i(t), [connect = Flow] # Current flowing into the pin [A]
17+
end
18+
19+
@model OnePort begin
20+
@components begin
21+
p = Pin()
22+
n = Pin()
23+
end
24+
@variables begin
25+
v(t)
26+
i(t)
27+
end
28+
@equations begin
29+
v ~ p.v - n.v
30+
0 ~ p.i + n.i
31+
i ~ p.i
32+
end
33+
end
34+
35+
@model Ground begin
36+
@components begin g = Pin() end
37+
@equations begin g.v ~ 0 end
38+
end
39+
40+
@model Resistor begin
41+
@extend v, i = oneport = OnePort()
42+
@parameters begin R = 1 end
43+
@equations begin v ~ i * R end
44+
end
45+
46+
@model Capacitor begin
47+
@extend v, i = oneport = OnePort()
48+
@parameters begin C = 1 end
49+
@equations begin D(v) ~ i / C end
50+
end
51+
52+
@model Voltage begin
53+
@extend v, i = oneport = OnePort()
54+
@components begin V = RealInput() end
55+
@equations begin v ~ V.u end
56+
end
57+
58+
@model RC begin
59+
@components begin
60+
resistor = Resistor()
61+
capacitor = Capacitor()
62+
source = Voltage()
63+
constant = Constant()
64+
ground = Ground()
65+
end
66+
@equations begin
67+
connect(constant.output, source.V)
68+
connect(source.p, resistor.p)
69+
connect(resistor.n, capacitor.p)
70+
connect(capacitor.n, source.n, ground.g)
71+
end
72+
end
73+
@named rc = RC()
74+
@test length(equations(structural_simplify(rc))) == 1

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ using SafeTestsets, Test
2727
@safetestset "Reduction Test" begin include("reduction.jl") end
2828
@safetestset "ODAEProblem Test" begin include("odaeproblem.jl") end
2929
@safetestset "Components Test" begin include("components.jl") end
30+
@safetestset "Model Parsing Test" begin include("model_parsing.jl") end
3031
@safetestset "print_tree" begin include("print_tree.jl") end
3132
@safetestset "Error Handling" begin include("error_handling.jl") end
3233
@safetestset "StructuralTransformations" begin include("structural_transformation/runtests.jl") end

0 commit comments

Comments
 (0)