Skip to content

Commit 2f5ced4

Browse files
committed
Test against incidence"..." structs, not repr
1 parent b1d0e49 commit 2f5ced4

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

test/incidence.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -151,61 +151,61 @@ dependencies(row) = sort(rowvals(row) .=> nonzeros(row), by = first)
151151
incidence = @infer_incidence t
152152
@test incidence.typ === Const(0.0)
153153
@test dependencies(incidence.row) == [1 => 1]
154-
@test repr(incidence) == "Incidence(t)"
154+
@test incidence == incidence"t"
155155

156156
incidence = @infer_incidence 5. +ᵢ u₁
157157
@test incidence.typ === Const(5.0)
158158
@test dependencies(incidence.row) == [2 => 1]
159-
@test repr(incidence) == "Incidence(5.0 + u₁)"
159+
@test incidence == incidence"5.0 + u₁"
160160

161161
incidence = @infer_incidence 5.0 +ᵢ t +ᵢ u₁
162162
@test incidence.typ === Const(5.0)
163163
@test dependencies(incidence.row) == [1 => 1, 2 => 1]
164-
@test repr(incidence) == "Incidence(5.0 + t + u₁)"
164+
@test incidence == incidence"5.0 + t + u₁"
165165

166166
incidence = @infer_incidence t *ᵢ u₁
167167
@test incidence.typ === Const(0.0)
168168
@test dependencies(incidence.row) == [1 => linear_state_dependent, 2 => linear_time_dependent]
169-
@test repr(incidence) == "Incidence(f(∝t, ∝u₁))"
169+
@test incidence == incidence"f(∝ₛt, ∝ₜu₁)"
170170

171171
incidence = @infer_incidence u₁
172172
@test incidence.typ === Const(0.0)
173173
@test dependencies(incidence.row) == [2 => 1]
174-
@test repr(incidence) == "Incidence(u₁)"
174+
@test incidence == incidence"u₁"
175175

176176
incidence = @infer_incidence u₁ +ᵢ u₂
177177
@test incidence.typ === Const(0.0)
178178
@test dependencies(incidence.row) == [2 => 1, 3 => 1]
179-
@test repr(incidence) == "Incidence(u₁ + u₂)"
179+
@test incidence == incidence"u₁ + u₂"
180180

181181
incidence = @infer_incidence u₁ *ᵢ u₂
182182
@test incidence.typ === Const(0.0)
183183
@test dependencies(incidence.row) == [2 => linear_state_dependent, 3 => linear_state_dependent]
184-
@test repr(incidence) == "Incidence(f(∝u₁, ∝u₂))"
184+
@test incidence == incidence"f(∝ₛu₁, ∝ₛu₂)"
185185

186186
incidence = @infer_incidence (2.0 +ᵢ u₁) *ᵢ (3.0 +ᵢ u₂)
187187
@test incidence.typ === Const(6.0)
188188
@test dependencies(incidence.row) == [2 => linear_state_dependent, 3 => linear_state_dependent]
189-
@test repr(incidence) == "Incidence(6.0 + f(∝u₁, ∝u₂))"
189+
@test incidence == incidence"6.0 + f(∝ₛu₁, ∝ₛu₂)"
190190

191191
incidence = @infer_incidence (2.0 +ᵢ u₁) *ᵢ (3.0 +ᵢ u₁ *ᵢ u₂)
192192
@test incidence.typ === Const(6.0)
193193
@test dependencies(incidence.row) == [2 => nonlinear, 3 => linear_state_dependent]
194-
@test repr(incidence) == "Incidence(6.0 + f(u₁, ∝u₂))"
194+
@test incidence == incidence"6.0 + f(u₁, ∝ₛu₂)"
195195

196196
incidence = @infer_incidence (2.0 +ᵢ u₁) *ᵢ (3.0 +ᵢ u₁ *ᵢ u₂) +ᵢ u₃
197197
@test incidence.typ === Const(6.0)
198198
@test dependencies(incidence.row) == [2 => nonlinear, 3 => linear_state_dependent, 4 => 1.0]
199-
@test repr(incidence) == "Incidence(6.0 + u₃ + f(u₁, ∝u₂))"
199+
@test incidence == incidence"6.0 + u₃ + f(u₁, ∝ₛu₂)"
200200

201201
incidence = @infer_incidence (u₁ +ᵢ u₂) *ᵢ t
202202
@test incidence.typ === Const(0.0)
203203
@test dependencies(incidence.row) == [1 => linear_state_dependent, (2:3 .=> linear_time_dependent)...]
204-
@test repr(incidence) == "Incidence(f(∝t, ∝u₁, ∝u₂))"
204+
@test incidence == incidence"f(∝ₛt, ∝ₜu₁, ∝ₜu₂)"
205205

206206
incidence = @infer_incidence u₁ *ᵢ u₂ +ᵢ (u₁ +ᵢ t) *ᵢ u₃
207-
@test dependencies(incidence.row) == [1 => linear_state_dependent, 2 => linear_state_dependent, 3 => linear_state_dependent, 4 => linear_time_and_state_dependent]
208-
@test repr(incidence) == "Incidence(f(∝t, ∝u₁, ∝u₂, ∝u₃))"
207+
@test dependencies(incidence.row) == [(1:3 .=> linear_state_dependent)..., 4 => linear_time_and_state_dependent]
208+
@test incidence == incidence"f(∝ₛt, ∝ₛu₁, ∝ₛu₂, ∝ₜₛu₃)"
209209

