1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-11-19 06:30:29 +01:00

even more tests

This commit is contained in:
kalmarek 2020-04-20 02:02:57 +02:00
parent 38f121d8ee
commit a6aabf4541
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
3 changed files with 19 additions and 7 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)