From a6aabf45417fadd46523caf891dde644297ae8a2 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Mon, 20 Apr 2020 02:02:57 +0200 Subject: [PATCH] even more tests --- src/DirectPower.jl | 4 ++-- src/symbols.jl | 5 +++-- test/FreeGroup-tests.jl | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/DirectPower.jl b/src/DirectPower.jl index ec0140f..fe87840 100644 --- a/src/DirectPower.jl +++ b/src/DirectPower.jl @@ -65,7 +65,7 @@ parent(g::DirectPowerGroupElem{N, T}) where {N,T} = # ############################################################################### -size(g::DirectPowerGroupElem{N}) where N = (N,) +Base.size(g::DirectPowerGroupElem{N}) where N = (N,) Base.IndexStyle(::Type{DirectPowerGroupElem}) = Base.LinearFast() Base.getindex(g::DirectPowerGroupElem, i::Int) = g.elts[i] @@ -188,7 +188,7 @@ end ############################################################################### order(G::DirectPowerGroup{N}) where N = order(G.group)^N -length(G::DirectPowerGroup) = order(G) +Base.length(G::DirectPowerGroup) = order(G) function iterate(G::DirectPowerGroup{N}) where N elts = collect(G.group) diff --git a/src/symbols.jl b/src/symbols.jl index dd766ff..e13435c 100644 --- a/src/symbols.jl +++ b/src/symbols.jl @@ -3,8 +3,9 @@ change_pow(s::S, n::Integer) where S<:GSymbol = S(s.id, n) function Base.iterate(s::GS, i=1) where GS<:GSymbol return i <= abs(s.pow) ? (GS(s.id, sign(s.pow)), i+1) : nothing end -Base.length(s::GSymbol) = abs(s.pow) -Base.size(s::GSymbol) = (length(s), ) +Base.size(s::GSymbol) = (abs(s.pow), ) +Base.length(s::GSymbol) = first(size(s)) + Base.eltype(s::GS) where GS<:GSymbol = GS Base.isone(s::GSymbol) = iszero(s.pow) diff --git a/test/FreeGroup-tests.jl b/test/FreeGroup-tests.jl index fae5c6d..3a1863f 100644 --- a/test/FreeGroup-tests.jl +++ b/test/FreeGroup-tests.jl @@ -38,6 +38,7 @@ end @test length(FreeGroupElem(t)) == 2 @test Groups.FreeSymbol(:s, 1) != Groups.FreeSymbol(:s, 2) @test Groups.FreeSymbol(:s, 1) != Groups.FreeSymbol(:t, 1) + @test collect(Groups.FreeSymbol(:s, 2)) == [i for i in Groups.FreeSymbol(:s, 2)] == [s, s] end @testset "FreeGroup" begin @@ -52,8 +53,10 @@ end @test eltype(gens(G)) == FreeGroupElem @test length(gens(G)) == 2 - @test collect(s*t) == Groups.syllables(s*t) tt, ss = Groups.FreeSymbol(:t), Groups.FreeSymbol(:s) + @test Groups.GroupWord([tt, inv(tt)]) isa FreeGroupElem + + @test collect(s*t) == Groups.syllables(s*t) @test collect(t^2) == [tt, tt] ttinv = Groups.FreeSymbol(:t, -1) w = t^-2*s^3*t^2 @@ -66,7 +69,8 @@ end @test collect(ttinv) == [ttinv] - @test Groups.GroupWord([tt, inv(tt)]) isa FreeGroupElem + @test isone(t^0) + @test !isone(t^1) end @testset "internal arithmetic" begin @@ -80,6 +84,13 @@ end tt = deepcopy(t) @test string(Groups.lmul!(tt, tt, inv(tt))) == "(id)" + w = deepcopy(t) + @test length(Groups.rmul!(w, t)) == 2 + @test length(Groups.lmul!(w, inv(t))) == 1 + w = AbstractAlgebra.mul!(w, w, s) + @test length(w) == 2 + @test length(Groups.lmul!(w, inv(s))) == 3 + tt = deepcopy(t) push!(tt, inv(t_symb)) @test string(tt) == "t*t^-1" @@ -150,7 +161,7 @@ end @test findlast(s^-1*t^-1, c) == 3 @test findprev(s, s*t*s*t, 4) == 3 @test findprev(s*t, s*t*s*t, 2) == 1 - @test findlast(t^2*s, c) === nothing + @test findprev(Groups.FreeSymbol(:t, 2), c, 4) === nothing w = s*t*s^-1 subst = Dict{FreeGroupElem, FreeGroupElem}(w => s^1, s*t^-1 => t^4)