Skip to content

Commit

Permalink
Improve coverage of src/compgraph_struct.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
mfasi committed Feb 2, 2024
1 parent 7075a70 commit 72c467a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compgraph_struct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function set_coeffs!(graph, x, cref = get_all_cref(graph))
end
if !(length(x) == length(cref))
error(
"Vector of coefficients and defined set of coefficients" *
"Vector of coefficients and defined set of coefficients " *
"do not have the same length.",
)
end
Expand Down
21 changes: 21 additions & 0 deletions test/graph_ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ using LinearAlgebra, Polynomials
add_lincomb!(graph, :AI, 2.0, :A, 2.0, :I)
add_mult!(graph, :Pout, :AI, :A)
add_output!(graph, :Pout)
try
rename_node!(graph, :Z, :Z_new)
catch e
@test e isa Exception
@test sprint(showerror, e) == "Node Z not present in the graph."
end

graph1 = deepcopy(graph)
rename_node!(graph1, :AI, :B)
Expand All @@ -92,4 +98,19 @@ using LinearAlgebra, Polynomials
del_output!(graph, :Pout)
@test isempty(graph.outputs)

# Setting and getting coefficients
graph = Compgraph()
add_lincomb!(graph, :B, [1.0], [:A])
add_output!(graph, :B)
set_coeffs!(graph, 2.0)
@test graph.coeffs[:B][1] == 2.0
try
set_coeffs!(graph, [1.0, 2.0])
catch e
@test e isa Exception
@test sprint(showerror, e) == "Vector of coefficients and defined " *
"set of coefficients do not have the same length."
end
@test get_coeffs(graph) == [2.0]

end
9 changes: 9 additions & 0 deletions test/topo_order.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ using LinearAlgebra
helper[:Z2] = -1
order = get_topo_order(g, priohelp = helper, will_not_dealloc = [:I])[1]
@test order[1:4] == [:X1; :X2; :X3; :Z1]

add_mult!(g, :Z, :B, :B)
try
get_topo_order(g)
catch e
@test e isa Exception
@test sprint(showerror, e) == "Graph is disconnected. Nodes " *
" [:Z] cannot be computed."
end
end

0 comments on commit 72c467a

Please sign in to comment.