diff --git a/src/words.jl b/src/words.jl index 9ef7383..1a1c76e 100644 --- a/src/words.jl +++ b/src/words.jl @@ -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) diff --git a/test/FreeGroup-tests.jl b/test/FreeGroup-tests.jl index da39e75..09924df 100644 --- a/test/FreeGroup-tests.jl +++ b/test/FreeGroup-tests.jl @@ -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