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