From 7517a8feb967a52f781c93a26996a536d0ca74e4 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Mon, 20 Apr 2020 00:52:06 +0200 Subject: [PATCH] tests and imports for findlast, findprev --- src/Groups.jl | 2 +- test/FreeGroup-tests.jl | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Groups.jl b/src/Groups.jl index 9dc67cb..4312ac2 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -7,7 +7,7 @@ import AbstractAlgebra: order, gens, matrix_repr import Base: length, ==, hash, show, convert, eltype, iterate import Base: inv, reduce, *, ^, power_by_squaring -import Base: findfirst, findnext, replace +import Base: findfirst, findnext, findlast, findprev, replace import Base: deepcopy_internal using LinearAlgebra diff --git a/test/FreeGroup-tests.jl b/test/FreeGroup-tests.jl index 09924df..7a4e720 100644 --- a/test/FreeGroup-tests.jl +++ b/test/FreeGroup-tests.jl @@ -36,7 +36,8 @@ end @test isa(Vector{FreeGroupElem}([s,t]), Vector{FreeGroupElem}) @test length(FreeGroupElem(s)) == 1 @test length(FreeGroupElem(t)) == 2 - + @test Groups.FreeSymbol(:s, 1) != Groups.FreeSymbol(:s, 2) + @test Groups.FreeSymbol(:s, 1) != Groups.FreeSymbol(:t, 1) end @testset "FreeGroup" begin @@ -64,6 +65,8 @@ end @test w[end] == tt @test collect(ttinv) == [ttinv] + + @test Groups.GroupWord([tt, inv(tt)]) isa FreeGroupElem end @testset "internal arithmetic" begin @@ -96,7 +99,7 @@ end @test o*p == one(parent(o*p)) w = FreeGroupElem([o.symbols..., p.symbols...]) w.parent = G - @test Groups.reduce!(w).symbols ==Vector{Groups.FreeSymbol}([]) + @test Groups.syllables(Groups.reduce(w)) == Vector{Groups.FreeSymbol}([]) end @testset "Group operations" begin @@ -126,8 +129,14 @@ end c = s*t*s^-1*t^-1 @test findfirst(s^-1*t^-1, c) == 3 @test findnext(s^-1*t^-1, c*s^-1,3) == 3 - @test findnext(s^-1*t^-1, c*s^-1*t^-1,4) == 5 + @test findnext(s^-1*t^-1, c*s^-1*t^-1, 4) == 5 @test findfirst(c, c*t) === nothing + + @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 + w = s*t*s^-1 subst = Dict{FreeGroupElem, FreeGroupElem}(w => s^1, s*t^-1 => t^4) @test Groups.replace(c, s*t=>one(G)) == s^-1*t^-1