Skip to content

Commit 117dd3a

Browse files
authored
add function graph_property_type (#10)
1 parent 318408a commit 117dd3a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

docs/src/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Documentation for [GraphProperties](https://github.com/JuliaGraphs/GraphProperti
1111

1212
```@docs
1313
GraphProperty
14+
graph_property_type
1415
PropertyComparison
1516
```
1617

1718
```@autodocs
1819
Modules = [GraphProperties]
19-
Filter = !(t -> t in (GraphProperty, PropertyComparison))
20+
Filter = !(t -> t in (GraphProperty, graph_property_type, PropertyComparison))
2021
```

src/GraphProperties.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module GraphProperties
22

33
export
44
GraphProperty,
5+
graph_property_type,
56
PropertyComparison
67

78
"""
@@ -13,6 +14,17 @@ The only type parameter is the type of each value of the property.
1314
"""
1415
abstract type GraphProperty{T} end
1516

17+
"""
18+
graph_property_type(::GraphProperty{T}) -> T
19+
20+
Get the type of each value of the property.
21+
22+
It is not allowed to add methods to this function.
23+
"""
24+
function graph_property_type(::GraphProperty{T}) where {T}
25+
T
26+
end
27+
1628
"""
1729
PropertyComparison(comparison, property, value)
1830

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ using Test
1010
@test FractionalChromaticNumber() isa GraphProperty{Real}
1111
@test DegreeSequence() isa GraphProperty{AbstractVector{<:Integer}}
1212
end
13+
@testset "`graph_property_type`" begin
14+
@test Bool === @inferred graph_property_type(GraphIsCograph())
15+
@test Integer === @inferred graph_property_type(Degeneracy())
16+
@test Real === @inferred graph_property_type(Strength())
17+
@test AbstractVector{<:Integer} == @inferred graph_property_type(DegreeSequence())
18+
end
1319
end
1420

1521
using Aqua: Aqua

0 commit comments

Comments
 (0)