1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-11-04 19:00:27 +01:00
Groups.jl/test/free_groups.jl

73 lines
1.7 KiB
Julia
Raw Normal View History

@testset "FreeGroup" begin
2021-05-24 14:46:54 +02:00
A3 = Alphabet([:a, :b, :c, :A, :B, :C], [4,5,6,1,2,3])
F3 = FreeGroup([:a, :b, :c], A3)
@test F3 isa FreeGroup
2021-05-24 14:46:54 +02:00
@test gens(F3) isa Vector
@test eltype(F3) <: FPGroupElement{<:FreeGroup}
2021-05-24 14:46:54 +02:00
w = F3([1,2,3,4])
W = inv(w)
@test deepcopy(w) !== w
@test deepcopy(w).word !== w.word
@test isone(w*W)
@test alphabet(w) == A3
2021-05-24 14:46:54 +02:00
@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)
2021-05-24 14:46:54 +02:00
@test k == a*b^-1
2021-05-25 22:27:22 +02:00
@time k = test_iteration(F3, 1000)
2022-04-02 15:53:55 +02:00
@time test_iteration(F3, 1000)
@test k == (a^2)*c^2*a^-1
2021-05-24 14:46:54 +02:00
end
@testset "wl_ball" begin
function wl_ball(F; radius::Integer)
g, state = iterate(F)
while length(word(g)) <= radius
2021-05-24 14:46:54 +02:00
res = iterate(F, state)
isnothing(res) && break
g, state = res
end
2021-05-25 22:27:22 +02:00
elts = collect(state.seen)
2021-05-24 14:46:54 +02:00
elts = resize!(elts, length(elts)-1)
return elts
end
E4 = wl_ball(F3, radius=4)
@test length(E4) == 937
@test word(last(E4)) == Word([6])^4
2021-05-24 14:46:54 +02:00
E8, t, _ = @timed wl_ball(F3, radius=8)
2021-05-24 14:46:54 +02:00
@test length(E8) == 585937
@test word(last(E8)) == Word([6])^8
@test t/10^9 < 1
2021-05-24 14:46:54 +02:00
end
@testset "GroupsCore conformance" begin
test_Group_interface(F3)
test_GroupElement_interface(rand(F3, 2)...)
end
2021-05-24 14:46:54 +02:00
end