Skip to content

Commit 09cb67c

Browse files
Weights throws if called without key for multiple edge values
1 parent 7b97806 commit 09cb67c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/matrices.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,15 @@ without any edge values.
315315
"""
316316
function weights end
317317

318-
LG.weights(g::ZeroEdgeValGraph) = LG.DefaultDistance(nv(g))
319-
320-
LG.weights(g::OneEdgeValGraph; kwargs...) = LG.weights(g, 1; kwargs...)
321-
322318
function LG.weights(g::AbstractValGraph, key; zerovalue=zero(edgevals_type(g, key)))
323319

324320
return ValMatrix(g, key, zerovalue)
325321
end
326322

323+
function LG.weights(g::AbstractValGraph; kwargs...)
324+
325+
g isa ZeroEdgeValGraph && return LG.DefaultDistance(nv(g))
326+
g isa OneEdgeValGraph && return weights(g, 1; kwargs...)
327+
328+
throw(ArgumentError("g has more than one edge value key. Must specify key."))
329+
end

test/matrices.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ using LightGraphs: DefaultDistance
179179
@test weights(g) == DefaultDistance(nv(g))
180180
end
181181

182+
@testset "weights for graph with two edge values and no key specified" begin
183+
184+
@test_throws ArgumentError weights(ValGraph(3, edgeval_types=(a=Int, b=String)))
185+
@test_throws ArgumentError weights(ValDiGraph(2, edgeval_types=(Int, String)); zerovalue=nothing)
186+
end
187+
182188
@testset "convert AdjacencyMatrix to SparseMatrixCSC" begin
183189

184190
g1 = ValGraph{Int8}(4)

0 commit comments

Comments
 (0)