1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-25 18:15:29 +01:00

fix tests

This commit is contained in:
kalmarek 2019-01-02 15:50:14 +01:00
parent 44f08716d2
commit 29be715c46
2 changed files with 104 additions and 89 deletions

View File

@ -1,73 +1,93 @@
@testset "DirectProducts" begin
@testset "DirectPowers" begin
×(a,b) = Groups.pow(a,b)
×(a,b) = Groups.DirectPower(a,b)
@testset "Constructors" begin
G = PermutationGroup(3)
g = G([2,3,1])
@test Groups.DirectProductGroup(G,2) isa AbstractAlgebra.Group
@test Groups.DirectPowerGroup(G,2) isa AbstractAlgebra.Group
@test G×G isa AbstractAlgebra.Group
@test Groups.DirectProductGroup(G,2) isa Groups.DirectProductGroup{Generic.PermGroup{Int64}}
@test Groups.DirectPowerGroup(G,2) isa Groups.DirectPowerGroup{2, Generic.PermGroup{Int64}}
@test (G×G)×G == DirectProductGroup(G, 3)
@test (G×G)×G == DirectPowerGroup(G, 3)
@test (G×G)×G == (G×G)×G
F = GF(13)
FF = F×F
@test FF×F == F×FF
GG = DirectPowerGroup(G,2)
@test (G×G)() isa GroupElem
@test (G×G)((G(), G())) isa GroupElem
@test (G×G)([G(), G()]) isa GroupElem
GG = DirectProductGroup(G,2)
@test Groups.DirectProductGroupElem([G(), G()]) == (G×G)()
@test Groups.DirectPowerGroupElem((G(), G())) == (G×G)()
@test GG(G(), G()) == (G×G)()
@test GG([g, g^2]) isa GroupElem
@test GG([g, g^2]) isa Groups.DirectProductGroupElem{Generic.perm{Int64}}
g = perm"(1,2,3)"
h = GG([g,g^2])
@test GG(g, g^2) isa GroupElem
@test GG(g, g^2) isa Groups.DirectPowerGroupElem{2, Generic.perm{Int64}}
h = GG(g,g^2)
@test h == GG(h)
@test GG(g, g^2) isa GroupElem
@test GG(g, g^2) isa Groups.DirectProductGroupElem
@test GG(g, g^2) isa Groups.DirectPowerGroupElem
@test_throws DomainError GG(g,g,g)
@test_throws MethodError GG(g,g,g)
@test GG(g,g^2) == h
@test h[1] == g
@test h[2] == g^2
h[2] = G()
h = GG(g, G())
@test h == GG(g, G())
end
@testset "Basic arithmetic" begin
G = PermutationGroup(3)
g = G([2,3,1])
h = (G×G)([g,g^2])
GG = G×G
i = perm"(1,3)"
g = perm"(1,2,3)"
@test h^2 == (G×G)(g^2,g)
@test h^6 == (G×G)()
h = GG(g,g^2)
k = GG(g^3, g^2)
@test h^2 == GG(g^2,g)
@test h^6 == GG()
@test h*h == h^2
@test h*k == GG(g,g)
@test h*inv(h) == (G×G)()
w = GG(g,i)*GG(i,g)
@test w == GG(perm"(1,2)(3)", perm"(2,3)")
@test w == inv(w)
@test w^2 == w*w == GG()
end
@testset "elem/parent_types" begin
G = PermutationGroup(3)
g = G([2,3,1])
g = perm"(1,2,3)"
@test elem_type(G×G) == DirectProductGroupElem{elem_type(G)}
@test parent_type(typeof((G×G)(g,g^2))) == Groups.DirectProductGroup{typeof(G)}
@test parent((G×G)(g,g^2)) == DirectProductGroup(G,2)
@test elem_type(G×G) == DirectPowerGroupElem{2, elem_type(G)}
@test elem_type(G×G×G) == DirectPowerGroupElem{3, elem_type(G)}
@test parent_type(typeof((G×G)(g,g^2))) == Groups.DirectPowerGroup{2, typeof(G)}
@test parent(DirectPowerGroupElem((g,g^2,g^3))) == DirectPowerGroup(G,3)
F = AdditiveGroup(GF(13))
@test elem_type(F×F) == DirectProductGroupElem{Groups.AddGrpElem{AbstractAlgebra.gfelem{Int}}}
@test parent_type(typeof((F×F)(1,5))) == Groups.DirectProductGroup{Groups.AddGrp{AbstractAlgebra.GFField{Int}}}
parent((F×F)(1,5)) == DirectProductGroup(F,2)
@test elem_type(F×F) ==
DirectPowerGroupElem{2, Groups.AddGrpElem{AbstractAlgebra.gfelem{Int}}}
@test parent_type(typeof((F×F)(1,5))) ==
Groups.DirectPowerGroup{2, Groups.AddGrp{AbstractAlgebra.GFField{Int}}}
parent((F×F)(1,5)) == DirectPowerGroup(F,2)
F = MultiplicativeGroup(GF(13))
@test elem_type(F×F) ==
DirectPowerGroupElem{2, Groups.MltGrpElem{AbstractAlgebra.gfelem{Int}}}
@test parent_type(typeof((F×F)(1,5))) ==
Groups.DirectPowerGroup{2, Groups.MltGrp{AbstractAlgebra.GFField{Int}}}
parent((F×F)(1,5)) == DirectPowerGroup(F,2)
end
@testset "Additive/Multiplicative groups" begin
@ -76,9 +96,6 @@
F, a = NumberField(x^3 + x + 1, "a")
G = PermutationGroup(3)
GG = Groups.DirectProductGroup(G,2)
FF = Groups.DirectProductGroup(F,2)
@testset "MltGrp basic functionality" begin
Gr = MltGrp(F)
@test Gr(a) isa MltGrpElem
@ -104,22 +121,22 @@
R, x = PolynomialRing(QQ, "x")
F, a = NumberField(x^3 + x + 1, "a")
FF = Groups.DirectProductGroup(MltGrp(F),2)
FF = Groups.DirectPowerGroup(MltGrp(F),2)
@test FF([a,1]) isa GroupElem
@test FF([a,1]) isa DirectProductGroupElem
@test FF([a,1]) isa DirectProductGroupElem{MltGrpElem{elem_type(F)}}
@test FF([a,1]) isa DirectPowerGroupElem
@test FF([a,1]) isa DirectPowerGroupElem{2, MltGrpElem{elem_type(F)}}
@test_throws DomainError FF(1,0)
@test_throws DomainError FF([0,1])
@test_throws DomainError FF([1,0])
@test MltGrp(F) isa AbstractAlgebra.Group
@test MltGrp(F) isa MultiplicativeGroup
@test DirectProductGroup(MltGrp(F), 2) isa AbstractAlgebra.Group
@test DirectProductGroup(MltGrp(F), 2) isa DirectProductGroup{MltGrp{typeof(F)}}
@test DirectPowerGroup(MltGrp(F), 2) isa AbstractAlgebra.Group
@test DirectPowerGroup(MltGrp(F), 2) isa DirectPowerGroup{2, MltGrp{typeof(F)}}
F, a = NumberField(x^3 + x + 1, "a")
FF = DirectProductGroup(MltGrp(F), 2)
FF = DirectPowerGroup(MltGrp(F), 2)
@test FF(a,a+1) == FF([a,a+1])
@test FF([1,a+1])*FF([a,a]) == FF(a,a^2+a)
@ -138,14 +155,14 @@
# Additive Group
@test AddGrp(F) isa AbstractAlgebra.Group
@test AddGrp(F) isa AdditiveGroup
@test DirectProductGroup(AddGrp(F), 2) isa AbstractAlgebra.Group
@test DirectProductGroup(AddGrp(F), 2) isa DirectProductGroup{AddGrp{typeof(F)}}
@test DirectPowerGroup(AddGrp(F), 2) isa AbstractAlgebra.Group
@test DirectPowerGroup(AddGrp(F), 2) isa DirectPowerGroup{2, AddGrp{typeof(F)}}
FF = DirectProductGroup(AdditiveGroup(F), 2)
FF = DirectPowerGroup(AdditiveGroup(F), 2)
@test FF([0,a]) isa AbstractAlgebra.GroupElem
@test FF(F(0),a) isa DirectProductGroupElem
@test FF(0,0) isa DirectProductGroupElem{AddGrpElem{elem_type(F)}}
@test FF(F(0),a) isa DirectPowerGroupElem
@test FF(0,0) isa DirectPowerGroupElem{2, AddGrpElem{elem_type(F)}}
@test FF(F(1),a+1) == FF([1,a+1])
@ -161,31 +178,31 @@
@testset "Misc" begin
F = GF(5)
FF = DirectProductGroup(AdditiveGroup(F),2)
FF = DirectPowerGroup(AdditiveGroup(F),2)
@test order(FF) == 25
elts = vec(collect(elements(FF)))
elts = vec(collect(FF))
@test length(elts) == 25
@test all([g*inv(g) == FF() for g in elts])
@test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts)
FF = DirectProductGroup(MultiplicativeGroup(F), 3)
FF = DirectPowerGroup(MultiplicativeGroup(F), 3)
@test order(FF) == 64
elts = vec(collect(elements(FF)))
elts = vec(collect(FF))
@test length(elts) == 64
@test all([g*inv(g) == FF() for g in elts])
@test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts)
G = PermutationGroup(3)
GG = Groups.DirectProductGroup(G,2)
@test order(GG) == 36
GG = Groups.DirectPowerGroup(G,3)
@test order(GG) == 216
@test isa([elements(GG)...], Vector{Groups.DirectProductGroupElem{elem_type(G)}})
elts = vec(collect(elements(GG)))
@test isa(collect(GG), Vector{Groups.DirectPowerGroupElem{3, elem_type(G)}})
elts = vec(collect(GG))
@test length(elts) == 36
@test length(elts) == 216
@test all([g*inv(g) == GG() for g in elts])
@test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts)
end

