Skip to content

Commit fbacee0

Browse files
author
Vincent Landau
committed
add method for weights, and corresponding test
1 parent f34531b commit fbacee0

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/graph_interface.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## With these methods defined, functions from Graphs should "just work"
33
import Graphs:
44
nv, ne, vertices, edges, eltype, edgetype, has_edge, has_vertex,
5-
inneighbors, outneighbors, is_directed, add_edge!
5+
inneighbors, outneighbors, is_directed, add_edge!, weights
66

77
import SimpleWeightedGraphs:
88
add_edge!, get_weight, add_vertex!, vertices
@@ -21,6 +21,8 @@ has_vertex(g::AbstractSpatialGraph, v) = has_vertex(g.graph, v)
2121
inneighbors(g::AbstractSpatialGraph, v) = inneighbors(g.graph, v)
2222
outneighbors(g::AbstractSpatialGraph, v) = outneighbors(g.graph, v)
2323
is_directed(g::AbstractSpatialGraph) = is_directed(g.graph)
24+
weights(g::AbstractSpatialGraph) = weights(g.graph)
25+
2426
function Base.zero(g::AbstractRasterGraph)
2527
if g.graph isa Graph
2628
RasterGraph(

test/graph_interface.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using SpatialGraphs, Test, Rasters, Graphs, SimpleWeightedGraphs
1+
using SpatialGraphs, Test, Rasters, Graphs, SimpleWeightedGraphs, SparseArrays
22
## This script tests methods for the LightGraph interface that aren't already
33
## used in other tests
44

@@ -16,6 +16,7 @@ num_edge = ne(rasgraph)
1616
@test vertices(rasgraph) == 1:maximum(rasgraph.vertex_raster)
1717
@test eltype(rasgraph) == Int # Should always be Int64 (or int32 on 32-bit)
1818
@test edgetype(rasgraph) == SimpleWeightedEdge{eltype(rasgraph), eltype(A_array)}
19+
@test typeof(weights(rasgraph)) <: SparseMatrixCSC # Make sure it's returning proper weights from the weighted graph
1920

2021
for i in 1:maximum(rasgraph.vertex_raster)
2122
@test has_vertex(rasgraph, i)

0 commit comments

Comments
 (0)