Skip to content

Commit

Permalink
More generic test_elem methods
Browse files Browse the repository at this point in the history
Also make sure other packages which only load Rings-conformance-tests.jl
get them.

Finally cleanup how we include Groups-conformance-tests.jl
  • Loading branch information
fingolfin committed Oct 3, 2024
1 parent 3fe0405 commit 423ff75
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 64 deletions.
68 changes: 57 additions & 11 deletions test/Rings-conformance-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,63 @@
# - test_MatSpace_interface(R)
# - test_MatAlgebra_interface(R)

#
# add methods for test_elem on ring elements here
#

function test_elem(R::AbstractAlgebra.Integers)
n = big(2)^rand((1,1,1,2,3,10,31,32,33,63,64,65,100))
return rand(R, -n:n)
end

function test_elem(R::AbstractAlgebra.Rationals)
B = base_ring(R)
n = test_elem(B)
d = test_elem(B)
return is_zero(d) ? R(n) : R(n, d)
end

function test_elem(R::AbstractAlgebra.GFField)
return rand(R)
end

function test_elem(R::AbstractAlgebra.Floats{T}) where T
return rand(T)*rand(-100:100)
end

function test_elem(Rx::AbstractAlgebra.PolyRing)
R = base_ring(Rx)
return Rx(elem_type(R)[test_elem(R) for i in 1:rand(0:6)])
end

function test_elem(S::Union{AbstractAlgebra.MatSpace,
AbstractAlgebra.MatRing})
R = base_ring(S)
return S(elem_type(R)[test_elem(R) for i in 1:nrows(S), j in 1:ncols(S)])
end

function test_elem(R::AbstractAlgebra.EuclideanRingResidueRing)
return R(test_elem(base_ring(R)))
end

function test_elem(Rx::AbstractAlgebra.SeriesRing)
R = base_ring(Rx)
prec = rand(3:10)
len = rand(0:prec-1)
val = rand(0:prec-len)
# FIXME: constructors don't seem to catch use of negative val
@assert val >= 0
if elem_type(Rx) <: RelPowerSeriesRingElem
@assert prec >= len + val
return Rx(elem_type(R)[test_elem(R) for i in 1:len], len, prec, val)
else
@assert prec >= len
return Rx(elem_type(R)[test_elem(R) for i in 1:len], len, prec)
end
end


# helper
function equality(a::T, b::T) where T <: AbstractAlgebra.NCRingElement
if is_exact_type(T)
return a == b
Expand Down Expand Up @@ -393,11 +450,6 @@ function test_EuclideanRing_interface(R::AbstractAlgebra.Ring; reps = 20)
end


function test_elem(Rx::AbstractAlgebra.PolyRing)
R = base_ring(Rx)
return Rx(elem_type(R)[test_elem(R) for i in 1:rand(0:6)])
end

function test_Poly_interface(Rx::AbstractAlgebra.PolyRing; reps = 30)

T = elem_type(Rx)
Expand Down Expand Up @@ -479,12 +531,6 @@ function test_Poly_interface(Rx::AbstractAlgebra.PolyRing; reps = 30)
return nothing
end

function test_elem(S::Union{AbstractAlgebra.MatSpace,
AbstractAlgebra.MatRing})
R = base_ring(S)
return S(elem_type(R)[test_elem(R) for i in 1:nrows(S), j in 1:ncols(S)])
end


function test_MatSpace_interface(S::MatSpace; reps = 20)

Expand Down
19 changes: 1 addition & 18 deletions test/conformance-tests.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,2 @@
include("Groups-conformance-tests.jl")
include("Rings-conformance-tests.jl")
# TODO: add more

# add methods for test_elem here

function test_elem(R::AbstractAlgebra.Integers{BigInt})
n = big(2)^rand(1:100)
return rand(ZZ, -n:n)
end

function test_elem(R::AbstractAlgebra.Rationals{BigInt})
n = big(2)^rand(1:100)
m = big(2)^rand(1:100)
return rand(ZZ, -n:n)//rand(ZZ, 1:m)
end

function test_elem(R::AbstractAlgebra.GFField{Int64})
return rand(R)
end
4 changes: 0 additions & 4 deletions test/generic/AbsSeries-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
# Note: only useful to distinguish rings and fields for 1/2, 3/4, 5/6 if the
# algos differ, and 7 can often stand in for 5/6 if the algorithm supports it.

function test_elem(R::AbstractAlgebra.Generic.AbsPowerSeriesRing{BigInt})
rand(R, 0:12, -10:10)
end

@testset "Generic.AbsSeries.conformance" begin
R, x = power_series_ring(ZZ, 30, "x", model=:capped_absolute)
test_Ring_interface(R)
Expand Down
2 changes: 0 additions & 2 deletions test/generic/PermGroupAPI-test.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@testset "Groups API PermGroup" begin

include(joinpath(dirname(dirname(pathof(AbstractAlgebra))), "test", "Groups-conformance-tests.jl"))
@testset "Sym($n)" for n in [1,2,5,10]
G = SymmetricGroup(n)
test_Group_interface(G)
Expand Down
4 changes: 0 additions & 4 deletions test/generic/RelSeries-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
# Note: only useful to distinguish rings and fields for 1/2, 3/4, 5/6 if the
# algos differ, and 7 can often stand in for 5/6 if the algorithm supports it.

function test_elem(R::AbstractAlgebra.Generic.RelPowerSeriesRing{BigInt})
rand(R, 0:12, -10:10)
end

@testset "Generic.RelSeries.conformance" begin
R, x = power_series_ring(ZZ, 10, "x")
test_Ring_interface(R)
Expand Down
8 changes: 0 additions & 8 deletions test/generic/Residue-test.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
function test_elem(R::AbstractAlgebra.EuclideanRingResidueRing{BigInt})
return rand(R, 0:characteristic(R))
end

function test_elem(R::AbstractAlgebra.EuclideanRingResidueRing{AbstractAlgebra.Generic.Poly{T}}) where T
return rand(R, 0:100, -100:100)
end

@testset "EuclideanRingResidueRingElem.conformance_tests" begin
test_Ring_interface(residue_ring(ZZ, 1)[1]) # is_gen fails on polys
test_Ring_interface_recursive(residue_ring(ZZ, -4)[1])
Expand Down
8 changes: 0 additions & 8 deletions test/julia/Floats-test.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
function test_elem(R::AbstractAlgebra.Floats{Float64})
return rand(Float64)*rand(-100:100)
end

function test_elem(R::AbstractAlgebra.Floats{BigFloat})
return rand(BigFloat)*rand(-100:100)
end

@testset "Julia.Floats.conformance_tests" begin
test_Ring_interface(RDF)
test_Ring_interface(RealField)
Expand Down
4 changes: 0 additions & 4 deletions test/julia/GFElem-test.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
function test_elem(R::AbstractAlgebra.GFField)
return rand(R)
end

@testset "Julia.GFElem.conformance_tests" begin
test_Field_interface_recursive(GF(3))
test_Field_interface_recursive(GF(13))
Expand Down
5 changes: 0 additions & 5 deletions test/julia/Rationals-test.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
function test_elem(R::AbstractAlgebra.Rationals{BigInt})
n = big(2)^rand(1:100)
return rand(QQ, -n:n)
end

@testset "Julia.Rationals.conformance_tests" begin
test_Field_interface_recursive(QQ)
end
Expand Down

0 comments on commit 423ff75

Please sign in to comment.