|
41 | 41 | @test_throws Graphs.NegativeCycleError bellman_ford_shortest_paths(g, 1, d)
|
42 | 42 | @test has_negative_edge_cycle(g, d)
|
43 | 43 | end
|
| 44 | + |
| 45 | + # setting zeros with zero(T) |
| 46 | + struct CustomReal <: Real |
| 47 | + val::Float64 |
| 48 | + bias::Int # need this, to avoid auto conversion of CustomReal(0) |
| 49 | + end |
| 50 | + Base.zero(::T) where {T<:CustomReal} = zero(T) |
| 51 | + Base.zero(::Type{CustomReal}) = CustomReal(0.0, 4) |
| 52 | + Base.typemax(::T) where {T<:CustomReal} = typemax(T) |
| 53 | + Base.typemax(::Type{CustomReal}) = CustomReal(typemax(Float64), 0) |
| 54 | + Base.:+(a::CustomReal, b::CustomReal) = CustomReal(a.val + b.val, 0) |
| 55 | + Base.:<(a::CustomReal, b::CustomReal) = a.val < b.val |
| 56 | + |
| 57 | + d3 = [CustomReal(i, 3) for i in d1] |
| 58 | + d4 = sparse(d3) |
| 59 | + for g in testdigraphs(g4) |
| 60 | + y = @inferred(bellman_ford_shortest_paths(g, 2, d3)) |
| 61 | + z = @inferred(bellman_ford_shortest_paths(g, 2, d4)) |
| 62 | + @test getfield.(y.dists, :val) == getfield.(z.dists, :val) == [Inf, 0, 6, 17, 33] |
| 63 | + @test @inferred(enumerate_paths(z))[2] == [] |
| 64 | + @test @inferred(enumerate_paths(z))[4] == enumerate_paths(z, 4) == [2, 3, 4] |
| 65 | + @test @inferred(!has_negative_edge_cycle(g)) |
| 66 | + @test @inferred(!has_negative_edge_cycle(g, d3)) |
| 67 | + |
| 68 | + y = @inferred(bellman_ford_shortest_paths(g, 2, d3)) |
| 69 | + z = @inferred(bellman_ford_shortest_paths(g, 2, d4)) |
| 70 | + @test getfield.(y.dists, :val) == getfield.(z.dists, :val) == [Inf, 0, 6, 17, 33] |
| 71 | + @test @inferred(enumerate_paths(z))[2] == [] |
| 72 | + @test @inferred(enumerate_paths(z))[4] == enumerate_paths(z, 4) == [2, 3, 4] |
| 73 | + @test @inferred(!has_negative_edge_cycle(g)) |
| 74 | + z = @inferred(bellman_ford_shortest_paths(g, 2)) |
| 75 | + @test z.dists == [typemax(Int), 0, 1, 2, 3] |
| 76 | + end |
44 | 77 | end
|
0 commit comments