Skip to content

Commit 98deb35

Browse files
committed
Update tests
1 parent 717f213 commit 98deb35

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

src/bipartite_graph.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,7 @@ end
102102
Base.eltype(::Type{<:BipartiteGraph{I}}) where I = I
103103
function Base.empty!(g::BipartiteGraph)
104104
foreach(empty!, g.fadjlist)
105-
if g.badjlist isa AbstractVector
106-
foreach(empty!, g.badjlist)
107-
else
108-
g.badjlist = 0
109-
end
105+
g.badjlist isa AbstractVector && foreach(empty!, g.badjlist)
110106
g.ne = 0
111107
if g.metadata !== nothing
112108
foreach(empty!, g.metadata)

test/structural_transformation/index_reduction.jl

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pendulum = ODESystem(eqs, t, [x, y, w, z, T], [L, g], name=:pendulum)
3434
pendulum = initialize_system_structure(pendulum)
3535
sss = structure(pendulum)
3636
@unpack graph, fullvars, varassoc = sss
37-
@test StructuralTransformations.matching(sss, varassoc .== 0) == map(x -> x == 0 ? StructuralTransformations.UNASSIGNED : x, [1, 0, 2, 0, 3, 4, 0, 0, 0])
37+
@test StructuralTransformations.matching(sss, varassoc .== 0) == map(x -> x == 0 ? StructuralTransformations.UNASSIGNED : x, [0, 1, 0, 0, 2, 0, 3, 0, 4])
3838

3939
sys, assign, eqassoc = StructuralTransformations.pantelides!(pendulum)
4040
sss = structure(sys)
@@ -48,18 +48,8 @@ scc = StructuralTransformations.find_scc(graph, assign)
4848
[6],
4949
]
5050

51-
@test graph.fadjlist == sort.([
52-
[1, 2],
53-
[3, 4],
54-
[5, 6, 7],
55-
[6, 8, 9],
56-
[7, 9],
57-
[1, 3, 7, 9],
58-
[1, 2, 5, 10],
59-
[3, 4, 8, 11],
60-
[1, 3, 7, 9, 10, 11],
61-
])
62-
@test varassoc == [10, 5, 11, 8, 0, 0, 1, 0, 3, 0, 0]
51+
@test graph.fadjlist == sort.([[1, 2], [4, 5], [3, 7, 8], [6, 7, 9], [3, 6], [2, 3, 5, 6], [1, 2, 8, 10], [4, 5, 9, 11], [2, 3, 5, 6, 10, 11]])
52+
@test varassoc == [8, 10, 2, 9, 11, 5, 0, 0, 0, 0, 0]
6353
#1: D(x) ~ w
6454
#2: D(y) ~ z
6555
#3: D(w) ~ T*x
@@ -100,22 +90,24 @@ using LinearAlgebra
10090
prob = ODEProblem(ODEFunction(first_order_idx1_pendulum),
10191
# [x, y, w, z, xˍt, yˍt, T]
10292
[1, 0, 0, 0, 0, 0, 0.0],# 0, 0, 0, 0],
103-
(0, 100.0),
93+
(0, 10.0),
10494
[1, 9.8],
10595
mass_matrix=calculate_massmatrix(first_order_idx1_pendulum))
10696
sol = solve(prob, Rodas5());
10797
#plot(sol, vars=(1, 2))
10898

10999
new_sys = dae_index_lowering(ModelingToolkit.ode_order_lowering(pendulum2))
110100

111-
prob_auto = ODEProblem(ODEFunction(new_sys),
112-
# [xˍt, yˍt, x, y, T]
113-
[0, 0, 1, 0, 0.0],# 0, 0, 0, 0],
114-
(0, 100.0),
115-
[1, 9.8],
116-
mass_matrix=calculate_massmatrix(new_sys))
101+
prob_auto = ODEProblem(new_sys,
102+
[D(x)=>0,
103+
D(y)=>0,
104+
x=>1,
105+
y=>0,
106+
T=>0.0],
107+
(0, 100.0),
108+
[1, 9.8])
117109
sol = solve(prob_auto, Rodas5());
118-
#plot(sol, vars=(3, 4))
110+
#plot(sol, vars=(x, y))
119111

120112
# Define some variables
121113
@parameters t L g
@@ -146,7 +138,7 @@ p = [
146138
g => 9.8
147139
]
148140

149-
prob_auto = ODEProblem(new_sys,u0,(0.0,100.0),p)
141+
prob_auto = ODEProblem(new_sys,u0,(0.0,10.0),p)
150142
sol = solve(prob_auto, Rodas5());
151143
#plot(sol, vars=(D(x), y))
152144

test/structural_transformation/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ sss = structure(sys)
2424
@test graph.fadjlist == sort.([[1, 2], [4, 5], [3, 7, 8], [6, 7, 9], [3, 6]])
2525
@test graph.badjlist == 9 == length(fullvars)
2626
@test ne(graph) == nnz(incidence_matrix(graph)) == 12
27-
@test nv(solvable_graph) == nv(solvable_graph) == 9 + 5
27+
@test nv(solvable_graph) == 9 + 5
2828
@test varassoc == [8, 0, 2, 9, 0, 5, 0, 0, 0]
2929

3030
se = collect(StructuralTransformations.𝑠edges(graph))

0 commit comments

Comments
 (0)