Skip to content

Commit f7da821

Browse files
committed
Add tests
1 parent c48e49c commit f7da821

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/systems/alias_elimination.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -845,11 +845,13 @@ function locally_structure_simplify!(adj_row, pivot_var, ag)
845845
# p = -(c / v) * a
846846
if iszero(alias_val)
847847
alias_candidate = 0
848-
elseif r == 0 && (d == 1 || d == -1)
849-
d, r = divrem(alias_val, pivot_val)
850-
alias_candidate = -d => alias_var
851848
else
852-
return false
849+
d, r = divrem(alias_val, pivot_val)
850+
if r == 0 && (d == 1 || d == -1)
851+
alias_candidate = -d => alias_var
852+
else
853+
return false
854+
end
853855
end
854856
end
855857

test/reduction.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,20 @@ new_sys = structural_simplify(sys)
269269
new_sys = structural_simplify(sys)
270270
@test equations(new_sys) == [D(x) ~ 1 - x]
271271
@test observed(new_sys) == [y ~ -D(x)]
272+
273+
@variables t x(t) y(t) a(t) b(t)
274+
D = Differential(t)
275+
eqs = [x ~ 0
276+
D(x) ~ y
277+
a ~ b + y]
278+
@named sys = ODESystem(eqs, t, [x, y, a, b], [])
279+
ss = alias_elimination(sys)
280+
@test isempty(equations(ss))
281+
@test observed(ss) == ([a, x, D(x), b, y] .~ 0)
282+
283+
eqs = [x ~ 0
284+
D(x) ~ x + y]
285+
@named sys = ODESystem(eqs, t, [x, y], [])
286+
ss = alias_elimination(sys)
287+
@test isempty(equations(ss))
288+
@test observed(ss) == ([x, D(x), y] .~ 0)

0 commit comments

Comments
 (0)