From 9eb8080ebb1fdd4d41fdb6552a81c811843d1860 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Tue, 7 Oct 2025 21:45:59 +0200 Subject: [PATCH] add function `graph_property_type` --- docs/src/index.md | 3 ++- src/GraphProperties.jl | 12 ++++++++++++ test/runtests.jl | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/src/index.md b/docs/src/index.md index fc0e3cb..0a3e1b4 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -11,10 +11,11 @@ Documentation for [GraphProperties](https://github.com/JuliaGraphs/GraphProperti ```@docs GraphProperty +graph_property_type PropertyComparison ``` ```@autodocs Modules = [GraphProperties] -Filter = !(t -> t in (GraphProperty, PropertyComparison)) +Filter = !(t -> t in (GraphProperty, graph_property_type, PropertyComparison)) ``` diff --git a/src/GraphProperties.jl b/src/GraphProperties.jl index bbc1f78..99a081f 100644 --- a/src/GraphProperties.jl +++ b/src/GraphProperties.jl @@ -2,6 +2,7 @@ module GraphProperties export GraphProperty, + graph_property_type, PropertyComparison """ @@ -13,6 +14,17 @@ The only type parameter is the type of each value of the property. """ abstract type GraphProperty{T} end +""" + graph_property_type(::GraphProperty{T}) -> T + +Get the type of each value of the property. + +It is not allowed to add methods to this function. +""" +function graph_property_type(::GraphProperty{T}) where {T} + T +end + """ PropertyComparison(comparison, property, value) diff --git a/test/runtests.jl b/test/runtests.jl index a961354..5cf7abc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,6 +10,12 @@ using Test @test FractionalChromaticNumber() isa GraphProperty{Real} @test DegreeSequence() isa GraphProperty{AbstractVector{<:Integer}} end + @testset "`graph_property_type`" begin + @test Bool === @inferred graph_property_type(GraphIsCograph()) + @test Integer === @inferred graph_property_type(Degeneracy()) + @test Real === @inferred graph_property_type(Strength()) + @test AbstractVector{<:Integer} == @inferred graph_property_type(DegreeSequence()) + end end using Aqua: Aqua