Skip to content

Commit 8fc9557

Browse files
authored
added constructor for SimpleWeightedEdge (#36)
Came across #12 (again) and decided to fix it. I added the appropriate constructor for the `SimpleWeightedEdge` type, added tests to check that it works and "unbroke" the test in A*.
1 parent 25b9d91 commit 8fc9557

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/simpleweightededge.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SimpleWeightedEdge(p::Pair) = SimpleWeightedEdge(p.first, p.second, one(Float64)
1515
SimpleWeightedEdge{T, U}(p::Pair) where T<:Integer where U <: Real = SimpleWeightedEdge(T(p.first), T(p.second), one(U))
1616
SimpleWeightedEdge{T, U}(t::NTuple{3}) where T<:Integer where U <: Real = SimpleWeightedEdge(T(t[1]), T(t[2]), U(t[3]))
1717
SimpleWeightedEdge{T, U}(t::NTuple{2}) where T<:Integer where U <: Real = SimpleWeightedEdge(T(t[1]), T(t[2]), one(U))
18+
SimpleWeightedEdge{T, U}(x,y) where T<: Integer where U<:Real = SimpleWeightedEdge(x,y,one(U))
1819
SimpleWeightedEdge(x, y) = SimpleWeightedEdge(x, y, one(Float64))
1920
eltype(e::T) where T<:AbstractSimpleWeightedEdge= eltype(src(e))
2021

test/a_star.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
add_edge!(g, 1, 2, 0.5)
44
add_edge!(g, 2, 3, 0.8)
55
add_edge!(g, 1, 3, 2.0)
6-
@test_broken length(a_star(g, 1, 3)) == 2
6+
@test length(a_star(g, 1, 3)) == 2
77
distmx = weights(g)
88
heuristic(v) = 0
99
edgetype_to_return = Graphs.SimpleEdge

test/simpleweightedgraph.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ using SimpleWeightedGraphs
103103
@test @inferred(copy(g)) == g
104104
@test @inferred(!is_directed(g))
105105

106+
# test that edgetype(g) is a valid constructor when called with just the source and destination vertex
107+
@test edgetype(g)(1,2) == SimpleWeightedGraphEdge{T, U}(1,2,1.0)
108+
106109
e = first(edges(g))
107110
@test @inferred(has_edge(g, e))
108111
end
@@ -172,6 +175,9 @@ using SimpleWeightedGraphs
172175
@test @inferred(copy(g)) == g
173176
@test @inferred(is_directed(g))
174177

178+
# test that edgetype(g) is a valid constructor when called with just the source and destination vertex
179+
@test edgetype(g)(1,2) == SimpleWeightedDiGraphEdge{T, U}(1,2,1.0)
180+
175181
e = first(@inferred(edges(g)))
176182
@test @inferred(has_edge(g, e))
177183
end

0 commit comments

Comments
 (0)