@@ -8,6 +8,89 @@ using ModelingToolkit: value, get_variables!
8
8
# Sets the default `t` to use.
9
9
t = default_t ()
10
10
11
+ # ## Reaction Constructor Tests ###
12
+
13
+ # Checks that `Reaction`s can be successfully created using various complicated inputs.
14
+ # Checks that the `Reaction`s have the correct type, and the correct net stoichiometries are generated.
15
+ let
16
+ # Declare symbolic variables.
17
+ @parameters k n1 n2:: Int32 x [isconstantspecies= true ]
18
+ @species X (t) Y (t) Z (t)
19
+ @variables A (t)
20
+
21
+ # Tries for different types of rates (should not matter).
22
+ for rate in (k, k* A, 2 , 3.0 , 4 // 3 )
23
+ # Creates `Reaction`s.
24
+ rx1 = Reaction (rate, [X], [])
25
+ rx2 = Reaction (rate, [x], [Y], [1.5 ], [1 ])
26
+ rx3 = Reaction (rate, [x, X], [], [n1 + n2, n2], [])
27
+ rx4 = Reaction (rate, [X, Y], [X, Y, Z], [2 // 3 , 3 ], [1 // 3 , 1 , 2 ])
28
+ rx5 = Reaction (rate, [X, Y], [X, Y, Z], [2 , 3 ], [1 , n1, n2])
29
+ rx6 = Reaction (rate, [X], [x], [n1], [1 ])
30
+
31
+ # Check `Reaction` types.
32
+ @test rx1 isa Reaction{Any,Int64}
33
+ @test rx2 isa Reaction{Any,Float64}
34
+ @test rx3 isa Reaction{Any,Any}
35
+ @test rx4 isa Reaction{Any,Rational{Int64}}
36
+ @test rx5 isa Reaction{Any,Any}
37
+ @test rx6 isa Reaction{Any,Any}
38
+
39
+ # Check `Reaction` net stoichiometries.
40
+ issetequal (rx1. netstoich, [X => - 1 ])
41
+ issetequal (rx2. netstoich, [x => - 1.5 , Y => 1.0 ])
42
+ issetequal (rx3. netstoich, [x => - n1 - n2, X => - n2])
43
+ issetequal (rx4. netstoich, [X => - 1 // 3 , Y => - 2 // 1 , Z => 2 // 1 ])
44
+ issetequal (rx5. netstoich, [X => - 1 , Y => n1 - 3 , Z => n2])
45
+ issetequal (rx6. netstoich, [X => - n1, x => 1 ])
46
+ end
47
+ end
48
+
49
+ # Tests that various `Reaction` constructors gives identical inputs.
50
+ let
51
+ # Declare symbolic variables.
52
+ @parameters k n1 n2:: Int32
53
+ @species X (t) Y (t) Z (t)
54
+ @variables A (t)
55
+
56
+ # Tests that the three-argument constructor generates correct result.
57
+ @test Reaction (k* A, [X], [Y, Z]) == Reaction (k* A, [X], [Y, Z], [1 ], [1 , 1 ])
58
+
59
+ # Tests that `[]` and `nothing` can be used interchangeably.
60
+ @test Reaction (k* A, [X, Z], nothing ) == Reaction (k* A, [X, Z], [])
61
+ @test Reaction (k* A, nothing , [Y, Z]) == Reaction (k* A, [], [Y, Z])
62
+ @test Reaction (k* A, [X, Z], nothing , [n1 + n2, 2 ], nothing ) == Reaction (k* A, [X, Z], [], [n1 + n2, 2 ], [])
63
+ @test Reaction (k* A, nothing , [Y, Z], nothing , [n1 + n2, 2 ]) == Reaction (k* A, [], [Y, Z], [], [n1 + n2, 2 ])
64
+ end
65
+
66
+ # Tests that various incorrect inputs yields errors.
67
+ let
68
+ # Declare symbolic variables.
69
+ @parameters k n1 n2:: Int32
70
+ @species X (t) Y (t) Z (t)
71
+ @variables A (t)
72
+
73
+ # Neither substrates nor products.
74
+ @test_throws ArgumentError Reaction (k* A, [], [])
75
+
76
+ # Substrate vector not of equal length to substrate stoichiometry vector.
77
+ @test_throws ArgumentError Reaction (k* A, [X, X, Z], [], [1 , 2 ], [])
78
+
79
+ # Product vector not of equal length to product stoichiometry vector.
80
+ @test_throws ArgumentError Reaction (k* A, [], [X, X, Z], [], [1 , 2 ])
81
+
82
+ # Repeated substrates.
83
+ @test_throws ArgumentError Reaction (k* A, [X, X, Z], [])
84
+
85
+ # Repeated products.
86
+ @test_throws ArgumentError Reaction (k* A, [], [Y, Z, Z])
87
+
88
+ # Non-valid reactants (parameter or variable).
89
+ @test_throws ArgumentError Reaction (k* A, [], [A])
90
+ @test_throws ArgumentError Reaction (k* A, [], [k])
91
+ end
92
+
93
+
11
94
# ## Test Basic Accessors ###
12
95
13
96
# Tests the `get_variables` function.
42
125
# Tests basic accessor functions.
43
126
# Tests that repeated metadata entries are not permitted.
44
127
let
45
- @variables t
46
128
@parameters k
47
129
@species X (t) X2 (t)
48
130
60
142
61
143
# Tests accessors for system without metadata.
62
144
let
63
- @variables t
64
145
@parameters k
65
146
@species X (t) X2 (t)
66
147
77
158
# Tests basic accessor functions.
78
159
# Tests various metadata types.
79
160
let
80
- @variables t
81
161
@parameters k
82
162
@species X (t) X2 (t)
83
163
109
189
110
190
# Tests the noise scaling metadata.
111
191
let
112
- @variables t
113
192
@parameters k η
114
193
@species X (t) X2 (t)
115
194
0 commit comments