Skip to content

Commit af49bbd

Browse files
committed
add tests
1 parent 03b6df8 commit af49bbd

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

test/dsl/custom_functions.jl

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using ModelingToolkit: get_states, get_ps
66
using StableRNGs
77
rng = StableRNG(12345)
88

9-
### Tests Cutom Functions ###
9+
### Tests Custom Functions ###
1010
let
1111
new_hill(x, v, k, n) = v * x^n / (k^n + x^n)
1212
new_poly(x, p1, p2) = 0.5 * p1 * x^2
@@ -203,4 +203,66 @@ let
203203
@test isequal(Symbolics.derivative(Catalyst.hillar(X, Y, v, K, n), n),
204204
v * (X^n) * ((K^n + Y^n) * log(X) - (K^n) * log(K) - (Y^n) * log(Y)) /
205205
(K^n + X^n + Y^n)^2)
206+
end
207+
208+
### Tests Current Function Expansion ###
209+
210+
# Tests `ReactionSystem`s.
211+
let
212+
@variables t
213+
@species x(t) y(t)
214+
@parameters k v n
215+
rs1 = @reaction_network rs begin
216+
mm(x, v, k), 0 --> x
217+
mmr(x, v, k), 0 --> x
218+
hill(x, v, k, n), 0 --> x
219+
hillr(x, v, k, n), 0 --> x
220+
hillar(x, y, v, k, n), 0 --> x
221+
end
222+
rs2 = @reaction_network rs begin
223+
v * x / (x + k), 0 --> x
224+
v * k / (x + k), 0 --> x
225+
v * (x^n) / (x^n + k^n), 0 --> x
226+
v * (k^n) / (x^n + k^n), 0 --> x
227+
v * (x^n) / (x^n + y^n + k^n), 0 --> x
228+
end
229+
230+
@test Catalyst.expand_registered_functions(rs1) == rs2
231+
end
232+
233+
# Tests `Reaction`s.
234+
let
235+
@variables t
236+
@species x(t) y(t)
237+
@parameters k v n
238+
239+
r1 = @reaction mm(x, v, k), 0 --> x
240+
r2 = @reaction mmr(x, v, k), 0 --> x
241+
r3 = @reaction hill(x, v, k, n), 0 --> x
242+
r4 = @reaction hillr(x, v, k, n), 0 --> x
243+
r5 = @reaction hillar(x, y, v, k, n), 0 --> x + y
244+
245+
@test isequal(Catalyst.expand_registered_functions(r1).rate, v * x / (x + k))
246+
@test isequal(Catalyst.expand_registered_functions(r2).rate, v * k / (x + k))
247+
@test isequal(Catalyst.expand_registered_functions(r3).rate, v * (x^n) / (x^n + k^n))
248+
@test isequal(Catalyst.expand_registered_functions(r4).rate, v * (k^n) / (x^n + k^n))
249+
@test isequal(Catalyst.expand_registered_functions(r5).rate, v * (x^n) / (x^n + y^n + k^n))
250+
end
251+
252+
# Tests `Equation`s.
253+
let
254+
@variables T X(T) Y(T)
255+
@parameters K V N
256+
257+
eq1 = 0 ~ mm(X, V, K)
258+
eq2 = 0 ~ mmr(X, V, K)
259+
eq3 = 0 ~ hill(X, V, K, N)
260+
eq4 = 0 ~ hillr(X, V, K, N)
261+
eq5 = 0 ~ hillar(X, Y, V, K, N)
262+
263+
@test isequal(Catalyst.expand_registered_functions(eq1), 0 ~ V * X / (X + K))
264+
@test isequal(Catalyst.expand_registered_functions(eq2), 0 ~ V * K / (X + K))
265+
@test isequal(Catalyst.expand_registered_functions(eq3), 0 ~ V * (X^N) / (X^N + K^N))
266+
@test isequal(Catalyst.expand_registered_functions(eq4), 0 ~ V * (K^N) / (X^N + K^N))
267+
@test isequal(Catalyst.expand_registered_functions(eq5), 0 ~ V * (X^N) / (X^N + Y^N + K^N))
206268
end

0 commit comments

Comments
 (0)