Skip to content

Commit 433031d

Browse files
author
Uwe Hernandez Acosta
committed
added available_accessors
1 parent 5bc992d commit 433031d

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/utility.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
available_accessors()
3+
4+
Returns a list of available accessor functions for four-momentum components.
5+
6+
This function gathers all defined accessor methods (such as px, py, pz, E, etc.) that are available
7+
for **any** custom four-momentum type implementing the LorentzVectorBase interface.
8+
9+
### Example
10+
11+
```julia
12+
julia> LorentzVectorBase.available_accessors()
13+
38-element Vector{Symbol}:
14+
:x
15+
:y
16+
:z
17+
:t
18+
:energy
19+
:px
20+
:py
21+
...
22+
```
23+
24+
This allows users to query which accessor functions are available for any custom four-momentum type.
25+
"""
26+
function available_accessors()
27+
res = Symbol[]
28+
for acc in FOURMOMENTUM_GETTER_FUNCTIONS
29+
push!(res, acc)
30+
for (key, val) in FOURMOMENTUM_GETTER_ALIASSES
31+
if val == acc
32+
push!(res, key)
33+
continue
34+
end
35+
end
36+
end
37+
return res
38+
end

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ begin
77
include("interface.jl")
88
end
99

10+
@time @safetestset "utility" begin
11+
include("utility.jl")
12+
end
13+
1014
@time @safetestset "XYZT" begin
1115
include("XYZT.jl")
1216
end

test/utility.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using LorentzVectorBase
2+
3+
av_accessors = available_accessors()
4+
5+
groundtruth = (
6+
LorentzVectorBase.FOURMOMENTUM_GETTER_FUNCTIONS...,
7+
keys(LorentzVectorBase.FOURMOMENTUM_GETTER_ALIASSES)...,
8+
)
9+
10+
@testset "available accessors" begin
11+
@test length(av_accessors) == length(groundtruth)
12+
13+
@testset "acc: $acc" for acc in groundtruth
14+
@test any(x -> acc == x, av_accessors)
15+
end
16+
end

0 commit comments

Comments
 (0)