Skip to content

Commit

Permalink
Move tests to graphsextensions tests. Refactor function
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed May 15, 2024
1 parent 92dc185 commit 29a491e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
8 changes: 3 additions & 5 deletions src/lib/GraphsExtensions/src/neighbors.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Graphs: AbstractGraph, neighborhood_dists

function vertices_at_distance(g::AbstractGraph, vertex, n::Int)
neighborhood = [first(v) for v in neighborhood_dists(g, vertex, n)]
closer_neighborhood = [first(v) for v in neighborhood_dists(g, vertex, n - 1)]
iszero(n) && return neighborhood
return setdiff(neighborhood, closer_neighborhood)
function vertices_at_distance(g::AbstractGraph, vertex, distance::Int)
n_dists = neighborhood_dists(g, vertex, distance)
return map(first, filter(==(distance) last, n_dists))
end

next_nearest_neighbors(g::AbstractGraph, v) = vertices_at_distance(g, v, 2)
11 changes: 10 additions & 1 deletion src/lib/GraphsExtensions/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ using NamedGraphs.GraphsExtensions:
is_self_loop,
leaf_vertices,
minimum_distance_to_leaves,
next_nearest_neighbors,
non_leaf_edges,
outdegrees,
permute_vertices,
Expand All @@ -81,7 +82,8 @@ using NamedGraphs.GraphsExtensions:
tree_graph_node,
undirected_graph,
undirected_graph_type,
vertextype
vertextype,
vertices_at_distance
using Test: @test, @test_broken, @test_throws, @testset

# TODO: Still need to test:
Expand Down Expand Up @@ -579,5 +581,12 @@ using Test: @test, @test_broken, @test_throws, @testset
g′ = path_graph(4)
rem_edges!(g′, [2 => 3, 3 => 4])
@test g′ == g

#vertices at distance
L = 10
g = path_graph(L)
@test only(vertices_at_distance(g, 1, L - 1)) == L
@test only(next_nearest_neighbors(g, 1)) == 3
@test length(vertices_at_distance(g, 5, 3)) == 2
end
end
24 changes: 0 additions & 24 deletions test/test_graphsextensions.jl

This file was deleted.

0 comments on commit 29a491e

Please sign in to comment.