Skip to content

Commit

Permalink
added Aqua tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausC committed Dec 24, 2023
1 parent d456768 commit 4cf9363
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 31 deletions.
11 changes: 6 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ repo = "https://github.com/KlausC/CommutativeRings.jl"
version = "0.6.0"

[deps]
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
LLLplus = "142c1900-a1c3-58ae-a66d-b187f9ca6423"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Scanf = "6ef1bc8b-493b-44e1-8d40-549aa65c4b41"

[compat]
Aqua = "0.8"
Polynomials = "1,2,3,4"
Primes = "0.5"
julia = "1"
julia = "1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,1.10,1.11"
LinearAlgebra = "1"
Random = "1"
Test = "1"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CommutativeRings.jl

[![Build Status][gha-img]][gha-url] [![Coverage Status][codecov-img]][codecov-url]
[![Build Status][gha-img]][gha-url] [![Coverage Status][codecov-img]][codecov-url] [![Aqua QA][aqua-img]][aqua-url]

W.I.P

Expand Down Expand Up @@ -643,3 +643,6 @@ The power series algorithms are partially from this wikipedia article [Formal Po
[codecov-img]: https://codecov.io/gh/KlausC/CommutativeRings.jl/branch/main/graph/badge.svg
[codecov-url]: https://codecov.io/gh/KlausC/CommutativeRings.jl
[aqua-img]: https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg
[aqua-url]: https://github.com/JuliaTesting/Aqua.jl
8 changes: 5 additions & 3 deletions src/conway.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,11 @@ function __init__()
# file imported from
# `https://www.math.rwth-aachen.de/~Frank.Luebeck/data/ConwayPol/CPimport.txt.gz`
# at 2023-11-11
file = joinpath(@__DIR__, "..", "data", "CPimport.txt")
empty!(CONWAY_POLYNOMIALS)
readparse(file, r -> store_conway!(r))
if ccall(:jl_generating_output, Cint, ()) == 0 # if we're not precompiling...
file = joinpath(@__DIR__, "..", "data", "CPimport.txt")
empty!(CONWAY_POLYNOMIALS)
readparse(file, r -> store_conway!(r))
end
end

end # module
6 changes: 5 additions & 1 deletion src/enumerations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ function hypercube(
throw(ErrorException("should not be reachable"))
end

function linear2tuple(x::Integer, b::NTuple{N,T}) where {N,T<:Integer}
function linear2tuple(x::Integer, b::Tuple{T,Vararg{T}}) where {T<:Integer}
N = length(b)
r = Vector{T}(undef, N)
for i = 1:N-1
x, r[i] = fldmod(x, b[i])
Expand Down Expand Up @@ -615,6 +616,9 @@ function ilog2(a::Base.BitInteger)
bpl = sizeof(a) * 8
bpl - 1 - leading_zeros(abs(a))
end
function ilog2(a::AbstractFloat)
Integer(floor(log2(a)))
end

"""
inv_hypercube(v::AbstractVector{<:Integer}, EnumCube(), [EnumFull(), EnumHalf()])
Expand Down
2 changes: 1 addition & 1 deletion src/galoisfields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ function homomorphism(
::Type{R},
::Type{S},
nr::Integer = 0,
) where {Z<:ZZmod,P<:UnivariatePolynomial{Z},T<:Union{Quotient{P},GaloisField},R<:T,S<:T}
) where {T<:Union{Quotient{<:UnivariatePolynomial{<:ZZmod}},GaloisField},R<:T,S<:T}

r = dimension(R)
s = dimension(S)
Expand Down
2 changes: 1 addition & 1 deletion src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ function _gcd(a::T, b::T, ::Type{<:UniqueFactorizationDomainTrait}) where T<:Rin
end

# extension to array
function gcd(aa::Union{AbstractVector{T},Tuple{Vararg{T}}}) where {T<:Ring}
function gcd(aa::Union{AbstractVector{T},Tuple{T,Vararg{T}}}) where {T<:Ring}
g = zero(T)
for x in aa
isone(g) && break
Expand Down
4 changes: 2 additions & 2 deletions src/linearalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ LinearAlgebra.rank(A::AbstractMatrix{<:Ring}) = rank(lu_total!(copy(A)))
Vector space generated by the vectors or matrix.
To obtain a basis of the space, use `Matrix(::VectorSpace)`.
"""
function VectorSpace(A::AbstractArray{R}...) where {R<:Ring}
B = convert(Array, hcat(A...))
function VectorSpace(A1::AbstractArray{R}, A::AbstractArray{R}...) where {R<:Ring}
B = convert(Array, hcat(A1, A...))
m = size(B, 1)
fac = lu_total!(B)
r = fac.rank
Expand Down
28 changes: 17 additions & 11 deletions src/multivarpolynom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function derive(p::P, d::NTuple{N,<:Integer}) where {S,N,P<:MultivariatePolynomi
ind = similar(p.ind)
coeff = similar(p.coeff)
j = 0
for i = eachindex(p.ind)
for i in eachindex(p.ind)
a = index2expo(p, i)
b = a .- d
if all(b .>= 0)
Expand All @@ -177,7 +177,11 @@ end
Return monic monomial with given exponent(s). (`monom(Z[:x.:y],[1,2]) == x * y^2`)
"""
function monom(P::Type{<:MultivariatePolynomial{S,N}}, xv::Vector{<:Integer}, lc = 1) where {N,S}
function monom(
P::Type{<:MultivariatePolynomial{S,N}},
xv::Vector{<:Integer},
lc = 1,
) where {N,S}
n = length(xv)
n == 0 && return zero(P)
length(xv) != N &&
Expand Down Expand Up @@ -416,12 +420,13 @@ function isless(a::T, b::T) where T<:MultivariatePolynomial
end
end

function +(a::T...) where T<:MultivariatePolynomial
function +(a1::T, a2::T...) where T<:MultivariatePolynomial
a = (a1, a2...)
n = length(a)
n > 0 || throw(ArgumentError("+ requires at least one argument"))
n == 1 && return a[1]
c = similar(a[1].coeff)
d = similar(a[1].ind)
n == 1 && return a1
c = similar(a1.coeff)
d = similar(a1.ind)
j = 0
p = ones(Int, n)
pm = [mindex(x, 1) for x in a]
Expand Down Expand Up @@ -552,9 +557,10 @@ end
function expo2ordblock(
::Type{P},
a::AbstractVector{<:Integer},
) where {R,N,X,T,M,B,P<:MultivariatePolynomial{R,N,X,NTuple{M,T},B}}
) where {R,N,X,T,Y<:Tuple{T,Vararg{T}},B,P<:MultivariatePolynomial{R,N,X,Y,B}}

t = tupcon(B)
M = length(Y.parameters)
res = Vector{T}(undef, M)
j = 0
for i = 1:M
Expand Down Expand Up @@ -688,10 +694,10 @@ function fillindex(
end
function fillindex(
f,
::Type{<:MultivariatePolynomial{R,N,X,Tuple{Vararg{T,M}}}},
::Type{<:MultivariatePolynomial{R,N,X,Tuple{T,Vararg{T,M}}}},
) where {R,N,X,M,T}
ft = f(T)
ntuple(x -> ft, M)
ntuple(x -> ft, M + 1)
end

"""
Expand Down Expand Up @@ -983,7 +989,7 @@ function criterion(G::AbstractVector{<:Polynomial}, C::AbstractVector, i::Int, k
fx = multideg(f)
gx = multideg(g)
Base.sum(fx .* gx) == 0 && return true # product criterion - no powers in common
for j = eachindex(G)
for j in eachindex(G)
(j == i || j == k) && continue
hx = multideg(G[j])
if all(hx .<= max.(fx, gx)) && !in(minmax(i, j), C) && !in(minmax(k, j), C)
Expand Down Expand Up @@ -1108,7 +1114,7 @@ The indices with `pos[i] == 0` are silently ignored.
"""
function reindex2(xa::AbstractVector, pos::AbstractVector{<:Integer}, n::Integer)
res = zeros(Int, n)
for i = eachindex(pos)
for i in eachindex(pos)
posi = pos[i]
if posi != 0
res[posi] = xa[i]
Expand Down
2 changes: 0 additions & 2 deletions src/ratqqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ function ratqr!(A::AbstractMatrix{T}, r::AbstractVector{T}) where T

end

ilog2(a::AbstractFloat) = Integer(floor(log2(a)))

"""
r1sqrt(a, n)
For given real `a` and `n > 0`, find a integers `b` (odd) and `k` so `a * b^2 * 2^-2k ≈ 1`,
Expand Down
2 changes: 1 addition & 1 deletion src/typevars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ sintern(m::IdentSymbols) = m
sintern(m::BigInt) = Symbol(m)
sintern(a::IdentSymbols...) = Symbol(tuple(a...))
sintern(a::AbstractVector{<:IdentSymbols}) = Symbol(a)
sintern(a::Tuple{Vararg{T}}) where T<:IdentSymbols = Symbol(a)
sintern(a::Tuple{T,Vararg{T}}) where T<:IdentSymbols = Symbol(a)
sintern(a::Any) = Symbol(Base.hash(a))
9 changes: 9 additions & 0 deletions test/Aqua.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Aqua

Aqua.test_all(
CommutativeRings;
ambiguities = true,
stale_deps = true,
deps_compat = true,
piracies = (treat_as_own = [Base.binomial],),
)
4 changes: 4 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"

[compat]
Aqua = "0.8"
4 changes: 1 addition & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Test
using CommutativeRings

@testset "ambiguities" begin
@test length(Test.detect_ambiguities(CommutativeRings)) == 0
end
@testset "Aqua" begin include("Aqua.jl") end

@testset "typevars" begin include("typevars.jl") end
@testset "generic" begin include("generic.jl") end
Expand Down

0 comments on commit 4cf9363

Please sign in to comment.