210210
# IPO
211211

@@ -214,64 +214,64 @@ dependencies(row) = sort(rowvals(row) .=> nonzeros(row), by = first)
214214

215215
incidence = @infer_incidence 1.0t * 3.0
216216
@test dependencies(incidence.row) == [1 => linear]
217-
@test repr(incidence) == "Incidence(a + cₜ * t)"
217+
@test incidence == incidence"a + ∝t"
218218

219219
incidence = @infer_incidence (1.0 + u₁ +ᵢ u₂) * 1.0
220220
@test incidence.typ === Float64
221221
@test dependencies(incidence.row) == (2:3 .=> linear_state_dependent)
222-
@test repr(incidence) == "Incidence(a + f(∝u₁, ∝u₂))"
222+
@test incidence == incidence"a + f(∝ₛu₁, ∝ₛu₂)"
223223

224224
incidence = @infer_incidence (2.0 + u₁) * (3.0 + u₂)
225225
@test dependencies(incidence.row) == [2 => linear_state_dependent, 3 => linear_state_dependent]
226-
@test repr(incidence) == "Incidence(a + f(∝u₁, ∝u₂))"
226+
@test incidence == incidence"a + f(∝ₛu₁, ∝ₛu₂)"
227227

228228
incidence = @infer_incidence 5.0 + u₁
229229
@test incidence.typ === Const(5.0)
230230
@test dependencies(incidence.row) == [2 => 1]
231-
@test repr(incidence) == "Incidence(5.0 + u₁)"
231+
@test incidence == incidence"5.0 + u₁"
232232

233233
incidence = @infer_incidence u₁ * u₁
234234
@test dependencies(incidence.row) == [2 => nonlinear]
235-
@test repr(incidence) == "Incidence(f(u₁))"
235+
@test incidence == incidence"f(u₁)"
236236

237237
incidence = @infer_incidence t * t
238238
@test dependencies(incidence.row) == [1 => nonlinear]
239-
@test repr(incidence) == "Incidence(f(t))"
239+
@test incidence == incidence"f(t)"
240240

241241
mul3(a, b, c) = a *ᵢ (b *ᵢ c)
242242
incidence = @infer_incidence mul3(t, u₁, u₂)
243243
@test dependencies(incidence.row) == [1 => linear_state_dependent, (2:3 .=> linear_time_and_state_dependent)...]
244-
@test repr(incidence) == "Incidence(f(∝t, ∝u₁, ∝u₂))"
244+
@test incidence == incidence"f(∝ₛt, ∝ₜₛu₁, ∝ₜₛu₂)"
245245

246246
incidence = @infer_incidence mul3(t, u₁, u₁)
247247
@test dependencies(incidence.row) == [1 => linear_state_dependent, 2 => nonlinear]
248-
@test repr(incidence) == "Incidence(f(∝t, u₁))"
248+
@test incidence == incidence"f(∝ₛt, u₁)"
249249

250250
incidence = @infer_incidence mul3(t, u₁, t)
251251
# If we knew which state is used for state dependence,
252252
# state should be inferred as linear_time_dependent.
253253
@test dependencies(incidence.row) == [1 => nonlinear, 2 => linear_time_and_state_dependent]
254-
@test repr(incidence) == "Incidence(f(t, ∝u₁))"
254+
@test incidence == incidence"f(t, ∝ₜₛu₁)"
255255

256256
incidence = @infer_incidence mul3(u₂, u₁, u₂)
257257
@test dependencies(incidence.row) == [2 => linear_state_dependent, 3 => nonlinear]
258-
@test repr(incidence) == "Incidence(f(∝u₁, u₂))"
258+
@test incidence == incidence"f(∝ₛu₁, u₂)"
259259

260260
_muladd(a, b, c) = a +ᵢ b *ᵢ c
261261
incidence = @infer_incidence _muladd(u₁, u₁, u₂)
262262
# We widen to `nonlinear` because we can't yet infer that `b := u₁` is
263263
# not multiplied by `a := u₁`. The solution would be to see that `a`
264264
# is linear but state-independent and therefore can't be a factor of `b`.
265265
@test dependencies(incidence.row) == [2 => nonlinear, 3 => linear_state_dependent]
266-
@test repr(incidence) == "Incidence(f(u₁, ∝u₂))"
266+
@test incidence == incidence"f(u₁, ∝ₛu₂)"
267267

268268
# Here we still wouldn't be able to use the above solution because `a := u₁` is state-dependent.
269269
# So `c := u₁` having a state-dependent coefficient might be multiplied by `a` a.k.a itself
270270
# which would make it nonlinear, so IPO can only infer `u₁` as nonlinear.
271271
_muladd2(a, b, c, d) = d *ᵢ a +ᵢ b *ᵢ c
272272
incidence = @infer_incidence _muladd2(u₁, u₂, u₁, u₃)
273273
@test dependencies(incidence.row) == [2 => nonlinear, 3 => linear_state_dependent, 4 => linear_state_dependent]
274-
@test repr(incidence) == "Incidence(f(u₁, ∝u₂, ∝u₃))"
274+
@test incidence == incidence"f(u₁, ∝ₛu₂, ∝ₛu₃)"
275275
end;
276276

277277
end

0 commit comments

Comments
 (0)