Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions ext/TestExt/Rings-conformance-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,63 @@ function test_NCRing_interface(R::AbstractAlgebra.NCRing; reps = 15)
end
end

@testset "Basic functions" begin
@testset "Basic properties" begin
@test iszero(R()) # R() is supposed to construct 0 ?
@test iszero(zero(R))
@test isone(one(R))
@test iszero(R(0))
@test isone(R(1))
@test isone(R(0)) || !is_unit(R(0))

@test is_unit(R(1))
if is_trivial(R)
@test isone(R(0))
@test iszero(R(1))
@test R(0) == R(1)
else
@test !is_unit(R(0))
for i in 1:reps
a = generate_element(R)::T
@test is_unit(a) == is_unit(a^2)
end
end

# test is_nilpotent if it is supported
try
f = is_nilpotent(R(1))
@test is_nilpotent(R(0))
if is_trivial(R)
@test is_nilpotent(R(1))
else
@test !is_unit(R(0))
@test !is_nilpotent(R(1))
for i in 1:reps
a = generate_element(R)::T
@test !(is_unit(a) && is_nilpotent(a))
@test is_nilpotent(a) == is_nilpotent(a^2)
if is_domain_type(typeof(a))
@test is_nilpotent(a) == is_zero(a)
end
end
end
catch
end
end

@testset "hash, deepcopy, equality, printing, parent" begin
for i in 1:reps
a = generate_element(R)::T
@test hash(a) isa UInt
A = deepcopy(a)
@test !ismutable(a) || a !== A
@test equality(a, A)
@test hash(a) == hash(A)
@test parent(a) === parent(A)
@test parent(a) === R
@test sprint(show, "text/plain", a) isa String
end
@test sprint(show, "text/plain", R) isa String
end

@testset "Basic arithmetic" begin
for i in 1:reps
a = generate_element(R)::T
b = generate_element(R)::T
Expand Down
4 changes: 2 additions & 2 deletions src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4142,13 +4142,13 @@ Return if `A` is nilpotent, i.e. if there exists a natural number $k$
such that $A^k = 0$. If `A` is not square an exception is raised.
"""
function is_nilpotent(A::MatrixElem{T}) where {T <: RingElement}
is_domain_type(T) || error("Only supported over integral domains")
!is_square(A) && error("Dimensions don't match in is_nilpotent")
is_zero(A) && return true
is_domain_type(T) || error("Only supported over integral domains")
is_zero(tr(A)) || return false
n = nrows(A)
A = deepcopy(A)
i = 1
is_zero(A) && return true
while i < n
i *= 2
A = mul!(A, A, A)
Expand Down
Loading