massive overhaul of tests

This commit is contained in:
kalmar 2017-05-11 18:30:23 +02:00
parent 0891f28c6f
commit 2e6cd65d39
1 changed files with 272 additions and 238 deletions

View File

@ -2,106 +2,136 @@ using Groups
using Base.Test
# 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
@test isa(FGSymbol(string(Char(rand(50:2000)))), Groups.GSymbol)
@test FGSymbol("abc").pow == 1
@test isa(s, FGSymbol)
@test isa(t, FGSymbol)
@test isa(FPSymbol(string(Char(rand(50:2000)))), GSymbol)
@test FPSymbol("abc").pow == 1
@test isa(s, FPSymbol)
@test isa(t, FPSymbol)
end
@testset "eltary functions" begin
@test length(s) == 1
@test one(s) == s^0
@test one(s) == one(FGSymbol)
@test Groups.change_pow(s,0) == one(s)
@test length(one(s)) == 0
@test Groups.change_pow(s, 0) == Groups.change_pow(t, 0)
@test length(Groups.change_pow(s, 0)) == 0
@test inv(s).pow == -1
@test FGSymbol("s", 3) == Groups.change_pow(s,3)
@test s^2 t^2
@test FPSymbol("s", 3) == Groups.change_pow(s, 3)
@test FPSymbol("s", 3) != FPSymbol("t", 3)
@test Groups.change_pow(inv(s), -3) == inv(Groups.change_pow(s, 3))
end
@testset "powers" begin
s⁴ = Groups.change_pow(s,4)
@test s⁴.pow == 4
@test (s^4).symbols[1] == Groups.change_pow(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)
@test Groups.change_pow(s, 4) == FPSymbol("s", 4)
end
end
@testset "FGWords" begin
@testset "FPGroupElems" begin
s = FPSymbol("s")
t = FPSymbol("t", -2)
@testset "defines" begin
@test isa(Groups.GWord(s), Groups.GWord)
@test isa(Groups.GWord(s), FGWord)
@test isa(FGWord(s), Groups.GWord)
@test isa(convert(FGWord, s), GWord)
@test isa(convert(FGWord, s), FGWord)
@test isa(Vector{FGWord}([s,t]), Vector{FGWord})
@test Vector{GWord{FGSymbol}}([s,t]) == Vector{FGWord}([s,t])
@test isa(s*s, FGWord)
@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])
@test isa(Groups.GWord(s), FPGroupElem)
@test isa(FPGroupElem(s), Groups.GWord)
@test isa(convert(FPGroupElem, s), GWord)
@test isa(convert(FPGroupElem, s), FPGroupElem)
@test isa(Vector{FPGroupElem}([s,t]), Vector{FPGroupElem})
@test length(FPGroupElem(s)) == 1
@test length(FPGroupElem(t)) == 2
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
@testset "reductions" begin
@test one(FGWord) == one(s)*one(s)
w = GWord{FGSymbol}([s])
@test length(G().symbols) == 1
@test length((G()*G()).symbols) == 0
@test G() == G()*G()
w = deepcopy(s)
push!(w.symbols, (s^-1).symbols[1])
@test Groups.reduce!(w) == one(FGWord)
@test Groups.reduce!(w) == parent(w)()
o = (t*s)^3
@test o == t*s*t*s*t*s
p = (t*s)^-3
@test p == s^-1*t^-1*s^-1*t^-1*s^-1*t^-1
@test o*p == one(FGWord)
w = FGWord([o.symbols..., p.symbols...])
@test Groups.reduce!(w).symbols ==Vector{FGSymbol}([])
@test o*p == parent(o*p)()
w = FPGroupElem([o.symbols..., p.symbols...])
w.parent = G
@test Groups.reduce!(w).symbols ==Vector{FPSymbol}([])
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
@test Groups.l_multiply!(FGWord(t),[s,t]; reduced=false) == t*s*t
@testset "binary/inv operations" begin
@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
end
@testset "replacements" begin
@test Groups.is_subsymbol(s, Groups.change_pow(s,2)) == true
@test Groups.is_subsymbol(s, Groups.change_pow(s,-2)) == false
@test Groups.is_subsymbol(t, Groups.change_pow(s,-2)) == false
@test Groups.is_subsymbol(inv(t), Groups.change_pow(t,-2)) == true
a = FPSymbol("a")
b = FPSymbol("b")
@test Groups.is_subsymbol(a, Groups.change_pow(a,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
@test findfirst(c, s^-1*t^-1) == 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 findfirst(c*t, c) == 0
w = s*t*s^-1
subst = Dict{FGWord, FGWord}(w => s^1, s*t^-1 => t^4)
@test Groups.replace(c, 1, s*t, one(FGWord)) == s^-1*t^-1
subst = Dict{FPGroupElem, FPGroupElem}(w => s^1, s*t^-1 => t^4)
@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(s*c*t^-1, 1, w, subst[w]) == s^2*t^-2
@test Groups.replace(t*c*t, 2, w, subst[w]) == t*s
@ -123,7 +153,7 @@ end
end
@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]
@test flip_AutSymbol(1)(domain) == [a^-1, b,c,d]
@test flip_AutSymbol(2)(domain) == [a, b^-1,c,d]
@ -136,7 +166,7 @@ end
end
@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]
σ = symmetric_AutSymbol([1,2,3,4])
@test σ(domain) == domain
@ -156,7 +186,7 @@ end
end
@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]
i,j = 1,2
r = rmul_AutSymbol(i,j)
@ -193,7 +223,6 @@ end
@test inv(l)(domain) == [a,d^-1*b,c,d]
end
@testset "AutWords" begin
f = AutSymbol("a", 1, :(a()), v -> v)
@test isa(GWord(f), GWord)
@ -203,6 +232,7 @@ end
@test isa(f^2, AutWord)
@test isa(f^-1, AutWord)
end
@testset "eltary functions" begin
f = symmetric_AutSymbol([2,1,4,3])
@test isa(inv(f), AutSymbol)
@ -210,6 +240,7 @@ end
@test f^-1 == GWord(inv(f))
@test inv(f) == f
end
@testset "reductions/arithmetic" begin
f = symmetric_AutSymbol([2,1,4,3])
= Groups.r_multiply(AutWord(f), [f], reduced=false)
@ -221,6 +252,7 @@ end
@test a*b == b*a
@test a^3 * b^3 == one(a)
end
@testset "specific Aut(𝔽₄) tests" begin
N = 4
import Combinatorics.nthperm
@ -243,3 +275,5 @@ end
@test length(p) == 53
end
end
end