Skip to content

Commit ba9af5b

Browse files
authored
fixed up codecov on core, simplegraphs, and interface (#1177)
* fixed up codecov on core, simplegraphs, and interface * remove duplicate enumerate_paths * inferred betweenness
1 parent 171df83 commit ba9af5b

File tree

7 files changed

+24
-30
lines changed

7 files changed

+24
-30
lines changed

src/Parallel/shortestpaths/johnson.jl

-22
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,3 @@ distmx::AbstractMatrix{T}=weights(g)) where T <: Real where U <: Integer
3737
return JohnsonState(dists, parents)
3838
end
3939

40-
function enumerate_paths(s::JohnsonState{T,U}, v::Integer) where T <: Real where U <: Integer
41-
pathinfo = s.parents[v, :]
42-
paths = Vector{Vector{U}}()
43-
for i in 1:length(pathinfo)
44-
if (i == v) || (s.dists[v, i] == typemax(T))
45-
push!(paths, Vector{U}())
46-
else
47-
path = Vector{U}()
48-
currpathindex = i
49-
while currpathindex != 0
50-
push!(path, currpathindex)
51-
currpathindex = pathinfo[currpathindex]
52-
end
53-
push!(paths, reverse(path))
54-
end
55-
end
56-
return paths
57-
end
58-
59-
enumerate_paths(s::JohnsonState) = [enumerate_paths(s, v) for v in 1:size(s.parents, 1)]
60-
enumerate_paths(st::JohnsonState, s::Integer, d::Integer) = enumerate_paths(st, s)[d]
61-

test/core.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
g5w = WheelGraph(5)
1414
for g in testgraphs(g5w)
15-
@test @inferred(indegree(g, 1)) == @inferred(outdegree(g, 1)) == @inferred(degree(g, 1)) == 4
15+
@test @inferred(indegree(g, 1)) == @inferred(outdegree(g, 1)) == 4
16+
@test degree(g, 1) == 4 # explicit codecov
1617
@test @inferred(indegree(g)) == @inferred(outdegree(g)) == @inferred(degree(g)) == [4, 3, 3, 3, 3]
1718

1819
@test @inferred(Δout(g)) == @inferred(Δin(g)) == @inferred(Δ(g)) == 4
@@ -24,7 +25,8 @@
2425

2526
@test z1 == z2 == z3 == Dict(4 => 1, 3 => 4)
2627

27-
@test @inferred(neighbors(g, 2)) == @inferred(all_neighbors(g, 2)) == [1, 3, 5]
28+
@test @inferred(neighbors(g, 2)) == [1, 3, 5]
29+
@test @inferred(all_neighbors(g, 2)) == [1, 3, 5]
2830
@test @inferred(common_neighbors(g, 1, 5)) == [2, 4]
2931

3032
gsl = copy(g)

test/interface.jl

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ mutable struct DummyEdge <: AbstractEdge{Int} end
3333
has_edge,
3434
]
3535
@test_throws ErrorException graphfunedge(dummygraph, dummyedge)
36+
@test_throws ErrorException graphfunedge(dummygraph, 1, 2)
3637
end
3738

3839
end # testset

test/parallel/centrality/betweenness.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
@test all(isapprox(y, yd))
2020

2121

22-
xt = Parallel.betweenness_centrality(g, 3; parallel=:threads)
22+
xt = @inferred(Parallel.betweenness_centrality(g, 3; parallel=:threads))
2323
@test length(xt) == 50
24-
xd = Parallel.betweenness_centrality(g, 3; parallel=:distributed)
24+
xd = @inferred(Parallel.betweenness_centrality(g, 3; parallel=:distributed))
2525
@test length(xd) == 50
2626

27-
xt2 = Parallel.betweenness_centrality(g, collect(1:20); parallel=:threads)
27+
xt2 = @inferred(Parallel.betweenness_centrality(g, collect(1:20); parallel=:threads))
2828
@test length(xt2) == 50
29-
xd2 = Parallel.betweenness_centrality(g, collect(1:20); parallel=:distributed)
29+
xd2 = @inferred(Parallel.betweenness_centrality(g, collect(1:20); parallel=:distributed))
3030
@test length(xd2) == 50
3131
end
3232
@test @inferred(Parallel.betweenness_centrality(s1; parallel=:threads)) == [0, 1, 0]
3333
@test @inferred(Parallel.betweenness_centrality(s1; parallel=:distributed)) == [0, 1, 0]
3434

