mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-10-15 15:25:36 +02:00
massive overhaul of tests
This commit is contained in:
parent
0891f28c6f
commit
2e6cd65d39
166
test/runtests.jl
166
test/runtests.jl
@ -2,106 +2,136 @@ using Groups
|
|||||||
using Base.Test
|
using Base.Test
|
||||||
|
|
||||||
# write your own tests here
|
# write your own tests here
|
||||||
s = FGSymbol("s")
|
|
||||||
t = FGSymbol("t")
|
|
||||||
|
|
||||||
@testset "FGSymbols" begin
|
@testset "Groups" begin
|
||||||
|
|
||||||
|
@testset "FPSymbols" begin
|
||||||
|
s = FPSymbol("s")
|
||||||
|
t = FPSymbol("t")
|
||||||
@testset "defines" begin
|
@testset "defines" begin
|
||||||
@test isa(FGSymbol(string(Char(rand(50:2000)))), Groups.GSymbol)
|
@test isa(FPSymbol(string(Char(rand(50:2000)))), GSymbol)
|
||||||
@test FGSymbol("abc").pow == 1
|
@test FPSymbol("abc").pow == 1
|
||||||
@test isa(s, FGSymbol)
|
@test isa(s, FPSymbol)
|
||||||
@test isa(t, FGSymbol)
|
@test isa(t, FPSymbol)
|
||||||
end
|
end
|
||||||
@testset "eltary functions" begin
|
@testset "eltary functions" begin
|
||||||
@test length(s) == 1
|
@test length(s) == 1
|
||||||
@test one(s) == s^0
|
@test Groups.change_pow(s, 0) == Groups.change_pow(t, 0)
|
||||||
@test one(s) == one(FGSymbol)
|
@test length(Groups.change_pow(s, 0)) == 0
|
||||||
@test Groups.change_pow(s,0) == one(s)
|
|
||||||
@test length(one(s)) == 0
|
|
||||||
@test inv(s).pow == -1
|
@test inv(s).pow == -1
|
||||||
@test FGSymbol("s", 3) == Groups.change_pow(s,3)
|
@test FPSymbol("s", 3) == Groups.change_pow(s, 3)
|
||||||
@test s^2 ≠ t^2
|
@test FPSymbol("s", 3) != FPSymbol("t", 3)
|
||||||
|
@test Groups.change_pow(inv(s), -3) == inv(Groups.change_pow(s, 3))
|
||||||
end
|
end
|
||||||
@testset "powers" begin
|
@testset "powers" begin
|
||||||
s⁴ = Groups.change_pow(s,4)
|
s⁴ = Groups.change_pow(s,4)
|
||||||
@test s⁴.pow == 4
|
@test s⁴.pow == 4
|
||||||
@test (s^4).symbols[1] == Groups.change_pow(s,4)
|
@test Groups.change_pow(s, 4) == FPSymbol("s", 4)
|
||||||
@test s*s == s^2
|
|
||||||
@test inv(s*s) == inv(s^2)
|
|
||||||
@test inv(s)^2 == inv(s^2)
|
|
||||||
@test inv(s)*inv(s) == inv(s^2)
|
|
||||||
@test inv(s*s) == inv(s)*inv(s)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "FGWords" begin
|
@testset "FPGroupElems" begin
|
||||||
|
s = FPSymbol("s")
|
||||||
|
t = FPSymbol("t", -2)
|
||||||
@testset "defines" begin
|
@testset "defines" begin
|
||||||
@test isa(Groups.GWord(s), Groups.GWord)
|
@test isa(Groups.GWord(s), Groups.GWord)
|
||||||
@test isa(Groups.GWord(s), FGWord)
|
@test isa(Groups.GWord(s), FPGroupElem)
|
||||||
@test isa(FGWord(s), Groups.GWord)
|
@test isa(FPGroupElem(s), Groups.GWord)
|
||||||
@test isa(convert(FGWord, s), GWord)
|
@test isa(convert(FPGroupElem, s), GWord)
|
||||||
@test isa(convert(FGWord, s), FGWord)
|
@test isa(convert(FPGroupElem, s), FPGroupElem)
|
||||||
@test isa(Vector{FGWord}([s,t]), Vector{FGWord})
|
@test isa(Vector{FPGroupElem}([s,t]), Vector{FPGroupElem})
|
||||||
@test Vector{GWord{FGSymbol}}([s,t]) == Vector{FGWord}([s,t])
|
@test length(FPGroupElem(s)) == 1
|
||||||
@test isa(s*s, FGWord)
|
@test length(FPGroupElem(t)) == 2
|
||||||
@test s*s == s^2
|
|
||||||
@test t*s ≠ s*t
|
|
||||||
@test Vector{GWord}([s,t]) == [s^2*s^-1, t]
|
|
||||||
@test hash([t^1,s^1]) == hash([t^2*inv(t),s*inv(s)*s])
|
|
||||||
end
|
end
|
||||||
@testset "eltary functions" begin
|
|
||||||
@test length(FGWord(s)) == 1
|
|
||||||
@test length(s*s) == 2
|
|
||||||
@test length(s*s^-1) == 0
|
|
||||||
@test length(s*t^-1) == 2
|
|
||||||
@test isa(one(FGWord), FGWord)
|
|
||||||
@test one(FGWord).symbols == Vector{FGSymbol}([one(FGSymbol)])
|
|
||||||
@test isa(one(Groups.GWord{FGSymbol}), Groups.GWord{FGSymbol})
|
|
||||||
w = s*t*s^-1
|
|
||||||
@test isa(one(w), FGWord)
|
|
||||||
@test inv(s*t) == t^-1*s^-1
|
|
||||||
@test inv(w) == s*t^-1*s^-1
|
|
||||||
|
|
||||||
|
@testset "eltary functions" begin
|
||||||
|
@test_skip (s*s).symbols == (s^2).symbols
|
||||||
|
@test_skip Vector{GWord{FPSymbol}}([s,t]) == Vector{FPGroupElem}([s,t])
|
||||||
|
@test_skip Vector{GWord}([s,t]) == [GWord(s), GWord(t)]
|
||||||
|
@test_skip hash([t^1,s^1]) == hash([t^2*inv(t),s*inv(s)*s])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@testset "FPGroup" begin
|
||||||
|
@test isa(FPGroup(["s", "t"]), Nemo.Group)
|
||||||
|
G = FPGroup(["s", "t"])
|
||||||
|
|
||||||
|
@testset "elements constructors" begin
|
||||||
|
@test isa(G(), FPGroupElem)
|
||||||
|
@test eltype(G.gens) == FPSymbol
|
||||||
|
@test length(G.gens) == 2
|
||||||
|
@test eltype(G.rels) == FPGroupElem
|
||||||
|
@test length(G.rels) == 0
|
||||||
|
@test eltype(generators(G)) == FPGroupElem
|
||||||
|
@test length(generators(G)) == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
s, t = generators(G)
|
||||||
|
|
||||||
|
@testset "internal arithmetic" begin
|
||||||
|
t_symb = FPSymbol("t")
|
||||||
|
tt = deepcopy(t)
|
||||||
|
@test string(Groups.r_multiply!(tt,[inv(t_symb)]; reduced=true)) ==
|
||||||
|
"(id)"
|
||||||
|
tt = deepcopy(t)
|
||||||
|
@test string(Groups.r_multiply!(tt,[inv(t_symb)]; reduced=false)) ==
|
||||||
|
"t*t^-1"
|
||||||
|
tt = deepcopy(t)
|
||||||
|
@test string(Groups.l_multiply!(tt,[inv(t_symb)]; reduced=true)) ==
|
||||||
|
"(id)"
|
||||||
|
tt = deepcopy(t)
|
||||||
|
@test string(Groups.l_multiply!(tt,[inv(t_symb)]; reduced=false)) ==
|
||||||
|
"t^-1*t"
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "reductions" begin
|
@testset "reductions" begin
|
||||||
@test one(FGWord) == one(s)*one(s)
|
@test length(G().symbols) == 1
|
||||||
w = GWord{FGSymbol}([s])
|
@test length((G()*G()).symbols) == 0
|
||||||
|
@test G() == G()*G()
|
||||||
|
w = deepcopy(s)
|
||||||
push!(w.symbols, (s^-1).symbols[1])
|
push!(w.symbols, (s^-1).symbols[1])
|
||||||
@test Groups.reduce!(w) == one(FGWord)
|
@test Groups.reduce!(w) == parent(w)()
|
||||||
o = (t*s)^3
|
o = (t*s)^3
|
||||||
@test o == t*s*t*s*t*s
|
@test o == t*s*t*s*t*s
|
||||||
p = (t*s)^-3
|
p = (t*s)^-3
|
||||||
@test p == s^-1*t^-1*s^-1*t^-1*s^-1*t^-1
|
@test p == s^-1*t^-1*s^-1*t^-1*s^-1*t^-1
|
||||||
@test o*p == one(FGWord)
|
@test o*p == parent(o*p)()
|
||||||
w = FGWord([o.symbols..., p.symbols...])
|
w = FPGroupElem([o.symbols..., p.symbols...])
|
||||||
@test Groups.reduce!(w).symbols ==Vector{FGSymbol}([])
|
w.parent = G
|
||||||
|
@test Groups.reduce!(w).symbols ==Vector{FPSymbol}([])
|
||||||
end
|
end
|
||||||
@testset "arithmetic" begin
|
|
||||||
@test Groups.r_multiply!(FGWord(t),[s,t]; reduced=true) == t*s*t
|
|
||||||
@test Groups.r_multiply!(FGWord(t),[s,t]; reduced=false) == t*s*t
|
|
||||||
|
|
||||||
@test Groups.l_multiply!(FGWord(t),[s,t]; reduced=true) == t*s*t
|
@testset "binary/inv operations" begin
|
||||||
@test Groups.l_multiply!(FGWord(t),[s,t]; reduced=false) == t*s*t
|
@test parent(s) == G
|
||||||
|
@test parent(s) === parent(deepcopy(s))
|
||||||
|
@test isa(s*t, FPGroupElem)
|
||||||
|
@test parent(s*t) == parent(s^2)
|
||||||
|
@test s*s == s^2
|
||||||
|
@test inv(s*s) == inv(s^2)
|
||||||
|
@test inv(s)^2 == inv(s^2)
|
||||||
|
@test inv(s)*inv(s) == inv(s^2)
|
||||||
|
@test inv(s*t) == inv(t)*inv(s)
|
||||||
|
w = s*t*s^-1
|
||||||
|
@test inv(w) == s*t^-1*s^-1
|
||||||
@test (t*s*t^-1)^10 == t*s^10*t^-1
|
@test (t*s*t^-1)^10 == t*s^10*t^-1
|
||||||
@test (t*s*t^-1)^-10 == t*s^-10*t^-1
|
@test (t*s*t^-1)^-10 == t*s^-10*t^-1
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "replacements" begin
|
@testset "replacements" begin
|
||||||
@test Groups.is_subsymbol(s, Groups.change_pow(s,2)) == true
|
a = FPSymbol("a")
|
||||||
@test Groups.is_subsymbol(s, Groups.change_pow(s,-2)) == false
|
b = FPSymbol("b")
|
||||||
@test Groups.is_subsymbol(t, Groups.change_pow(s,-2)) == false
|
@test Groups.is_subsymbol(a, Groups.change_pow(a,2)) == true
|
||||||
@test Groups.is_subsymbol(inv(t), Groups.change_pow(t,-2)) == true
|
@test Groups.is_subsymbol(a, Groups.change_pow(a,-2)) == false
|
||||||
|
@test Groups.is_subsymbol(b, Groups.change_pow(a,-2)) == false
|
||||||
|
@test Groups.is_subsymbol(inv(b), Groups.change_pow(b,-2)) == true
|
||||||
c = s*t*s^-1*t^-1
|
c = s*t*s^-1*t^-1
|
||||||
@test findfirst(c, s^-1*t^-1) == 3
|
@test findfirst(c, s^-1*t^-1) == 3
|
||||||
@test findnext(c*s^-1, s^-1*t^-1,3) == 3
|
@test findnext(c*s^-1, s^-1*t^-1,3) == 3
|
||||||
@test findnext(c*s^-1*t^-1, s^-1*t^-1,4) == 5
|
@test findnext(c*s^-1*t^-1, s^-1*t^-1,4) == 5
|
||||||
@test findfirst(c*t, c) == 0
|
@test findfirst(c*t, c) == 0
|
||||||
w = s*t*s^-1
|
w = s*t*s^-1
|
||||||
subst = Dict{FGWord, FGWord}(w => s^1, s*t^-1 => t^4)
|
subst = Dict{FPGroupElem, FPGroupElem}(w => s^1, s*t^-1 => t^4)
|
||||||
@test Groups.replace(c, 1, s*t, one(FGWord)) == s^-1*t^-1
|
@test Groups.replace(c, 1, s*t, G()) == s^-1*t^-1
|
||||||
|
|
||||||
@test Groups.replace(c, 1, w, subst[w]) == s*t^-1
|
@test Groups.replace(c, 1, w, subst[w]) == s*t^-1
|
||||||
@test Groups.replace(s*c*t^-1, 1, w, subst[w]) == s^2*t^-2
|
@test Groups.replace(s*c*t^-1, 1, w, subst[w]) == s^2*t^-2
|
||||||
@test Groups.replace(t*c*t, 2, w, subst[w]) == t*s
|
@test Groups.replace(t*c*t, 2, w, subst[w]) == t*s
|
||||||
@ -123,7 +153,7 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
@testset "flip_AutSymbol correctness" begin
|
@testset "flip_AutSymbol correctness" begin
|
||||||
a,b,c,d = [FGWord(FGSymbol(i)) for i in ["a", "b", "c", "d"]]
|
a,b,c,d = [FPGroupElem(FPSymbol(i)) for i in ["a", "b", "c", "d"]]
|
||||||
domain = [a,b,c,d]
|
domain = [a,b,c,d]
|
||||||
@test flip_AutSymbol(1)(domain) == [a^-1, b,c,d]
|
@test flip_AutSymbol(1)(domain) == [a^-1, b,c,d]
|
||||||
@test flip_AutSymbol(2)(domain) == [a, b^-1,c,d]
|
@test flip_AutSymbol(2)(domain) == [a, b^-1,c,d]
|
||||||
@ -136,7 +166,7 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
@testset "symmetric_AutSymbol correctness" begin
|
@testset "symmetric_AutSymbol correctness" begin
|
||||||
a,b,c,d = [FGWord(FGSymbol(i)) for i in ["a", "b", "c", "d"]]
|
a,b,c,d = [FPGroupElem(FPSymbol(i)) for i in ["a", "b", "c", "d"]]
|
||||||
domain = [a,b,c,d]
|
domain = [a,b,c,d]
|
||||||
σ = symmetric_AutSymbol([1,2,3,4])
|
σ = symmetric_AutSymbol([1,2,3,4])
|
||||||
@test σ(domain) == domain
|
@test σ(domain) == domain
|
||||||
@ -156,7 +186,7 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
@testset "mul_AutSymbol correctness" begin
|
@testset "mul_AutSymbol correctness" begin
|
||||||
a,b,c,d = [FGWord(FGSymbol(i)) for i in ["a", "b", "c", "d"]]
|
a,b,c,d = [FPGroupElem(FPSymbol(i)) for i in ["a", "b", "c", "d"]]
|
||||||
domain = [a,b,c,d]
|
domain = [a,b,c,d]
|
||||||
i,j = 1,2
|
i,j = 1,2
|
||||||
r = rmul_AutSymbol(i,j)
|
r = rmul_AutSymbol(i,j)
|
||||||
@ -193,7 +223,6 @@ end
|
|||||||
@test inv(l)(domain) == [a,d^-1*b,c,d]
|
@test inv(l)(domain) == [a,d^-1*b,c,d]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@testset "AutWords" begin
|
@testset "AutWords" begin
|
||||||
f = AutSymbol("a", 1, :(a()), v -> v)
|
f = AutSymbol("a", 1, :(a()), v -> v)
|
||||||
@test isa(GWord(f), GWord)
|
@test isa(GWord(f), GWord)
|
||||||
@ -203,6 +232,7 @@ end
|
|||||||
@test isa(f^2, AutWord)
|
@test isa(f^2, AutWord)
|
||||||
@test isa(f^-1, AutWord)
|
@test isa(f^-1, AutWord)
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "eltary functions" begin
|
@testset "eltary functions" begin
|
||||||
f = symmetric_AutSymbol([2,1,4,3])
|
f = symmetric_AutSymbol([2,1,4,3])
|
||||||
@test isa(inv(f), AutSymbol)
|
@test isa(inv(f), AutSymbol)
|
||||||
@ -210,6 +240,7 @@ end
|
|||||||
@test f^-1 == GWord(inv(f))
|
@test f^-1 == GWord(inv(f))
|
||||||
@test inv(f) == f
|
@test inv(f) == f
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "reductions/arithmetic" begin
|
@testset "reductions/arithmetic" begin
|
||||||
f = symmetric_AutSymbol([2,1,4,3])
|
f = symmetric_AutSymbol([2,1,4,3])
|
||||||
f² = Groups.r_multiply(AutWord(f), [f], reduced=false)
|
f² = Groups.r_multiply(AutWord(f), [f], reduced=false)
|
||||||
@ -221,6 +252,7 @@ end
|
|||||||
@test a*b == b*a
|
@test a*b == b*a
|
||||||
@test a^3 * b^3 == one(a)
|
@test a^3 * b^3 == one(a)
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "specific Aut(𝔽₄) tests" begin
|
@testset "specific Aut(𝔽₄) tests" begin
|
||||||
N = 4
|
N = 4
|
||||||
import Combinatorics.nthperm
|
import Combinatorics.nthperm
|
||||||
@ -243,3 +275,5 @@ end
|
|||||||
@test length(p) == 53
|
@test length(p) == 53
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user