Skip to content

Commit bc85fed

Browse files
committed
Add conformance tests for is_unit & is_nilpotent
Also improve is_nilpotent for matrices / matrix ring elements to work if the base ring is trivial.
1 parent 3f986c1 commit bc85fed

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

ext/TestExt/Rings-conformance-tests.jl

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,63 @@ function test_NCRing_interface(R::AbstractAlgebra.NCRing; reps = 50)
6767
end
6868
end
6969

70-
@testset "Basic functions" begin
70+
@testset "Basic properties" begin
7171
@test iszero(R()) # R() is supposed to construct 0 ?
7272
@test iszero(zero(R))
7373
@test isone(one(R))
7474
@test iszero(R(0))
7575
@test isone(R(1))
76-
@test isone(R(0)) || !is_unit(R(0))
76+
7777
@test is_unit(R(1))
78+
if is_trivial(R)
79+
@test isone(R(0))
80+
@test iszero(R(1))
81+
@test R(0) == R(1)
82+
else
83+
@test !is_unit(R(0))
84+
for i in 1:reps
85+
a = generate_element(R)::T
86+
@test is_unit(a) == is_unit(a^2)
87+
end
88+
end
89+
90+
# test is_nilpotent if it is supported
91+
try
92+
f = is_nilpotent(R(1))
93+
@test is_nilpotent(R(0))
94+
if is_trivial(R)
95+
@test is_nilpotent(R(1))
96+
else
97+
@test !is_unit(R(0))
98+
@test !is_nilpotent(R(1))
99+
for i in 1:reps
100+
a = generate_element(R)::T
101+
@test !(is_unit(a) && is_nilpotent(a))
102+
@test is_nilpotent(a) == is_nilpotent(a^2)
103+
if is_domain_type(typeof(a))
104+
@test is_nilpotent(a) == is_zero(a)
105+
end
106+
end
107+
end
108+
catch
109+
end
110+
end
111+
112+
@testset "hash, deepcopy, equality, printing, parent" begin
78113
for i in 1:reps
79114
a = generate_element(R)::T
80115
@test hash(a) isa UInt
81116
A = deepcopy(a)
82117
@test !ismutable(a) || a !== A
83118
@test equality(a, A)
84119
@test hash(a) == hash(A)
85-
@test parent(a) === parent(A)
120+
@test parent(a) === R
86121
@test sprint(show, "text/plain", a) isa String
87122
end
88123
@test sprint(show, "text/plain", R) isa String
124+
end
89125

126+
@testset "Basic arithmetic" begin
90127
for i in 1:reps
91128
a = generate_element(R)::T
92129
b = generate_element(R)::T

src/Matrix.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,13 +3875,13 @@ Return if `A` is nilpotent, i.e. if there exists a natural number $k$
38753875
such that $A^k = 0$. If `A` is not square an exception is raised.
38763876
"""
38773877
function is_nilpotent(A::MatrixElem{T}) where {T <: RingElement}
3878-
is_domain_type(T) || error("Only supported over integral domains")
38793878
!is_square(A) && error("Dimensions don't match in is_nilpotent")
3879+
is_zero(A) && return true
3880+
is_domain_type(T) || error("Only supported over integral domains")
38803881
is_zero(tr(A)) || return false
38813882
n = nrows(A)
38823883
A = deepcopy(A)
38833884
i = 1
3884-
is_zero(A) && return true
38853885
while i < n
38863886
i *= 2
38873887
A = mul!(A, A, A)

0 commit comments

Comments
 (0)