From c59dffe98dc2948a95f0e2153d0870ade383682f Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Fri, 26 Apr 2024 12:48:49 -0400 Subject: [PATCH] Fix `convert_vertextype` (#74) --- src/namedgraph.jl | 2 +- test/test_namedgraph.jl | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/namedgraph.jl b/src/namedgraph.jl index c4a0a1d..b58a273 100644 --- a/src/namedgraph.jl +++ b/src/namedgraph.jl @@ -73,7 +73,7 @@ end function GraphsExtensions.convert_vertextype(vertextype::Type, graph::GenericNamedGraph) return GenericNamedGraph( - position_graph(graph), convert(Vector{vertextype}, graph.ordered_vertices) + position_graph(graph), convert(Vector{vertextype}, ordered_vertices(graph)) ) end diff --git a/test/test_namedgraph.jl b/test/test_namedgraph.jl index 6f4610e..02fe7bd 100644 --- a/test/test_namedgraph.jl +++ b/test/test_namedgraph.jl @@ -66,6 +66,7 @@ using NamedGraphs.GraphsExtensions: ⊔, boundary_edges, boundary_vertices, + convert_vertextype, degrees, eccentricities, dijkstra_mst, @@ -82,7 +83,8 @@ using NamedGraphs.GraphsExtensions: rename_vertices, subgraph, symrcm_perm, - symrcm_permute + symrcm_permute, + vertextype using NamedGraphs.NamedGraphGenerators: named_binary_tree, named_grid, named_path_graph using SymRCM: SymRCM using Test: @test, @test_broken, @testset @@ -117,6 +119,15 @@ end @test degree(g, "A") == 1 @test degree(g, "B") == 2 + g = NamedGraph(grid((4,)), [2, 4, 6, 8]) + g_t = convert_vertextype(UInt16, g) + @test g == g_t + @test nv(g_t) == 4 + @test ne(g_t) == 3 + @test vertextype(g_t) === UInt16 + @test issetequal(vertices(g_t), UInt16[2, 4, 6, 8]) + @test eltype(vertices(g_t)) === UInt16 + g = NamedGraph(grid((4,)), ["A", "B", "C", "D"]) zg = zero(g) @test zg isa NamedGraph{String}