diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000000..9cbefe8a55 --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,4 @@ +coverage: + precision: 2 + round: down + range: 85...95 # FIXME: We should set this one to about 90...95 diff --git a/src/KnownProperties.jl b/src/KnownProperties.jl index 5991206763..38d0f06284 100644 --- a/src/KnownProperties.jl +++ b/src/KnownProperties.jl @@ -42,11 +42,3 @@ ERROR: MethodError: no method matching is_known(::typeof(dim), ::AbstractAlgebra ``` """ function is_known end - -# A generic implementation to look up attributes. This can be used to implement -# `is_known` for a specific type of arguments of unary functions. -function _is_known_via_attributes(f::Function, x::Any) - @req is_attribute_storing(x) "objects of type $(typeof(x)) do not support attribute storage" - return has_attribute(x, nameof(f)) -end - diff --git a/src/NCPoly.jl b/src/NCPoly.jl index 4758112d9d..bb655a34dc 100644 --- a/src/NCPoly.jl +++ b/src/NCPoly.jl @@ -146,11 +146,16 @@ number_of_generators(R::NCPolyRing) = 1 # ############################################################################### -function show(io::IO, p::NCPolyRing) +function show(io::IO, p::Union{NCPolyRing, PolyRing}) @show_name(io, p) @show_special(io, p) - print(io, "Univariate polynomial ring in ", var(p), " over ") - print(terse(pretty(io)), Lowercase(), base_ring(p)) + if is_terse(io) + print(io, "Univariate polynomial ring") + else + io = pretty(io) + print(io, "Univariate polynomial ring in ", var(p), " over ") + print(terse(io), Lowercase(), base_ring(p)) + end end ############################################################################### diff --git a/src/Poly.jl b/src/Poly.jl index 2eaebd29ea..394c996dae 100644 --- a/src/Poly.jl +++ b/src/Poly.jl @@ -495,18 +495,6 @@ end @enable_all_show_via_expressify Union{PolynomialElem, NCPolyRingElem} -function show(io::IO, p::PolyRing) - @show_name(io, p) - @show_special(io, p) - if is_terse(io) - print(io, "Univariate polynomial ring") - else - io = pretty(io) - print(io, "Univariate polynomial ring in ", var(p), " over ") - print(terse(io), Lowercase(), base_ring(p)) - end -end - pretty_eq(x::PolyRingElem, y::PolyRingElem) = x == y function pretty_lt(x::PolyRingElem, y::PolyRingElem) if length(x) < length(y) diff --git a/test/Rings-test.jl b/test/Rings-test.jl index 0c54c39f1d..7e6e106a7c 100644 --- a/test/Rings-test.jl +++ b/test/Rings-test.jl @@ -1,4 +1,5 @@ include("julia/Integers-test.jl") +include("julia/Matrix-test.jl") include("broadcasting-test.jl") # artificially low cutoffs for testing purposes @@ -62,6 +63,16 @@ end end end +@testset "sqrt" begin + Base.sqrt(a::EuclideanRingResidueRingElem{BigInt}) = parent(a)(BigInt(sqrt(a.data))) + R = residue_ring(ZZ, 101)[1] + + @test sqrt(R(81), check=true) == R(9) + @test_throws ErrorException sqrt(R(82), check=true) + @test is_square_with_sqrt(R(16)) == (true, R(4)) + @test is_square_with_sqrt(R(15))[1] == false +end + @testset "properties" begin @test is_perfect(QQ) @test is_perfect(GF(2)) diff --git a/test/generic/Poly-test.jl b/test/generic/Poly-test.jl index 7a8bae24d4..7ad9aeba5c 100644 --- a/test/generic/Poly-test.jl +++ b/test/generic/Poly-test.jl @@ -3081,3 +3081,66 @@ end @test is_separable(x) @test !is_separable(x^2) end + +@testset "Generic.Poly.Misc" begin + # factor function is required for is_power. Implement naive ones here. + function AbstractAlgebra.factor(a::Integer) + R = parent(a) + f = Fac{typeof(a)}() + f.unit = sign(a) + a = abs(a) + for ix in [R(2), R(3), R(5), R(7), R(11)] + if is_zero(a % ix) + a /= ix + f.fac[ix] = 1 + end + while is_zero(a % ix) + a /= ix + f.fac[ix] += 1 + end + end + if !is_one(a) + error() + end + return f + end + function AbstractAlgebra.factor(p::PolyRingElem) + P = parent(p) + x = gen(P) + f = Fac{typeof(p)}() + ct = content(p) + cf = factor(ct) + ut = sign(leading_coefficient(p)) + for (t, k) in cf + f.fac[P(t)] = k + end + f.unit = P(ut) + p /= ut * ct + for y in [x + c for c in -2:2] + if is_zero(p % y) + p /= y + f.fac[y] = 1 + end + while is_zero(p % y) + p /= y + f.fac[y] += 1 + end + end + if !is_one(p) + error() + end + return f + end + ZZx, x = ZZ[:x] + @test is_power(x, 2) == (false, x) + @test is_power(x, 3) == (false, x) + @test is_power(x^2, 2) == (true, x) + @test is_power(3 * x^2, 2) == (false, 3 * x^2) + @test is_power(2^2 * x^2, 2) == (true, 2 * x) + @test is_power(2^3 * x^3, 3) == (true, 2 * x) + @test is_power(3^4 * x^4, 2) == (true, 9 * x^2) + @test is_power(-3^4 * x^4, 2) == (false, -81 * x^4) + @test is_power(-3^3 * x^3, 3) == (true, -3 * x) + @test is_power(3^2 * (x + 1)^2 * x^2, 2) == (true, 3 * (x + 1) * x) + @test is_power(-3^2 * (x + 1)^2 * x^2, 2) == (false, -3^2 * (x + 1)^2 * x^2) +end diff --git a/test/julia/Matrix-test.jl b/test/julia/Matrix-test.jl new file mode 100644 index 0000000000..b9d48e8f08 --- /dev/null +++ b/test/julia/Matrix-test.jl @@ -0,0 +1,36 @@ +@testset "Julia.Matrix.manipulation" begin + r, c = 1, 2 + A = zero_matrix(Int, r, c) + A[1, :] = [10, -2] + B = Int[10 -2] + + @test A == B + @test number_of_rows(A) == r + @test number_of_columns(A) == c +end + +@testset "Julia.Matrix.array_creation" begin + M = matrix_ring(ZZ, 2) + m1 = M(ZZ[1 2; 3 4]) + m2 = M(ZZ[1 0; 0 1]) + arr = Array(M, 2) + arr[1] = deepcopy(m1) + arr[2] = deepcopy(m2) + @test arr[1] == m1 + @test arr[2] == m2 +end + +@testset "Julia.Matrix.permutations" begin + M = matrix_ring(ZZ, 2) + m0 = M([1 2; 3 4]) + m1 = M([2 3; 4 5]) + m2 = M([3 4; 5 6]) + m3 = M([4 5; 6 7]) + m = elem_type(M)[m0 m1; m2 m3] + Rm = elem_type(M)[m2 m3; m0 m1] + Cm = elem_type(M)[m1 m0; m3 m2] + rm = swap_rows(m, 2, 1) + cm = swap_cols(m, 1, 2) + @test rm == Rm + @test cm == Cm +end