@@ -157,6 +157,103 @@ end
157157 @test sol[prod. output. u] ≈ 2 * sin .(2 * pi * sol. t)
158158end
159159
160+ @testset " Power" begin
161+ @named c1 = Sine (; frequency = 1 )
162+ @named c2 = Constant (; k = 2 )
163+ @named pow = Power (;)
164+ @named int = Integrator (; k = 1 )
165+ @named model = ODESystem (
166+ [
167+ connect (c1. output, pow. base),
168+ connect (c2. output, pow. exponent),
169+ connect (pow. output, int. input)
170+ ],
171+ t,
172+ systems = [int, pow, c1, c2])
173+ sys = structural_simplify (model)
174+ prob = ODEProblem (sys, Pair[int. x => 0.0 ], (0.0 , 1.0 ))
175+ sol = solve (prob, Rodas4 ())
176+ @test isequal (unbound_inputs (sys), [])
177+ @test sol. retcode == Success
178+ @test sol[pow. output. u] ≈ sin .(2 * pi * sol. t) .^ 2
179+ end
180+
181+ @testset " Modulo" begin
182+ @named c1 = Ramp (height = 2 , duration = 1 , offset = 1 , start_time = 0 , smooth = false )
183+ @named c2 = Constant (; k = 1 )
184+ @named modl = Modulo (;)
185+ @named model = ODESystem (
186+ [
187+ connect (c1. output, modl. dividend),
188+ connect (c2. output, modl. divisor)
189+ ],
190+ t,
191+ systems = [modl, c1, c2])
192+ sys = structural_simplify (model)
193+ prob = ODEProblem (sys, [], (0.0 , 1.0 ))
194+ sol = solve (prob, Rodas4 ())
195+ @test isequal (unbound_inputs (sys), [])
196+ @test sol. retcode == Success
197+ @test sol[modl. remainder. u] ≈ mod .(2 * sol. t,1 )
198+ end
199+
200+ @testset " UnaryMinus" begin
201+ @named c1 = Sine (; frequency = 1 )
202+ @named minu = UnaryMinus (;)
203+ @named int = Integrator (; k = 1 )
204+ @named model = ODESystem (
205+ [
206+ connect (c1. output, minu. input),
207+ connect (minu. output, int. input)
208+ ],
209+ t,
210+ systems = [int, minu, c1])
211+ sys = structural_simplify (model)
212+ prob = ODEProblem (sys, Pair[int. x => 0.0 ], (0.0 , 1.0 ))
213+ sol = solve (prob, Rodas4 ())
214+ @test isequal (unbound_inputs (sys), [])
215+ @test sol. retcode == Success
216+ @test sol[minu. output. u] ≈ - sin .(2 * pi * sol. t)
217+ end
218+
219+ @testset " Floor" begin
220+ @named c1 = Sine (; frequency = 1 )
221+ @named flr = Floor (;)
222+ @named int = Integrator (; k = 1 )
223+ @named model = ODESystem (
224+ [
225+ connect (c1. output, flr. input),
226+ connect (flr. output, int. input)
227+ ],
228+ t,
229+ systems = [int, flr, c1])
230+ sys = structural_simplify (model)
231+ prob = ODEProblem (sys, Pair[int. x => 0.0 ], (0.0 , 1.0 ))
232+ sol = solve (prob, Rodas4 ())
233+ @test isequal (unbound_inputs (sys), [])
234+ @test sol. retcode == Success
235+ @test sol[flr. output. u] ≈ floor .(sin .(2 * pi * sol. t))
236+ end
237+
238+ @testset " Ceil" begin
239+ @named c1 = Sine (; frequency = 1 )
240+ @named cel = Ceil (;)
241+ @named int = Integrator (; k = 1 )
242+ @named model = ODESystem (
243+ [
244+ connect (c1. output, cel. input),
245+ connect (cel. output, int. input)
246+ ],
247+ t,
248+ systems = [int, cel, c1])
249+ sys = structural_simplify (model)
250+ prob = ODEProblem (sys, Pair[int. x => 0.0 ], (0.0 , 1.0 ))
251+ sol = solve (prob, Rodas4 ())
252+ @test isequal (unbound_inputs (sys), [])
253+ @test sol. retcode == Success
254+ @test sol[cel. output. u] ≈ ceil .(sin .(2 * pi * sol. t))
255+ end
256+
160257@testset " Division" begin
161258 @named c1 = Sine (; frequency = 1 )
162259 @named c2 = Constant (; k = 2 )
0 commit comments