View File

@ -1,105 +1,103 @@
@testset "WreathProducts" begin
S_3 = PermutationGroup(3)
S_2 = PermutationGroup(2)
b = S_3([2,3,1])
a = S_2([2,1])
b = perm"(1,2,3)"
a = perm"(1,2)"
@testset "Constructors" begin
@test isa(Groups.WreathProduct(S_2, S_3), AbstractAlgebra.Group)
@test Groups.WreathProduct(S_2, S_3) isa AbstractAlgebra.Group
B3 = Groups.WreathProduct(S_2, S_3)
@test B3 isa Groups.WreathProduct
@test B3 isa WreathProduct{AbstractAlgebra.Generic.PermGroup{Int}, Int}
@test B3 isa WreathProduct{3, AbstractAlgebra.Generic.PermGroup{Int}, Int}
aa = Groups.DirectProductGroupElem([a^0 ,a, a^2])
aa = Groups.DirectPowerGroupElem((a^0 ,a, a^2))
@test isa(Groups.WreathProductElem(aa, b), AbstractAlgebra.GroupElem)
@test Groups.WreathProductElem(aa, b) isa AbstractAlgebra.GroupElem
x = Groups.WreathProductElem(aa, b)
@test x isa Groups.WreathProductElem
@test x isa Groups.WreathProductElem{AbstractAlgebra.Generic.perm{Int}, Int}
@test x isa
Groups.WreathProductElem{3, AbstractAlgebra.Generic.perm{Int}, Int}
@test B3.N == Groups.DirectProductGroup(S_2, 3)
@test B3.N == Groups.DirectPowerGroup(S_2, 3)
@test B3.P == S_3
@test B3(aa, b) == Groups.WreathProductElem(aa, b)
@test B3(b) == Groups.WreathProductElem(B3.N(), b)
@test B3(aa) == Groups.WreathProductElem(aa, S_3())
@test B3([a^0 ,a, a^2], perm"(1,2,3)") isa WreathProductElem
@test B3((a^0 ,a, a^2), b) isa WreathProductElem
@test B3([a^0 ,a, a^2], perm"(1,2,3)") == B3(aa, b)
@test B3((a^0 ,a, a^2), b) == B3(aa, b)
end
@testset "Types" begin
B3 = Groups.WreathProduct(S_2, S_3)
@test elem_type(B3) == Groups.WreathProductElem{perm{Int}, Int}
@test elem_type(B3) == Groups.WreathProductElem{3, perm{Int}, Int}
@test parent_type(typeof(B3())) == Groups.WreathProduct{parent_type(typeof(B3.N.group())), Int}
@test parent_type(typeof(B3())) == Groups.WreathProduct{3, parent_type(typeof(B3.N.group())), Int}
@test parent(B3()) == Groups.WreathProduct(S_2,S_3)
@test parent(B3()) == B3
end
@testset "Basic operations on WreathProductElem" begin
aa = Groups.DirectProductGroupElem([a^0 ,a, a^2])
aa = Groups.DirectPowerGroupElem((a^0 ,a, a^2))
B3 = Groups.WreathProduct(S_2, S_3)
g = B3(aa, b)
@test g.p == b
@test g.n == DirectProductGroupElem(aa.elts)
@test g.n == DirectPowerGroupElem(aa.elts)
h = deepcopy(g)
@test h == g
@test !(g === h)
g.n[1] = parent(g.n[1])(a)
g = B3(Groups.DirectPowerGroupElem((a ,a, a^2)), g.p)
@test g.n[1] == parent(g.n[1])(a)
@test g != h
@test hash(g) != hash(h)
g.n[1] = a
@test g.n[1] == parent(g.n[1])(a)
@test g != h
@test hash(g) != hash(h)
end
@testset "Group arithmetic" begin
B4 = Groups.WreathProduct(AdditiveGroup(GF(3)), PermutationGroup(4))
x = B4([0,1,2,0], perm"(1,2,3)(4)")
@test inv(x) == B4([1,0,2,0], perm"(1,3,2)(4)")
x = B4((0,1,2,0), perm"(1,2,3)(4)")
@test inv(x) == B4((1,0,2,0), perm"(1,3,2)(4)")
y = B4([1,0,1,2], perm"(1,4)(2,3)")
@test inv(y) == B4([1,2,0,2], perm"(1,4)(2,3)")
y = B4((1,0,1,2), perm"(1,4)(2,3)")
@test inv(y) == B4((1,2,0,2), perm"(1,4)(2,3)")
@test x*y == B4([0,2,0,2], perm"(1,3,4)(2)")
@test x*y == B4((0,2,0,2), perm"(1,3,4)(2)")
@test y*x == B4([1,2,2,2], perm"(1,4,2)(3)")
@test y*x == B4((1,2,2,2), perm"(1,4,2)(3)")
@test inv(x)*y == B4([2,1,2,2], perm"(1,2,4)(3)")
@test inv(x)*y == B4((2,1,2,2), perm"(1,2,4)(3)")
@test y*inv(x) == B4([1,2,1,0], perm"(1,4,3)(2)")
@test y*inv(x) == B4((1,2,1,0), perm"(1,4,3)(2)")
end
@testset "Misc" begin
B3 = Groups.WreathProduct(GF(3), S_3)
B3 = Groups.WreathProduct(AdditiveGroup(GF(3)), S_3)
@test order(B3) == 3^3*6
@test collect(B3) isa Vector{
WreathProductElem{3, AddGrpElem{AbstractAlgebra.gfelem{Int}}, Int}}
# B3 = Groups.WreathProduct(MultiplicativeGroup(GF(3)), S_3)
# @test order(B3) == 2^3*6
B3 = Groups.WreathProduct(MultiplicativeGroup(GF(3)), S_3)
@test order(B3) == 2^3*6
@test collect(B3) isa Vector{
WreathProductElem{3, MltGrpElem{AbstractAlgebra.gfelem{Int}}, Int}}
Wr = WreathProduct(PermutationGroup(2),PermutationGroup(4))
@test isa([elements(Wr)...], Vector{Groups.WreathProductElem{Generic.perm{Int}, Int}})
elts = collect(Wr)
@test elts isa Vector{Groups.WreathProductElem{4, Generic.perm{Int}, Int}}
@test order(Wr) == 2^4*factorial(4)
elts = [elements(Wr)...]
@test length(elts) == order(Wr)
@test all([g*inv(g) == Wr() for g in elts])
@test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts)