Skip to content

Commit

Permalink
get_node_path -> get_path
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenJ committed Apr 15, 2024
1 parent 07c52f0 commit d9e0334
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/HerbCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export
get_rulesequence,
rulesonleft,
get_node_at_location,
get_node_path,
get_path,
number_of_holes,
contains_hole,
contains_nonuniform_hole,
Expand Down
6 changes: 3 additions & 3 deletions src/rulenode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,17 +387,17 @@ function get_node_at_location(root::Hole, location::Vector{Int})
end

"""
get_node_path(root::AbstractRuleNode, node::AbstractRuleNode)
get_path(root::AbstractRuleNode, node::AbstractRuleNode)
Returns the path from the `root` to the `targetnode`. Returns nothing if no path exists.
"""
function get_node_path(
function get_path(
root::AbstractRuleNode, targetnode::AbstractRuleNode)::Union{Vector{Int}, Nothing}
if root === targetnode
return Vector{Int}()
end
for (i, child) in enumerate(get_children(root))
path = get_node_path(child, targetnode)
path = get_path(child, targetnode)
if !isnothing(path)
return prepend!(path, i)
end
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ using Test
@test get_node_at_location(rulenode, [2]).ind == 4
end

@testset "get_node_path" begin
@testset "get_path" begin
n1 = RuleNode(1)
n2 = RuleNode(2)
n3 = UniformHole(BitVector((1, 1, 1)), [RuleNode(1), n2])
Expand All @@ -116,10 +116,10 @@ using Test
]),
n3
])
@test get_node_path(root, n1) == [1, 1]
@test get_node_path(root, n2) == [2, 2]
@test get_node_path(root, n3) == [2]
@test isnothing(get_node_path(root, n4))
@test get_path(root, n1) == [1, 1]
@test get_path(root, n2) == [2, 2]
@test get_path(root, n3) == [2]
@test isnothing(get_path(root, n4))
end

@testset "Length tests with holes" begin
Expand Down

0 comments on commit d9e0334

Please sign in to comment.