add basic tests for FPGroups

This commit is contained in:
Marek Kaluba 2021-05-24 14:46:54 +02:00
parent 60f3b686ba
commit 9d1678d099
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
3 changed files with 117 additions and 0 deletions

44
test/fp_groups.jl Normal file
View File

@ -0,0 +1,44 @@
@testset "FPGroups" begin
A = Alphabet([:a, :A, :b, :B, :c, :C], [2,1,4,3,6,5])
F = New.FreeGroup([:a, :b, :c], A)
a,b,c = gens(F)
@test c*b*a isa New.FPGroupElement
# quotient of F:
G = New.FPGroup(F, [a*b=>b*a, a*c=>c*a, b*c=>c*b])
@test G isa New.FPGroup
@test rand(G) isa New.FPGroupElement
f = a*c*b
@test New.word(f) isa Word{UInt8}
aG,bG,cG = gens(G)
@test aG isa New.FPGroupElement
@test_throws AssertionError aG == a
@test New.word(aG) == New.word(a)
g = aG*cG*bG
@test_throws AssertionError f == g
@test New.word(f) == New.word(g)
@test New.word(g) == [1, 5, 3]
New.normalform!(g)
@test New.word(g) == [1, 3, 5]
# quotient of G
H = New.FPGroup(G, [aG^2=>cG, bG*cG=>aG], maxrules=200)
h = H(New.word(g))
@test h isa New.FPGroupElement
@test_throws AssertionError h == g
@test_throws AssertionError h*g
New.normalform!(h)
@test h == H([5])
end

65
test/free_groups.jl Normal file
View File

@ -0,0 +1,65 @@
@testset "New.FreeGroup" begin
A3 = Alphabet([:a, :b, :c, :A, :B, :C], [4,5,6,1,2,3])
F3 = New.FreeGroup([:a, :b, :c], A3)
@test F3 isa New.FreeGroup
@test gens(F3) isa Vector
@test eltype(F3) <: New.FPGroupElement{<:New.FreeGroup}
w = F3([1,2,3,4])
W = inv(w)
@test deepcopy(w) !== w
@test deepcopy(w).word !== w.word
@test isone(w*W)
@test New.alphabet(w) == A3
@testset "generic iteration" begin
w, s = iterate(F3)
@test isone(w)
w, s = iterate(F3, s)
@test w == gens(F3, 1)
a,b,c = gens(F3)
function test_iteration(F, n=1000)
w, s = iterate(F)
for i in 1:n
w, s = iterate(F, s)
end
return w
end
k = test_iteration(F3, 10)
@test k == a*b^-1
@time k = test_iteration(F3, 1000)
@test k == (a^2)*c^2*a^-1
end
@testset "wl_ball" begin
function wl_ball(F; radius::Integer)
g, state = iterate(F)
while length(New.word(g)) <= radius
res = iterate(F, state)
isnothing(res) && break
g, state = res
end
elts = collect(first(state).elts)
elts = resize!(elts, length(elts)-1)
return elts
end
E4 = wl_ball(F3, radius=4)
@test length(E4) == 937
@test New.word(last(E4)) == Word([6])^4
@time E8 = wl_ball(F3, radius=8)
@test length(E8) == 585937
@test New.word(last(E8)) == Word([6])^8
end
end

View File

@ -23,4 +23,12 @@ using LinearAlgebra
include("FreeGroup-tests.jl")
include("AutGroup-tests.jl")
include("FPGroup-tests.jl")
@testset "New FPGroups" begin
using Groups.New
using KnuthBendix
include("free_groups.jl")
include("fp_groups.jl")
end
end