35-
@test Parallel.betweenness_centrality(s2; parallel=:threads) == [0, 0.5, 0]
36-
@test Parallel.betweenness_centrality(s2; parallel=:distributed) == [0, 0.5, 0]
35+
@test @inferred(Parallel.betweenness_centrality(s2; parallel=:threads)) == [0, 0.5, 0]
36+
@test @inferred(Parallel.betweenness_centrality(s2; parallel=:distributed)) == [0, 0.5, 0]
3737

3838
g = SimpleGraph(2)
3939
add_edge!(g, 1, 2)

test/simplegraphs/runtests.jl

+5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
using LightGraphs.SimpleGraphs
22

33
import LightGraphs.SimpleGraphs: fadj, badj, adj
4+
import LightGraphs.edgetype, LightGraphs.has_edge
45
using Statistics: mean
56

67
struct DummySimpleGraph <: AbstractSimpleGraph{Int} end
8+
struct DummySimpleEdge <: AbstractSimpleEdge{Int} end
9+
DummySimpleEdge(x...) = DummySimpleEdge()
10+
LightGraphs.edgetype(g::DummySimpleGraph) = DummySimpleEdge
11+
has_edge(::DummySimpleGraph, ::DummySimpleEdge) = true
712

813
# function to check if the invariants for SimpleGraph and SimpleDiGraph holds
914
function isvalid_simplegraph(g::SimpleGraph{T}) where {T <: Integer}

test/simplegraphs/simpleedgeiter.jl

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@testset "SimpleEdgeIter" begin
22
ga = @inferred(SimpleGraph(10, 20; seed=1))
33
gb = @inferred(SimpleGraph(10, 20; seed=1))
4+
gd = SimpleDiGraph{UInt8}(10, 20)
45
@test sprint(show, edges(ga)) == "SimpleEdgeIter 20"
56
# note: we don't get the first iterator state,
67
#since iterate returns the state after taking the first value
@@ -19,6 +20,9 @@
1920
@test @inferred(eltype(edges(ga))) == eltype(typeof(edges(ga))) == edgetype(ga)
2021
@test eltype(collect(edges(ga))) == edgetype(ga)
2122

23+
# codecov for eltype(::Type{SimpleEdgeIter{SimpleDiGraph{T}}}) where {T} = SimpleDiGraphEdge{T}
24+
@test @inferred(eltype(edges(gd))) == eltype(typeof(edges(gd))) == edgetype(gd) == SimpleDiGraphEdge{UInt8}
25+
2226
ga = @inferred(SimpleDiGraph(10, 20; seed=1))
2327
gb = @inferred(SimpleDiGraph(10, 20; seed=1))
2428
@test @inferred(edges(ga)) == edges(gb)

test/simplegraphs/simplegraphs.jl

+4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import Random
1212

1313
@test @inferred(ne(SimpleGraph(PathDiGraph(5)))) == 4
1414
@test @inferred(!is_directed(SimpleGraph))
15+
@test @inferred(!is_directed(SimpleGraph{Int}))
1516

1617
@test @inferred(eltype(SimpleDiGraph())) == Int
1718
@test @inferred(eltype(SimpleDiGraph(adjmx2))) == Int
1819
@test @inferred(ne(SimpleDiGraph(PathGraph(5)))) == 8
1920
@test @inferred(is_directed(SimpleDiGraph))
21+
@test @inferred(is_directed(SimpleDiGraph{Int}))
2022

2123

2224
for gbig in [SimpleGraph(0xff), SimpleDiGraph(0xff)]
@@ -446,4 +448,6 @@ import Random
446448
@test isvalid_simplegraph(gf)
447449
end
448450
end
451+
# codecov for has_edge(::AbstractSimpleGraph, x, y)
452+
@test @inferred has_edge(DummySimpleGraph(), 1, 2)
449453
end

0 commit comments

Comments
 (0)