| 
1 | 1 | using ModelingToolkit  | 
2 | 2 | using ModelingToolkit: t_nounits as t, D_nounits as D, iscomplete, does_namespacing  | 
3 | 3 | 
 
  | 
4 |  | -@testset "System" begin  | 
5 |  | -    @variables x(t)  | 
6 |  | -    @parameters p  | 
7 |  | -    sys = System(D(x) ~ p * x, t; name = :inner)  | 
8 |  | -    @test !iscomplete(sys)  | 
9 |  | -    @test does_namespacing(sys)  | 
10 |  | - | 
11 |  | -    csys = complete(sys)  | 
12 |  | -    @test iscomplete(csys)  | 
13 |  | -    @test !does_namespacing(csys)  | 
14 |  | - | 
15 |  | -    nsys = toggle_namespacing(sys, false)  | 
16 |  | -    @test !iscomplete(nsys)  | 
17 |  | -    @test !does_namespacing(nsys)  | 
18 |  | - | 
19 |  | -    @test isequal(x, csys.x)  | 
20 |  | -    @test isequal(x, nsys.x)  | 
21 |  | -    @test !isequal(x, sys.x)  | 
22 |  | -    @test isequal(p, csys.p)  | 
23 |  | -    @test isequal(p, nsys.p)  | 
24 |  | -    @test !isequal(p, sys.p)  | 
25 |  | - | 
26 |  | -    @test_throws ["namespacing", "inner"] System(  | 
27 |  | -        Equation[], t; systems = [nsys], name = :a)  | 
28 |  | -end  | 
29 |  | - | 
30 |  | -@testset "SDESystem" begin  | 
31 |  | -    @variables x(t)  | 
32 |  | -    @parameters p  | 
33 |  | -    sys = SDESystem([D(x) ~ p * x], [x], t, [x], [p]; name = :inner)  | 
34 |  | -    @test !iscomplete(sys)  | 
35 |  | -    @test does_namespacing(sys)  | 
36 |  | - | 
37 |  | -    csys = complete(sys)  | 
38 |  | -    @test iscomplete(csys)  | 
39 |  | -    @test !does_namespacing(csys)  | 
40 |  | - | 
41 |  | -    nsys = toggle_namespacing(sys, false)  | 
42 |  | -    @test !iscomplete(nsys)  | 
43 |  | -    @test !does_namespacing(nsys)  | 
44 |  | - | 
45 |  | -    @test isequal(x, csys.x)  | 
46 |  | -    @test isequal(x, nsys.x)  | 
47 |  | -    @test !isequal(x, sys.x)  | 
48 |  | -    @test isequal(p, csys.p)  | 
49 |  | -    @test isequal(p, nsys.p)  | 
50 |  | -    @test !isequal(p, sys.p)  | 
51 |  | - | 
52 |  | -    @test_throws ["namespacing", "inner"] SDESystem(  | 
53 |  | -        Equation[], [], t; systems = [nsys], name = :a)  | 
54 |  | -end  | 
55 |  | - | 
56 |  | -@testset "DiscreteSystem" begin  | 
57 |  | -    @variables x(t)  | 
58 |  | -    @parameters p  | 
59 |  | -    k = ShiftIndex(t)  | 
60 |  | -    sys = System([x(k) ~ p * x(k - 1)], t; name = :inner)  | 
61 |  | -    @test !iscomplete(sys)  | 
62 |  | -    @test does_namespacing(sys)  | 
63 |  | - | 
64 |  | -    csys = complete(sys)  | 
65 |  | -    @test iscomplete(csys)  | 
66 |  | -    @test !does_namespacing(csys)  | 
67 |  | - | 
68 |  | -    nsys = toggle_namespacing(sys, false)  | 
69 |  | -    @test !iscomplete(nsys)  | 
70 |  | -    @test !does_namespacing(nsys)  | 
71 |  | - | 
72 |  | -    @test isequal(x, csys.x)  | 
73 |  | -    @test isequal(x, nsys.x)  | 
74 |  | -    @test !isequal(x, sys.x)  | 
75 |  | -    @test isequal(p, csys.p)  | 
76 |  | -    @test isequal(p, nsys.p)  | 
77 |  | -    @test !isequal(p, sys.p)  | 
78 |  | - | 
79 |  | -    @test_throws ["namespacing", "inner"] System(  | 
80 |  | -        Equation[], t; systems = [nsys], name = :a)  | 
81 |  | -end  | 
82 |  | - | 
83 |  | -@testset "ImplicitDiscreteSystem" begin  | 
84 |  | -    @variables x(t)  | 
85 |  | -    @parameters p  | 
86 |  | -    k = ShiftIndex(t)  | 
87 |  | -    sys = System([x(k) ~ p + x(k - 1) * x(k)], t; name = :inner)  | 
88 |  | -    @test !iscomplete(sys)  | 
89 |  | -    @test does_namespacing(sys)  | 
90 |  | - | 
91 |  | -    csys = complete(sys)  | 
92 |  | -    @test iscomplete(csys)  | 
93 |  | -    @test !does_namespacing(csys)  | 
94 |  | - | 
95 |  | -    nsys = toggle_namespacing(sys, false)  | 
96 |  | -    @test !iscomplete(nsys)  | 
97 |  | -    @test !does_namespacing(nsys)  | 
98 |  | - | 
99 |  | -    @test isequal(x, csys.x)  | 
100 |  | -    @test isequal(x, nsys.x)  | 
101 |  | -    @test !isequal(x, sys.x)  | 
102 |  | -    @test isequal(p, csys.p)  | 
103 |  | -    @test isequal(p, nsys.p)  | 
104 |  | -    @test !isequal(p, sys.p)  | 
105 |  | - | 
106 |  | -    @test_throws ["namespacing", "inner"] System(  | 
107 |  | -        Equation[], t; systems = [nsys], name = :a)  | 
108 |  | -end  | 
109 |  | - | 
110 |  | -@testset "NonlinearSystem" begin  | 
111 |  | -    @variables x  | 
112 |  | -    @parameters p  | 
113 |  | -    sys = System([x ~ p * x^2 + 1]; name = :inner)  | 
114 |  | -    @test !iscomplete(sys)  | 
115 |  | -    @test does_namespacing(sys)  | 
116 |  | - | 
117 |  | -    csys = complete(sys)  | 
118 |  | -    @test iscomplete(csys)  | 
119 |  | -    @test !does_namespacing(csys)  | 
120 |  | - | 
121 |  | -    nsys = toggle_namespacing(sys, false)  | 
122 |  | -    @test !iscomplete(nsys)  | 
123 |  | -    @test !does_namespacing(nsys)  | 
124 |  | - | 
125 |  | -    @test isequal(x, csys.x)  | 
126 |  | -    @test isequal(x, nsys.x)  | 
127 |  | -    @test !isequal(x, sys.x)  | 
128 |  | -    @test isequal(p, csys.p)  | 
129 |  | -    @test isequal(p, nsys.p)  | 
130 |  | -    @test !isequal(p, sys.p)  | 
131 |  | - | 
132 |  | -    @test_throws ["namespacing", "inner"] System(  | 
133 |  | -        Equation[]; systems = [nsys], name = :a)  | 
134 |  | -end  | 
135 |  | - | 
136 |  | -@testset "OptimizationSystem" begin  | 
137 |  | -    @variables x  | 
138 |  | -    @parameters p  | 
139 |  | -    sys = OptimizationSystem(p * x^2 + 1; name = :inner)  | 
140 |  | -    @test !iscomplete(sys)  | 
141 |  | -    @test does_namespacing(sys)  | 
142 |  | - | 
143 |  | -    csys = complete(sys)  | 
144 |  | -    @test iscomplete(csys)  | 
145 |  | -    @test !does_namespacing(csys)  | 
146 |  | - | 
147 |  | -    nsys = toggle_namespacing(sys, false)  | 
148 |  | -    @test !iscomplete(nsys)  | 
149 |  | -    @test !does_namespacing(nsys)  | 
150 |  | - | 
151 |  | -    @test isequal(x, csys.x)  | 
152 |  | -    @test isequal(x, nsys.x)  | 
153 |  | -    @test !isequal(x, sys.x)  | 
154 |  | -    @test isequal(p, csys.p)  | 
155 |  | -    @test isequal(p, nsys.p)  | 
156 |  | -    @test !isequal(p, sys.p)  | 
157 |  | - | 
158 |  | -    @test_throws ["namespacing", "inner"] OptimizationSystem(  | 
159 |  | -        []; systems = [nsys], name = :a)  | 
160 |  | -end  | 
161 |  | - | 
162 |  | -@testset "ConstraintsSystem" begin  | 
163 |  | -    @variables x  | 
164 |  | -    @parameters p  | 
165 |  | -    sys = ConstraintsSystem([x^2 + p ~ 0], [x], [p]; name = :inner)  | 
166 |  | -    @test !iscomplete(sys)  | 
167 |  | -    @test does_namespacing(sys)  | 
168 |  | - | 
169 |  | -    csys = complete(sys)  | 
170 |  | -    @test iscomplete(csys)  | 
171 |  | -    @test !does_namespacing(csys)  | 
172 |  | - | 
173 |  | -    nsys = toggle_namespacing(sys, false)  | 
174 |  | -    @test !iscomplete(nsys)  | 
175 |  | -    @test !does_namespacing(nsys)  | 
176 |  | - | 
177 |  | -    @test isequal(x, csys.x)  | 
178 |  | -    @test isequal(x, nsys.x)  | 
179 |  | -    @test !isequal(x, sys.x)  | 
180 |  | -    @test isequal(p, csys.p)  | 
181 |  | -    @test isequal(p, nsys.p)  | 
182 |  | -    @test !isequal(p, sys.p)  | 
183 |  | - | 
184 |  | -    @test_throws ["namespacing", "inner"] ConstraintsSystem(  | 
185 |  | -        [], [], []; systems = [nsys], name = :a)  | 
186 |  | -end  | 
 | 4 | +@variables x(t)  | 
 | 5 | +@parameters p  | 
 | 6 | +sys = System(D(x) ~ p * x, t; name = :inner)  | 
 | 7 | +@test !iscomplete(sys)  | 
 | 8 | +@test does_namespacing(sys)  | 
 | 9 | + | 
 | 10 | +csys = complete(sys)  | 
 | 11 | +@test iscomplete(csys)  | 
 | 12 | +@test !does_namespacing(csys)  | 
 | 13 | + | 
 | 14 | +nsys = toggle_namespacing(sys, false)  | 
 | 15 | +@test !iscomplete(nsys)  | 
 | 16 | +@test !does_namespacing(nsys)  | 
 | 17 | + | 
 | 18 | +@test isequal(x, csys.x)  | 
 | 19 | +@test isequal(x, nsys.x)  | 
 | 20 | +@test !isequal(x, sys.x)  | 
 | 21 | +@test isequal(p, csys.p)  | 
 | 22 | +@test isequal(p, nsys.p)  | 
 | 23 | +@test !isequal(p, sys.p)  | 
 | 24 | + | 
 | 25 | +@test_throws ["namespacing", "inner"] System(  | 
 | 26 | +    Equation[], t; systems = [nsys], name = :a)  | 
0 commit comments