add test for hash/normalform

This commit is contained in:
Marek Kaluba 2023-05-25 11:58:32 +02:00
parent 93a841359b
commit 126c8bbc22
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
2 changed files with 33 additions and 2 deletions

View File

@ -88,6 +88,9 @@ end
abstract type AbstractFPGroupElement{Gr} <: GroupElement end
Base.copy(g::AbstractFPGroupElement) = one(g) * g
word(f::AbstractFPGroupElement) = f.word
mutable struct FPGroupElement{Gr<:AbstractFPGroup,W<:AbstractWord} <:
AbstractFPGroupElement{Gr}
word::W
@ -111,7 +114,9 @@ function Base.show(io::IO, ::Type{<:FPGroupElement{Gr}}) where {Gr}
return print(io, FPGroupElement, "{$Gr, …}")
end
word(f::AbstractFPGroupElement) = f.word
function Base.copy(f::FPGroupElement)
return FPGroupElement(copy(word(f)), parent(f), f.savedhash)
end
#convenience
KnuthBendix.alphabet(g::AbstractFPGroupElement) = alphabet(parent(g))
@ -134,7 +139,13 @@ function Base.:(==)(g::AbstractFPGroupElement, h::AbstractFPGroupElement)
end
function Base.deepcopy_internal(g::FPGroupElement, stackdict::IdDict)
return FPGroupElement(copy(word(g)), parent(g), g.savedhash)
haskey(stackdict, objectid(g)) && return stackdict[objectid(g)]
cw = if haskey(stackdict, objectid(word(g)))
stackdict[objectid(word(g))]
else
copy(word(g))
end
return FPGroupElement(cw, parent(g), g.savedhash)
end
function Base.inv(g::GEl) where {GEl<:AbstractFPGroupElement}

View File

@ -64,4 +64,24 @@
test_GroupElement_interface(rand(H, 2)...)
end
end
@testset "hash/normalform #28" begin
function cyclic_group(n::Integer)
A = Alphabet([:a, :A], [2, 1])
F = FreeGroup(A)
a, = Groups.gens(F)
e = one(F)
Cₙ = FPGroup(F, [a^n => e])
return Cₙ
end
n = 15
G = cyclic_group(n)
ball, sizes = Groups.wlmetric_ball(gens(G); radius = n)
@test first(sizes) == 2
@test last(sizes) == n
@test Set(ball) == Set([first(gens(G))^i for i in 0:n-1])
end
end