add tests for iteration for GWords

This commit is contained in:
kalmarek 2020-04-20 00:36:35 +02:00
parent ea7813b5dc
commit dfce36c099
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
2 changed files with 17 additions and 2 deletions

View File

@ -36,6 +36,8 @@ Base.@propagate_inbounds function Base.getindex(w::GWord, i::Integer)
return first(syllables(w)[idx])
end
Base.@propagate_inbounds Base.getindex(w::GWord, itr) = [w[i] for i in itr]
# no setindex! for syllable based words
Base.convert(::Type{GW}, s::GSymbol) where GW <: GWord = GW(s)

View File

@ -42,6 +42,7 @@ end
@testset "FreeGroup" begin
@test isa(FreeGroup(["s", "t"]), AbstractAlgebra.Group)
G = FreeGroup(["s", "t"])
s, t = gens(G)
@testset "elements constructors" begin
@test isa(one(G), FreeGroupElem)
@ -49,9 +50,21 @@ end
@test length(G.gens) == 2
@test eltype(gens(G)) == FreeGroupElem
@test length(gens(G)) == 2
end
s, t = gens(G)
@test collect(s*t) == Groups.syllables(s*t)
tt, ss = Groups.FreeSymbol(:t), Groups.FreeSymbol(:s)
@test collect(t^2) == [tt, tt]
ttinv = Groups.FreeSymbol(:t, -1)
w = t^-2*s^3*t^2
@test collect(w) == [inv(tt), inv(tt), ss, ss, ss, tt, tt]
@test w[1] == inv(tt)
@test w[2] == inv(tt)
@test w[3] == ss
@test w[3:5] == [ss, ss, ss]
@test w[end] == tt
@test collect(ttinv) == [ttinv]
end
@testset "internal arithmetic" begin