Skip to content

Commit

Permalink
Migrate test_elem methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Feb 21, 2025
1 parent 4b58484 commit 35d8ab4
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 44 deletions.
10 changes: 10 additions & 0 deletions src/antic/nf_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,16 @@ rand(rng::AbstractRNG, K::AbsSimpleNumField, r::AbstractUnitRange{Int}) = rand(r

rand(K::AbsSimpleNumField, r) = rand(Random.default_rng(), K, r)

###############################################################################
#
# Conformance test element generation
#
###############################################################################

function ConformanceTests.generate_element(K::AbsSimpleNumField)
return rand(K, -10:10)
end

###############################################################################
#
# AbsSimpleNumField constructor
Expand Down
10 changes: 10 additions & 0 deletions src/calcium/ca.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ function rand(C::CalciumField; depth::Int, bits::Int,
return x
end

###############################################################################
#
# Conformance test element generation
#
###############################################################################

function ConformanceTests.generate_element(R::CalciumField)
return rand(R, depth=5, bits=5)
end

###############################################################################
#
# Comparison and predicates
Expand Down
10 changes: 10 additions & 0 deletions src/calcium/qqbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,16 @@ function rand(R::QQBarField; degree::Int, bits::Int,
return x
end

###############################################################################
#
# Conformance test element generation
#
###############################################################################

function ConformanceTests.generate_element(R::QQBarField)
return rand(R, degree=5, bits=5)
end

###############################################################################
#
# Unary operators
Expand Down
10 changes: 10 additions & 0 deletions src/flint/fmpq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,16 @@ function rand_bits(::QQField, b::Int)
return z
end

###############################################################################
#
# Conformance test element generation
#
###############################################################################

function ConformanceTests.generate_element(R::QQField)
return rand_bits(ZZ, rand(0:100))//rand_bits(ZZ, rand(1:100))
end

###############################################################################
#
# Conversions and promotions
Expand Down
10 changes: 10 additions & 0 deletions src/flint/fmpz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2856,6 +2856,16 @@ function rand!(A::Vector{ZZRingElem}, v::StepRange{ZZRingElem,ZZRingElem})
return A
end

###############################################################################
#
# Conformance test element generation
#
###############################################################################

function ConformanceTests.generate_element(R::ZZRing)
return rand_bits(ZZ, rand(0:100))
end

###############################################################################
#
# Constructors
Expand Down
10 changes: 10 additions & 0 deletions src/flint/fmpz_mod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,16 @@ rand(r::Random.AbstractRNG, R::ZZModRing, b::AbstractArray) = rand(r, make(R, b)

rand(R::ZZModRing, b::AbstractArray) = rand(Random.default_rng(), R, b)

###############################################################################
#
# Conformance test element generation
#
###############################################################################

function ConformanceTests.generate_element(R::Nemo.ZZModRing)
return R(rand(Int))
end

###############################################################################
#
# Promotions
Expand Down
10 changes: 10 additions & 0 deletions src/flint/nmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,16 @@ rand(r::Random.AbstractRNG, R::zzModRing, b::AbstractArray) = rand(r, make(R, b)

rand(R::zzModRing, b::AbstractArray) = rand(Random.default_rng(), R, b)

###############################################################################
#
# Conformance test element generation
#
###############################################################################

function ConformanceTests.generate_element(R::Nemo.zzModRing)
return R(rand(Int))
end

###############################################################################
#
# Promotions
Expand Down
13 changes: 13 additions & 0 deletions src/flint/padic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -797,3 +797,16 @@ function with_precision(f, K::PadicField, n::Int)
end

Base.setprecision(f::Function, K::PadicField, n::Int) = with_precision(f, K, n)

###############################################################################
#
# Conformance test element generation
#
###############################################################################

function ConformanceTests.generate_element(R::PadicField)
p = prime(R)
prec = rand(1:R.prec_max)
r = ZZRingElem(0):p-1
return R(sum(rand(r)*p^i for i in 0:prec))
end
10 changes: 10 additions & 0 deletions src/gaussiannumbers/QQi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ function rand_bits(a::QQiField, b::Int)
return reduce!(QQiFieldElem(rand_bits(ZZi, clamp(b - t, 0, b)), rand_bits(ZZ, t)))
end

###############################################################################
#
# Conformance test element generation
#
###############################################################################

function ConformanceTests.generate_element(R::Nemo.QQiField)
return rand_bits(R, rand(0:200))
end

###############################################################################
#
# Basic manipulation
Expand Down
10 changes: 10 additions & 0 deletions src/gaussiannumbers/ZZi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ function rand_bits(::ZZiRing, b::Int)
return ZZiRingElem(rand_bits(ZZ, t), rand_bits(ZZ, b - t))
end

###############################################################################
#
# Conformance test element generation
#
###############################################################################

function ConformanceTests.generate_element(R::Nemo.ZZiRing)
return rand_bits(R, rand(0:200))
end

###############################################################################
#
# Basic manipulation
Expand Down
4 changes: 0 additions & 4 deletions test/antic/nf_elem-test.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
function test_elem(K::AbsSimpleNumField)
return rand(K, -10:10)
end

@testset "AbsSimpleNumFieldElem.conformance_tests" begin
R, x = polynomial_ring(QQ, "x")
K, a = number_field(x^3 + 3x + 1, "a")
Expand Down
4 changes: 0 additions & 4 deletions test/calcium/ca-test.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
function test_elem(R::CalciumField)
return rand(R, depth=5, bits=5)
end

@testset "CalciumFieldElem.conformance_tests" begin
R = CalciumField()
ConformanceTests.test_Field_interface(R)
Expand Down
4 changes: 0 additions & 4 deletions test/calcium/qqbar-test.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
function test_elem(R::QQBarField)
return rand(R, degree=5, bits=5)
end

@testset "QQBarFieldElem.conformance_tests" begin
R = algebraic_closure(QQ)
ConformanceTests.test_Field_interface(R)
Expand Down
4 changes: 0 additions & 4 deletions test/flint/fmpq-test.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import Nemo: AbstractAlgebra.PrettyPrinting

function test_elem(R::QQField)
return rand_bits(ZZ, rand(0:100))//rand_bits(ZZ, rand(1:100))
end

@testset "QQFieldElem.conformance_tests" begin
ConformanceTests.test_Field_interface_recursive(QQ)
end
Expand Down
4 changes: 0 additions & 4 deletions test/flint/fmpz-test.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import Nemo: AbstractAlgebra.PrettyPrinting

function test_elem(R::ZZRing)
return rand_bits(ZZ, rand(0:100))
end

@testset "ZZRingElem.conformance_tests" begin
ConformanceTests.test_Ring_interface_recursive(ZZ)
end
Expand Down
4 changes: 0 additions & 4 deletions test/flint/fmpz_mod-test.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
function test_elem(R::Nemo.ZZModRing)
return R(rand(Int))
end

@testset "ZZModRingElem.conformance_tests" begin
# for the modulus 1 we get a null ring and some things don't work quite
# right, e.g. isone(one(S))==false when S is a univariate polynomial ring
Expand Down
4 changes: 0 additions & 4 deletions test/flint/nmod-test.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
function test_elem(R::Nemo.zzModRing)
return R(rand(Int))
end

@testset "zzModRingElem.conformance_tests" begin
# for the modulus 1 we get a null ring and some things don't work quite
# right, e.g. isone(one(S))==false when S is a univariate polynomial ring
Expand Down
7 changes: 0 additions & 7 deletions test/flint/padic-test.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
function test_elem(R::PadicField)
p = prime(R)
prec = rand(1:R.prec_max)
r = ZZRingElem(0):p-1
return R(sum(rand(r)*p^i for i in 0:prec))
end

@testset "PadicFieldElem.conformance_tests" begin
# TODO: make the following work; for now they fail because the conformance
# tests want to use isapprox on PadicFieldElem elements, but no such method exists
Expand Down
4 changes: 0 additions & 4 deletions test/gaussiannumbers/fmpqi-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ end
end
end

function test_elem(R::Nemo.QQiField)
return rand_bits(R, rand(0:200))
end

@testset "QQiFieldElem.conformance_tests" begin
ConformanceTests.test_Field_interface(QQi)
end
4 changes: 0 additions & 4 deletions test/gaussiannumbers/fmpzi-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ end
@test b == A && a == B
end

function test_elem(R::Nemo.ZZiRing)
return rand_bits(R, rand(0:200))
end

@testset "ZZiRingElem.conformance_tests" begin
ConformanceTests.test_Ring_interface(ZZi)
ConformanceTests.test_EuclideanRing_interface(ZZi)
Expand Down
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ end
ComplexField() => ComplexMatrix,
)

@everywhere include(joinpath(pathof(AbstractAlgebra), "..", "..", "test", "Rings-conformance-tests.jl"))
@everywhere include("rand.jl")
include("Nemo-test.jl")

0 comments on commit 35d8ab4

Please sign in to comment.