1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-26 18:30:29 +01:00
Groups.jl/test/DirectPower-tests.jl

210 lines
6.1 KiB
Julia
Raw Normal View History

2019-01-02 15:50:14 +01:00
@testset "DirectPowers" begin
2017-07-23 03:27:03 +02:00
2019-01-02 15:50:14 +01:00
×(a,b) = Groups.DirectPower(a,b)
2018-09-21 19:11:37 +02:00
2017-07-23 03:27:03 +02:00
@testset "Constructors" begin
2018-07-30 15:20:37 +02:00
G = PermutationGroup(3)
2017-07-23 03:27:03 +02:00
2019-01-02 15:50:14 +01:00
@test Groups.DirectPowerGroup(G,2) isa AbstractAlgebra.Group
2018-07-30 15:20:37 +02:00
@test G×G isa AbstractAlgebra.Group
2019-01-02 15:50:14 +01:00
@test Groups.DirectPowerGroup(G,2) isa Groups.DirectPowerGroup{2, Generic.PermGroup{Int64}}
2017-07-23 03:27:03 +02:00
2019-01-02 15:50:14 +01:00
@test (G×G)×G == DirectPowerGroup(G, 3)
2018-07-30 15:20:37 +02:00
@test (G×G)×G == (G×G)×G
2017-07-23 03:27:03 +02:00
2019-01-02 15:50:14 +01:00
GG = DirectPowerGroup(G,2)
@test (G×G)() isa GroupElem
@test (G×G)((G(), G())) isa GroupElem
@test (G×G)([G(), G()]) isa GroupElem
2017-07-23 03:27:03 +02:00
2019-01-02 15:50:14 +01:00
@test Groups.DirectPowerGroupElem((G(), G())) == (G×G)()
2018-07-30 15:20:37 +02:00
@test GG(G(), G()) == (G×G)()
2019-01-02 15:50:14 +01:00
g = perm"(1,2,3)"
@test GG(g, g^2) isa GroupElem
@test GG(g, g^2) isa Groups.DirectPowerGroupElem{2, Generic.perm{Int64}}
2017-07-23 03:27:03 +02:00
2019-01-02 15:50:14 +01:00
h = GG(g,g^2)
2017-07-23 03:27:03 +02:00
@test h == GG(h)
2018-07-30 15:20:37 +02:00
@test GG(g, g^2) isa GroupElem
2019-01-02 15:50:14 +01:00
@test GG(g, g^2) isa Groups.DirectPowerGroupElem
2017-07-23 03:27:03 +02:00
2019-01-02 15:50:14 +01:00
@test_throws MethodError GG(g,g,g)
2017-07-23 03:27:03 +02:00
@test GG(g,g^2) == h
@test h[1] == g
@test h[2] == g^2
2019-01-02 15:50:14 +01:00
h = GG(g, G())
2017-07-23 03:27:03 +02:00
@test h == GG(g, G())
end
2018-07-30 15:20:37 +02:00
@testset "Basic arithmetic" begin
G = PermutationGroup(3)
2019-01-02 15:50:14 +01:00
GG = G×G
i = perm"(1,3)"
g = perm"(1,2,3)"
h = GG(g,g^2)
k = GG(g^3, g^2)
2018-07-30 15:20:37 +02:00
2019-01-02 15:50:14 +01:00
@test h^2 == GG(g^2,g)
@test h^6 == GG()
2017-07-23 03:27:03 +02:00
2018-07-30 15:20:37 +02:00
@test h*h == h^2
2019-01-02 15:50:14 +01:00
@test h*k == GG(g,g)
2017-07-23 03:27:03 +02:00
2018-07-30 15:20:37 +02:00
@test h*inv(h) == (G×G)()
2019-01-02 15:50:14 +01:00
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()
2017-07-23 03:27:03 +02:00
end
2018-07-30 15:20:37 +02:00
@testset "elem/parent_types" begin
G = PermutationGroup(3)
2019-01-02 15:50:14 +01:00
g = perm"(1,2,3)"
2017-07-23 03:27:03 +02:00
2019-01-02 15:50:14 +01:00
@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)
2017-07-23 03:27:03 +02:00
2018-09-21 19:11:37 +02:00
F = AdditiveGroup(GF(13))
2018-07-30 15:20:37 +02:00
2019-01-02 15:50:14 +01:00
@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)
2018-07-30 15:20:37 +02:00
end
@testset "Additive/Multiplicative groups" begin
R, x = PolynomialRing(QQ, "x")
F, a = NumberField(x^3 + x + 1, "a")
G = PermutationGroup(3)
@testset "MltGrp basic functionality" begin
Gr = MltGrp(F)
@test Gr(a) isa MltGrpElem
g = Gr(a)
@test deepcopy(g) isa MltGrpElem
@test inv(g) == Gr(a^-1)
@test Gr() == Gr(1)
@test inv(g)*g == Gr()
end
@testset "AddGrp basic functionality" begin
Gr = AddGrp(F)
@test Gr(a) isa AddGrpElem
g = Gr(a)
@test deepcopy(g) isa AddGrpElem
@test inv(g) == Gr(-a)
@test Gr() == Gr(0)
@test inv(g)*g == Gr()
end
end
2017-07-23 03:27:03 +02:00
2018-07-30 15:20:37 +02:00
@testset "Direct Product of Multiplicative Groups" begin
2017-07-23 03:27:03 +02:00
2018-07-30 15:20:37 +02:00
R, x = PolynomialRing(QQ, "x")
F, a = NumberField(x^3 + x + 1, "a")
2019-01-02 15:50:14 +01:00
FF = Groups.DirectPowerGroup(MltGrp(F),2)
2018-07-30 15:20:37 +02:00
@test FF([a,1]) isa GroupElem
2019-01-02 15:50:14 +01:00
@test FF([a,1]) isa DirectPowerGroupElem
@test FF([a,1]) isa DirectPowerGroupElem{2, MltGrpElem{elem_type(F)}}
2018-09-21 19:27:47 +02:00
@test_throws DomainError FF(1,0)
@test_throws DomainError FF([0,1])
@test_throws DomainError FF([1,0])
2018-07-30 15:20:37 +02:00
@test MltGrp(F) isa AbstractAlgebra.Group
@test MltGrp(F) isa MultiplicativeGroup
2019-01-02 15:50:14 +01:00
@test DirectPowerGroup(MltGrp(F), 2) isa AbstractAlgebra.Group
@test DirectPowerGroup(MltGrp(F), 2) isa DirectPowerGroup{2, MltGrp{typeof(F)}}
2018-07-30 15:20:37 +02:00
F, a = NumberField(x^3 + x + 1, "a")
2019-01-02 15:50:14 +01:00
FF = DirectPowerGroup(MltGrp(F), 2)
2018-07-30 15:20:37 +02:00
@test FF(a,a+1) == FF([a,a+1])
@test FF([1,a+1])*FF([a,a]) == FF(a,a^2+a)
2017-07-23 03:27:03 +02:00
x, y = FF([1,a]), FF([a^2,1])
2018-07-30 15:20:37 +02:00
@test x*y == FF([a^2, a])
@test inv(x) == FF([1,-a^2-1])
@test parent(x) == FF
end
@testset "Direct Product of Additive Groups" begin
R, x = PolynomialRing(QQ, "x")
F, a = NumberField(x^3 + x + 1, "a")
# Additive Group
@test AddGrp(F) isa AbstractAlgebra.Group
@test AddGrp(F) isa AdditiveGroup
2019-01-02 15:50:14 +01:00
@test DirectPowerGroup(AddGrp(F), 2) isa AbstractAlgebra.Group
@test DirectPowerGroup(AddGrp(F), 2) isa DirectPowerGroup{2, AddGrp{typeof(F)}}
2018-07-30 15:20:37 +02:00
2019-01-02 15:50:14 +01:00
FF = DirectPowerGroup(AdditiveGroup(F), 2)
2018-07-30 15:20:37 +02:00
@test FF([0,a]) isa AbstractAlgebra.GroupElem
2019-01-02 15:50:14 +01:00
@test FF(F(0),a) isa DirectPowerGroupElem
@test FF(0,0) isa DirectPowerGroupElem{2, AddGrpElem{elem_type(F)}}
2018-07-30 15:20:37 +02:00
@test FF(F(1),a+1) == FF([1,a+1])
@test FF([F(1),a+1])*FF([a,a]) == FF(1+a,2a+1)
x, y = FF([1,a]), FF([a^2,1])
@test x*y == FF(a^2+1, a+1)
@test inv(x) == FF([F(-1),-a])
@test parent(x) == FF
2017-07-23 03:27:03 +02:00
end
@testset "Misc" begin
2018-07-30 15:20:37 +02:00
F = GF(5)
2019-01-02 15:50:14 +01:00
FF = DirectPowerGroup(AdditiveGroup(F),2)
2018-07-30 15:20:37 +02:00
@test order(FF) == 25
2019-01-02 15:50:14 +01:00
elts = vec(collect(FF))
2018-07-30 15:20:37 +02:00
@test length(elts) == 25
2018-09-21 19:11:37 +02:00
@test all([g*inv(g) == FF() for g in elts])
2018-07-30 15:20:37 +02:00
@test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts)
2019-01-02 15:50:14 +01:00
FF = DirectPowerGroup(MultiplicativeGroup(F), 3)
2017-07-23 03:27:03 +02:00
@test order(FF) == 64
2019-01-02 15:50:14 +01:00
elts = vec(collect(FF))
2018-07-30 15:20:37 +02:00
@test length(elts) == 64
2018-09-21 19:11:37 +02:00
@test all([g*inv(g) == FF() for g in elts])
2018-07-30 15:20:37 +02:00
@test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts)
G = PermutationGroup(3)
2019-01-02 15:50:14 +01:00
GG = Groups.DirectPowerGroup(G,3)
@test order(GG) == 216
2018-07-30 15:20:37 +02:00
2019-01-02 15:50:14 +01:00
@test isa(collect(GG), Vector{Groups.DirectPowerGroupElem{3, elem_type(G)}})
elts = vec(collect(GG))
2017-07-23 03:27:03 +02:00
2019-01-02 15:50:14 +01:00
@test length(elts) == 216
2018-09-21 19:11:37 +02:00
@test all([g*inv(g) == GG() for g in elts])
2017-07-23 03:27:03 +02:00
@test all(inv(g*h) == inv(h)*inv(g) for g in elts for h in elts)
end
end