Skip to content

Commit 3b78341

Browse files
committed
tests in testsets
1 parent 37a57e0 commit 3b78341

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

test/Blocks/discrete.jl

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -235,50 +235,56 @@ end
235235
## Delay
236236
# ==============================================================================
237237

238-
@mtkmodel DelayModel begin
239-
@components begin
240-
fake_plant = FirstOrder(T = 1e-4) # Included due to bug with only discrete-time systems
241-
input = Step(start_time = 2, smooth = false)
242-
sampler = Sampler(; dt = 1)
243-
delay = Delay(n = 3)
244-
zoh = ZeroOrderHold()
245-
end
246-
@equations begin
247-
connect(input.output, sampler.input)
248-
connect(sampler.output, delay.input)
249-
connect(delay.output, zoh.input)
250-
connect(zoh.output, fake_plant.input)
238+
@testset "delay" begin
239+
@mtkmodel DelayModel begin
240+
@components begin
241+
fake_plant = FirstOrder(T = 1e-4) # Included due to bug with only discrete-time systems
242+
input = Step(start_time = 2, smooth = false)
243+
sampler = Sampler(; dt = 1)
244+
delay = Delay(n = 3)
245+
zoh = ZeroOrderHold()
246+
end
247+
@equations begin
248+
connect(input.output, sampler.input)
249+
connect(sampler.output, delay.input)
250+
connect(delay.output, zoh.input)
251+
connect(zoh.output, fake_plant.input)
252+
end
251253
end
252-
end
253254

254-
@mtkbuild m = DelayModel()
255-
prob = ODEProblem(
256-
m, [m.delay.u(k - 3) => 0, m.delay.u(k - 2) => 0, m.delay.u(k - 1) => 0], (0.0, 10.0))
257-
sol = solve(prob, Tsit5(), kwargshandle = KeywordArgSilent)
255+
@mtkbuild m = DelayModel()
256+
prob = ODEProblem(
257+
m, [m.delay.u(k - 3) => 0, m.delay.u(k - 2) => 0, m.delay.u(k - 1) => 0], (
258+
0.0, 10.0))
259+
sol = solve(prob, Tsit5(), kwargshandle = KeywordArgSilent)
258260

259-
@test reduce(vcat, sol((0:10) .+ 1e-2))[:][zeros(5); ones(6)] atol=1e-2
261+
@test reduce(vcat, sol((0:10) .+ 1e-2))[:][zeros(5); ones(6)] atol=1e-2
262+
end
260263

261264
# ==============================================================================
262265
## Difference
263266
# ==============================================================================
264267
using ModelingToolkitStandardLibrary.Blocks
265-
k = ShiftIndex(Clock(t, 1))
266268

267-
@mtkmodel DiffModel begin
268-
@components begin
269-
input = Step(start_time = 2, smooth = false)
270-
diff = Blocks.Difference(z = k)
271-
zoh = Blocks.ZeroOrderHold()
272-
plant = FirstOrder(T = 1e-4) # Included due to bug with only discrete-time systems
273-
end
274-
@equations begin
275-
connect(input.output, diff.input)
276-
connect(diff.output, zoh.input)
277-
connect(zoh.output, plant.input)
269+
@testset "Difference" begin
270+
k = ShiftIndex(Clock(t, 1))
271+
272+
@mtkmodel DiffModel begin
273+
@components begin
274+
input = Step(start_time = 2, smooth = false)
275+
diff = Blocks.Difference(z = k)
276+
zoh = Blocks.ZeroOrderHold()
277+
plant = FirstOrder(T = 1e-4) # Included due to bug with only discrete-time systems
278+
end
279+
@equations begin
280+
connect(input.output, diff.input)
281+
connect(diff.output, zoh.input)
282+
connect(zoh.output, plant.input)
283+
end
278284
end
279-
end
280285

281-
@mtkbuild m = DiffModel()
282-
prob = ODEProblem(m, Dict(m.diff.u(k - 1) => 0), (0.0, 10.0))
283-
sol = solve(prob, Tsit5(), kwargshandle = KeywordArgSilent)
284-
@test reduce(vcat, sol((0:10) .+ 1e-2))[:][zeros(2); 1; zeros(8)] atol=1e-2
286+
@mtkbuild m = DiffModel()
287+
prob = ODEProblem(m, Dict(m.diff.u(k - 1) => 0), (0.0, 10.0))
288+
sol = solve(prob, Tsit5(), kwargshandle = KeywordArgSilent, dtmax = 0.01)
289+
@test reduce(vcat, sol((0:10) .+ 1e-2))[:][zeros(2); 1; zeros(8)] atol=1e-2
290+
end

0 commit comments

Comments
 (0)