From b6f1d9e6e75a5a83de052fd84bd08ce00ffb7b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 1 Oct 2024 10:53:48 +0200 Subject: [PATCH 01/10] Add more exhaustive mutating op tests to ring conformance test --- test/Rings-conformance-tests.jl | 159 +++++++++++++++++++++++--------- 1 file changed, 117 insertions(+), 42 deletions(-) diff --git a/test/Rings-conformance-tests.jl b/test/Rings-conformance-tests.jl index c6c5a138a1..d5edf08ca6 100644 --- a/test/Rings-conformance-tests.jl +++ b/test/Rings-conformance-tests.jl @@ -21,6 +21,113 @@ function equality(a::T, b::T) where T <: AbstractAlgebra.NCRingElement end end +function test_mutating_op_like_zero(f::Function, f!::Function, a) + A = deepcopy(a) + a = f!(a) + @test equality(a, f(A)) + a = deepcopy(A) +end + +function test_mutating_op_like_neg(f::Function, f!::Function, a, b) + A = deepcopy(a) + B = deepcopy(b) + a = f!(a, b) + @test equality(a, f(B)) + @test b == B + a = deepcopy(A) + b = deepcopy(B) + + a = f!(a) + @test equality(a, f(A)) + a = deepcopy(A) +end + +function test_mutating_op_like_add(f::Function, f!::Function, a, b, c) + A = deepcopy(a) + B = deepcopy(b) + C = deepcopy(c) + + a = f!(a, b, c) + @test equality(a, f(B, C)) + @test b == B + @test c == C + a = deepcopy(A) + b = deepcopy(B) + c = deepcopy(C) + + a = f!(a, a, b) + @test equality(a, f(A, B)) + @test b == B + a = deepcopy(A) + b = deepcopy(B) + + a = f!(a, b, a) + @test equality(a, f(B, A)) + @test b == B + a = deepcopy(A) + b = deepcopy(B) + + a = f!(a, b, b) + @test equality(a, f(B, B)) + @test b == B + a = deepcopy(A) + b = deepcopy(B) + + a = f!(a, a, a) + @test equality(a, f(A, A)) + a = deepcopy(A) + + a = f!(a, b) + @test equality(a, f(A, B)) + @test b == B + a = deepcopy(A) + b = deepcopy(B) + + a = f!(a, a) + @test equality(a, f(A, A)) + a = deepcopy(A) +end + +function test_mutating_op_like_addmul(f::Function, f!_::Function, a, b, c) + A = deepcopy(a) + B = deepcopy(b) + C = deepcopy(c) + + f!(a, b, c, ::Nothing) = f!_(a, b, c) + f!(a, b, c, t) = f!_(a, b, c, t) + + for t in [nothing, zero(parent(a)), deepcopy(a)] + a = f!(a, b, c, t) + @test equality(a, f(A, B, C)) + @test b == B + @test c == C + a = deepcopy(A) + b = deepcopy(B) + c = deepcopy(C) + + a = f!(a, a, b, t) + @test equality(a, f(A, A, B)) + @test b == B + a = deepcopy(A) + b = deepcopy(B) + + a = f!(a, b, a, t) + @test equality(a, f(A, B, A)) + @test b == B + a = deepcopy(A) + b = deepcopy(B) + + a = f!(a, b, b, t) + @test equality(a, f(A, B, B)) + @test b == B + a = deepcopy(A) + b = deepcopy(B) + + a = f!(a, a, a, t) + @test equality(a, f(A, A, A)) + a = deepcopy(A) + end +end function test_NCRing_interface(R::AbstractAlgebra.NCRing; reps = 50) @@ -171,50 +278,18 @@ function test_NCRing_interface(R::AbstractAlgebra.NCRing; reps = 50) a = test_elem(R)::T b = test_elem(R)::T c = test_elem(R)::T - A = deepcopy(a) - B = deepcopy(b) - C = deepcopy(c) + + test_mutating_op_like_zero(zero, zero!, a) + test_mutating_op_like_zero(one, one!, a) - x = deepcopy(a) - @test iszero(zero!(x)) - - ab = a*b - x = R() - @test mul!(x, a, b) == ab - x = deepcopy(b) - @test mul!(x, a, b) == ab - x = deepcopy(a) - @test mul!(x, x, b) == ab - x = deepcopy(b) - @test mul!(x, a, x) == ab - - ab = a+b - x = R() - @test add!(x, a, b) == ab - x = deepcopy(b) - @test add!(x, a, b) == ab - x = deepcopy(a) - @test add!(x, x, b) == ab - x = deepcopy(b) - @test add!(x, a, x) == ab - x = deepcopy(a) - @test add!(x, b) == ab - - # isapprox as BigFloat may fuse - # matrices don't implement addmul! - #t = R() - #x = deepcopy(a) - #@test equality(addmul!(x, b, c, t), a+b*c) - #x = deepcopy(a) - #@test equality(addmul!(x, x, c, t), a+a*c) - #x = deepcopy(a) - #@test equality(addmul!(x, b, x, t), a+b*a) - #x = deepcopy(a) - #@test equality(addmul!(x, x, x, t), a+a*a) + test_mutating_op_like_neg(-, neg!, a, b) - @test A == a - @test B == b - @test C == c + test_mutating_op_like_add(+, add!, a, b, c) + test_mutating_op_like_add(-, sub!, a, b, c) + test_mutating_op_like_add(*, mul!, a, b, c) + + test_mutating_op_like_addmul((a, b, c) -> a + b*c, addmul!, a, b, c) + test_mutating_op_like_addmul((a, b, c) -> a - b*c, submul!, a, b, c) end end end From daadd75f35bdfcbfc9cb76529783fd9720fd3cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 1 Oct 2024 15:09:52 +0200 Subject: [PATCH 02/10] Switch variable names --- test/Rings-conformance-tests.jl | 62 ++++++++++++++------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/test/Rings-conformance-tests.jl b/test/Rings-conformance-tests.jl index d5edf08ca6..3c8c075877 100644 --- a/test/Rings-conformance-tests.jl +++ b/test/Rings-conformance-tests.jl @@ -21,111 +21,101 @@ function equality(a::T, b::T) where T <: AbstractAlgebra.NCRingElement end end -function test_mutating_op_like_zero(f::Function, f!::Function, a) - A = deepcopy(a) +function test_mutating_op_like_zero(f::Function, f!::Function, A) + a = deepcopy(A) a = f!(a) @test equality(a, f(A)) - a = deepcopy(A) end -function test_mutating_op_like_neg(f::Function, f!::Function, a, b) - A = deepcopy(a) - B = deepcopy(b) +function test_mutating_op_like_neg(f::Function, f!::Function, A, B) + a = deepcopy(A) + b = deepcopy(B) a = f!(a, b) @test equality(a, f(B)) @test b == B - a = deepcopy(A) - b = deepcopy(B) + a = deepcopy(A) a = f!(a) @test equality(a, f(A)) - a = deepcopy(A) end -function test_mutating_op_like_add(f::Function, f!::Function, a, b, c) - A = deepcopy(a) - B = deepcopy(b) - C = deepcopy(c) - +function test_mutating_op_like_add(f::Function, f!::Function, A, B, C) + a = deepcopy(A) + b = deepcopy(B) + c = deepcopy(C) a = f!(a, b, c) @test equality(a, f(B, C)) @test b == B @test c == C + a = deepcopy(A) b = deepcopy(B) - c = deepcopy(C) - a = f!(a, a, b) @test equality(a, f(A, B)) @test b == B + a = deepcopy(A) b = deepcopy(B) - a = f!(a, b, a) @test equality(a, f(B, A)) @test b == B + a = deepcopy(A) b = deepcopy(B) - a = f!(a, b, b) @test equality(a, f(B, B)) @test b == B + a = deepcopy(A) - b = deepcopy(B) - a = f!(a, a, a) @test equality(a, f(A, A)) + a = deepcopy(A) - + b = deepcopy(B) a = f!(a, b) @test equality(a, f(A, B)) @test b == B + a = deepcopy(A) - b = deepcopy(B) - a = f!(a, a) @test equality(a, f(A, A)) a = deepcopy(A) end -function test_mutating_op_like_addmul(f::Function, f!_::Function, a, b, c) - A = deepcopy(a) - B = deepcopy(b) - C = deepcopy(c) - +function test_mutating_op_like_addmul(f::Function, f!_::Function, A, B, C) f!(a, b, c, ::Nothing) = f!_(a, b, c) f!(a, b, c, t) = f!_(a, b, c, t) - for t in [nothing, zero(parent(a)), deepcopy(a)] + for t in [nothing, zero(parent(A)), deepcopy(A)] + a = deepcopy(A) + b = deepcopy(B) + c = deepcopy(C) a = f!(a, b, c, t) @test equality(a, f(A, B, C)) @test b == B @test c == C + a = deepcopy(A) b = deepcopy(B) - c = deepcopy(C) - a = f!(a, a, b, t) @test equality(a, f(A, A, B)) @test b == B + a = deepcopy(A) b = deepcopy(B) - a = f!(a, b, a, t) @test equality(a, f(A, B, A)) @test b == B + a = deepcopy(A) b = deepcopy(B) - a = f!(a, b, b, t) @test equality(a, f(A, B, B)) @test b == B + a = deepcopy(A) - b = deepcopy(B) - a = f!(a, a, a, t) @test equality(a, f(A, A, A)) - a = deepcopy(A) end end From 6e1fc7ce47eb1bd7c05fc8e9c057311f5a87c5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 1 Oct 2024 15:29:37 +0200 Subject: [PATCH 03/10] Add `test_mutating_op_like_divexact` --- test/Rings-conformance-tests.jl | 55 ++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/test/Rings-conformance-tests.jl b/test/Rings-conformance-tests.jl index 3c8c075877..268bb03e76 100644 --- a/test/Rings-conformance-tests.jl +++ b/test/Rings-conformance-tests.jl @@ -39,6 +39,51 @@ function test_mutating_op_like_neg(f::Function, f!::Function, A, B) @test equality(a, f(A)) end +function test_mutating_op_like_divexact(f::Function, f!::Function, A, B, C) + a = deepcopy(A) + b = deepcopy(B) + c = deepcopy(C) + a = f!(a, b, c) + @test equality(a, f(B, C)) + @test b == B + @test c == C + + a = deepcopy(A) + b = deepcopy(B) + a = f!(a, a, b) + @test equality(a, f(A, B)) + @test b == B + + if typeof(A) == typeof(B) + a = deepcopy(A) + b = deepcopy(B) + a = f!(a, b, a) + @test equality(a, f(B, A)) + @test b == B + end + + a = deepcopy(A) + b = deepcopy(B) + a = f!(a, b, b) + @test equality(a, f(B, B)) + @test b == B + + a = deepcopy(A) + a = f!(a, a, a) + @test equality(a, f(A, A)) + + a = deepcopy(A) + b = deepcopy(B) + a = f!(a, b) + @test equality(a, f(A, B)) + @test b == B + + a = deepcopy(A) + a = f!(a, a) + @test equality(a, f(A, A)) + a = deepcopy(A) +end + function test_mutating_op_like_add(f::Function, f!::Function, A, B, C) a = deepcopy(A) b = deepcopy(B) @@ -47,19 +92,19 @@ function test_mutating_op_like_add(f::Function, f!::Function, A, B, C) @test equality(a, f(B, C)) @test b == B @test c == C - + a = deepcopy(A) b = deepcopy(B) a = f!(a, a, b) @test equality(a, f(A, B)) @test b == B - + a = deepcopy(A) b = deepcopy(B) a = f!(a, b, a) @test equality(a, f(B, A)) @test b == B - + a = deepcopy(A) b = deepcopy(B) a = f!(a, b, b) @@ -69,13 +114,13 @@ function test_mutating_op_like_add(f::Function, f!::Function, A, B, C) a = deepcopy(A) a = f!(a, a, a) @test equality(a, f(A, A)) - + a = deepcopy(A) b = deepcopy(B) a = f!(a, b) @test equality(a, f(A, B)) @test b == B - + a = deepcopy(A) a = f!(a, a) @test equality(a, f(A, A)) From c30cfd45549303f32a37d42fd4be09c3a6e9ea35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 1 Oct 2024 15:58:47 +0200 Subject: [PATCH 04/10] Add more mutating op tests to conformance tests --- test/Rings-conformance-tests.jl | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/Rings-conformance-tests.jl b/test/Rings-conformance-tests.jl index 268bb03e76..1b13ef4125 100644 --- a/test/Rings-conformance-tests.jl +++ b/test/Rings-conformance-tests.jl @@ -344,12 +344,16 @@ function test_Ring_interface(R::AbstractAlgebra.Ring; reps = 50) test_NCRing_interface(R) @testset "Basic functionality for commutative rings only" begin + @test isone(AbstractAlgebra.inv(one(R))) + test_mutating_op_like_neg(AbstractAlgebra.inv, inv!, one(R), one(R)) + test_mutating_op_like_neg(AbstractAlgebra.inv, inv!, one(R), -one(R)) + test_mutating_op_like_neg(AbstractAlgebra.inv, inv!, -one(R), one(R)) + test_mutating_op_like_neg(AbstractAlgebra.inv, inv!, -one(R), -one(R)) for i in 1:reps a = test_elem(R)::T b = test_elem(R)::T A = deepcopy(a) B = deepcopy(b) - @test isone(AbstractAlgebra.inv(one(R))) @test a*b == b*a # documentation is not clear on divexact if is_domain_type(T) @@ -359,6 +363,7 @@ function test_Ring_interface(R::AbstractAlgebra.Ring; reps = 50) if T isa RingElem @test iszero(b) || equality((b*a) / b, a) end + iszero(a) || iszero(b) || test_mutating_op_like_divexact(divexact, divexact!, b*a, b*a, b) else try t = divexact(b*a, b) @@ -407,7 +412,17 @@ function test_Field_interface(R::AbstractAlgebra.Field; reps = 50) for i in 1:reps a = test_elem(R)::T + b = test_elem(R)::T + A = deepcopy(a) + B = deepcopy(b) @test is_unit(a) == !iszero(a) + if !is_zero(a) + @test is_one(a * inv(a)) + @test is_one(inv(a) * a) + test_mutating_op_like_neg(inv, inv!, b, a) + end + @test A == a + @test B == b end end @@ -495,6 +510,14 @@ function test_EuclideanRing_interface(R::AbstractAlgebra.Ring; reps = 20) @test d == gcd(f, g) @test d == s*f + t*g @test gcdinv(f, g) == (d, s) + + if !is_zero(f) && !is_zero(g) && !is_zero(m) + test_mutating_op_like_add(AbstractAlgebra.div, div!, f, g, m) + test_mutating_op_like_add(rem, rem!, f, g, m) + test_mutating_op_like_add(mod, mod!, f, g, m) + end + test_mutating_op_like_add(gcd, gcd!, f, g, m) + test_mutating_op_like_add(lcm, lcm!, f, g, m) end end From 43b4721049da0fe8db6c85f3a874d51fdf318efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 4 Oct 2024 10:45:47 +0200 Subject: [PATCH 05/10] Add basic deepcopy test --- test/Rings-conformance-tests.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/Rings-conformance-tests.jl b/test/Rings-conformance-tests.jl index 1b13ef4125..3cda7f225b 100644 --- a/test/Rings-conformance-tests.jl +++ b/test/Rings-conformance-tests.jl @@ -224,7 +224,11 @@ function test_NCRing_interface(R::AbstractAlgebra.NCRing; reps = 50) for i in 1:reps a = test_elem(R)::T @test hash(a) isa UInt - @test hash(a) == hash(deepcopy(a)) + A = deepcopy(a) + @test !ismutable(a) || a !== A + @test equality(a, A) + @test hash(a) == hash(A) + @test parent(a) === parent(A) @test sprint(show, "text/plain", a) isa String end @test sprint(show, "text/plain", R) isa String From f0177285734db68214fb50bbc54fe6b14148d8ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 4 Oct 2024 11:02:31 +0200 Subject: [PATCH 06/10] Address comments --- test/Rings-conformance-tests.jl | 255 +++++++++++++------------------- 1 file changed, 102 insertions(+), 153 deletions(-) diff --git a/test/Rings-conformance-tests.jl b/test/Rings-conformance-tests.jl index 3cda7f225b..5cced1dbbc 100644 --- a/test/Rings-conformance-tests.jl +++ b/test/Rings-conformance-tests.jl @@ -22,146 +22,102 @@ function equality(a::T, b::T) where T <: AbstractAlgebra.NCRingElement end function test_mutating_op_like_zero(f::Function, f!::Function, A) - a = deepcopy(A) - a = f!(a) - @test equality(a, f(A)) + a = deepcopy(A) + a = f!(a) + @test equality(a, f(A)) end -function test_mutating_op_like_neg(f::Function, f!::Function, A, B) - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, b) - @test equality(a, f(B)) - @test b == B +function test_mutating_op_like_neg(f::Function, f!::Function, A) + for z in [zero(A), deepcopy(A)] + a = deepcopy(A) + z = f!(z, a) + @test equality(z, f(A)) + @test a == A + end - a = deepcopy(A) - a = f!(a) - @test equality(a, f(A)) + a = deepcopy(A) + a = f!(a) + @test equality(a, f(A)) end -function test_mutating_op_like_divexact(f::Function, f!::Function, A, B, C) - a = deepcopy(A) - b = deepcopy(B) - c = deepcopy(C) - a = f!(a, b, c) - @test equality(a, f(B, C)) - @test b == B - @test c == C - - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, a, b) - @test equality(a, f(A, B)) - @test b == B - - if typeof(A) == typeof(B) - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, b, a) - @test equality(a, f(B, A)) - @test b == B - end - - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, b, b) - @test equality(a, f(B, B)) - @test b == B - - a = deepcopy(A) - a = f!(a, a, a) - @test equality(a, f(A, A)) - - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, b) - @test equality(a, f(A, B)) - @test b == B - - a = deepcopy(A) - a = f!(a, a) - @test equality(a, f(A, A)) - a = deepcopy(A) -end +function test_mutating_op_like_add(f::Function, f!::Function, A, B) + for z in [zero(A), deepcopy(A), deepcopy(B)] + a = deepcopy(A) + b = deepcopy(B) + z = f!(z, a, b) + @test equality(z, f(A, B)) + @test a == A + @test b == B + end -function test_mutating_op_like_add(f::Function, f!::Function, A, B, C) - a = deepcopy(A) - b = deepcopy(B) - c = deepcopy(C) - a = f!(a, b, c) - @test equality(a, f(B, C)) - @test b == B - @test c == C - - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, a, b) - @test equality(a, f(A, B)) - @test b == B - - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, b, a) - @test equality(a, f(B, A)) - @test b == B - - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, b, b) - @test equality(a, f(B, B)) - @test b == B - - a = deepcopy(A) - a = f!(a, a, a) - @test equality(a, f(A, A)) - - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, b) - @test equality(a, f(A, B)) - @test b == B - - a = deepcopy(A) - a = f!(a, a) - @test equality(a, f(A, A)) - a = deepcopy(A) + a = deepcopy(A) + b = deepcopy(B) + a = f!(a, a, b) + @test equality(a, f(A, B)) + @test b == B + + a = deepcopy(A) + b = deepcopy(B) + b = f!(b, a, b) + @test equality(b, f(A, B)) + @test a == A + + a = deepcopy(A) + b = deepcopy(B) + a = f!(a, b, b) + @test equality(a, f(B, B)) + @test b == B + + b = deepcopy(B) + b = f!(b, b, b) + @test equality(b, f(B, B)) + + a = deepcopy(A) + b = deepcopy(B) + a = f!(a, b) + @test equality(a, f(A, B)) + @test b == B + + b = deepcopy(B) + b = f!(b, b) + @test equality(b, f(B, B)) end -function test_mutating_op_like_addmul(f::Function, f!_::Function, A, B, C) - f!(a, b, c, ::Nothing) = f!_(a, b, c) - f!(a, b, c, t) = f!_(a, b, c, t) - - for t in [nothing, zero(parent(A)), deepcopy(A)] - a = deepcopy(A) - b = deepcopy(B) - c = deepcopy(C) - a = f!(a, b, c, t) - @test equality(a, f(A, B, C)) - @test b == B - @test c == C - - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, a, b, t) - @test equality(a, f(A, A, B)) - @test b == B - - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, b, a, t) - @test equality(a, f(A, B, A)) - @test b == B - - a = deepcopy(A) - b = deepcopy(B) - a = f!(a, b, b, t) - @test equality(a, f(A, B, B)) - @test b == B - - a = deepcopy(A) - a = f!(a, a, a, t) - @test equality(a, f(A, A, A)) - end +function test_mutating_op_like_addmul(f::Function, f!_::Function, Z, A, B) + f!(z, a, b, ::Nothing) = f!_(z, a, b) + f!(z, a, b, t) = f!_(z, a, b, t) + + for t in [nothing, zero(A), deepcopy(A)] + z = deepcopy(Z) + a = deepcopy(A) + b = deepcopy(B) + z = f!(z, a, b, t) + @test equality(z, f(Z, A, B)) + @test a == A + @test b == B + + a = deepcopy(A) + b = deepcopy(B) + a = f!(a, a, b, t) + @test equality(a, f(A, A, B)) + @test b == B + + a = deepcopy(A) + b = deepcopy(B) + b = f!(b, a, b, t) + @test equality(b, f(B, A, B)) + @test a == A + + a = deepcopy(A) + b = deepcopy(B) + a = f!(a, b, b, t) + @test equality(a, f(A, B, B)) + @test b == B + + b = deepcopy(B) + b = f!(b, b, b, t) + @test equality(b, f(B, B, B)) + end end function test_NCRing_interface(R::AbstractAlgebra.NCRing; reps = 50) @@ -321,11 +277,11 @@ function test_NCRing_interface(R::AbstractAlgebra.NCRing; reps = 50) test_mutating_op_like_zero(zero, zero!, a) test_mutating_op_like_zero(one, one!, a) - test_mutating_op_like_neg(-, neg!, a, b) + test_mutating_op_like_neg(-, neg!, a) - test_mutating_op_like_add(+, add!, a, b, c) - test_mutating_op_like_add(-, sub!, a, b, c) - test_mutating_op_like_add(*, mul!, a, b, c) + test_mutating_op_like_add(+, add!, a, b) + test_mutating_op_like_add(-, sub!, a, b) + test_mutating_op_like_add(*, mul!, a, b) test_mutating_op_like_addmul((a, b, c) -> a + b*c, addmul!, a, b, c) test_mutating_op_like_addmul((a, b, c) -> a - b*c, submul!, a, b, c) @@ -348,11 +304,9 @@ function test_Ring_interface(R::AbstractAlgebra.Ring; reps = 50) test_NCRing_interface(R) @testset "Basic functionality for commutative rings only" begin - @test isone(AbstractAlgebra.inv(one(R))) - test_mutating_op_like_neg(AbstractAlgebra.inv, inv!, one(R), one(R)) - test_mutating_op_like_neg(AbstractAlgebra.inv, inv!, one(R), -one(R)) - test_mutating_op_like_neg(AbstractAlgebra.inv, inv!, -one(R), one(R)) - test_mutating_op_like_neg(AbstractAlgebra.inv, inv!, -one(R), -one(R)) + @test isone(AbstractAlgebra.inv(one(R))) + test_mutating_op_like_neg(AbstractAlgebra.inv, inv!, one(R)) + test_mutating_op_like_neg(AbstractAlgebra.inv, inv!, -one(R)) for i in 1:reps a = test_elem(R)::T b = test_elem(R)::T @@ -367,7 +321,7 @@ function test_Ring_interface(R::AbstractAlgebra.Ring; reps = 50) if T isa RingElem @test iszero(b) || equality((b*a) / b, a) end - iszero(a) || iszero(b) || test_mutating_op_like_divexact(divexact, divexact!, b*a, b*a, b) + iszero(b) || test_mutating_op_like_add(divexact, divexact!, b*a, b) else try t = divexact(b*a, b) @@ -416,17 +370,14 @@ function test_Field_interface(R::AbstractAlgebra.Field; reps = 50) for i in 1:reps a = test_elem(R)::T - b = test_elem(R)::T A = deepcopy(a) - B = deepcopy(b) @test is_unit(a) == !iszero(a) if !is_zero(a) @test is_one(a * inv(a)) @test is_one(inv(a) * a) - test_mutating_op_like_neg(inv, inv!, b, a) + test_mutating_op_like_neg(inv, inv!, a) end @test A == a - @test B == b end end @@ -515,13 +466,11 @@ function test_EuclideanRing_interface(R::AbstractAlgebra.Ring; reps = 20) @test d == s*f + t*g @test gcdinv(f, g) == (d, s) - if !is_zero(f) && !is_zero(g) && !is_zero(m) - test_mutating_op_like_add(AbstractAlgebra.div, div!, f, g, m) - test_mutating_op_like_add(rem, rem!, f, g, m) - test_mutating_op_like_add(mod, mod!, f, g, m) - end - test_mutating_op_like_add(gcd, gcd!, f, g, m) - test_mutating_op_like_add(lcm, lcm!, f, g, m) + test_mutating_op_like_add(AbstractAlgebra.div, div!, f, m) + test_mutating_op_like_add(rem, rem!, f, m) + test_mutating_op_like_add(mod, mod!, f, m) + test_mutating_op_like_add(gcd, gcd!, f, m) + test_mutating_op_like_add(lcm, lcm!, f, m) end end From ea557498a11de406d2b9a06108659a71b88a0e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 4 Oct 2024 11:28:27 +0200 Subject: [PATCH 07/10] Remove `rem!` test --- test/Rings-conformance-tests.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Rings-conformance-tests.jl b/test/Rings-conformance-tests.jl index 5cced1dbbc..9295c175b8 100644 --- a/test/Rings-conformance-tests.jl +++ b/test/Rings-conformance-tests.jl @@ -467,7 +467,6 @@ function test_EuclideanRing_interface(R::AbstractAlgebra.Ring; reps = 20) @test gcdinv(f, g) == (d, s) test_mutating_op_like_add(AbstractAlgebra.div, div!, f, m) - test_mutating_op_like_add(rem, rem!, f, m) test_mutating_op_like_add(mod, mod!, f, m) test_mutating_op_like_add(gcd, gcd!, f, m) test_mutating_op_like_add(lcm, lcm!, f, m) From 9aa5cb4bdfe85128d2df698d3e78382026b97c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 4 Oct 2024 12:26:13 +0200 Subject: [PATCH 08/10] Update test/Rings-conformance-tests.jl --- test/Rings-conformance-tests.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Rings-conformance-tests.jl b/test/Rings-conformance-tests.jl index 9295c175b8..d20496e55b 100644 --- a/test/Rings-conformance-tests.jl +++ b/test/Rings-conformance-tests.jl @@ -21,6 +21,8 @@ function equality(a::T, b::T) where T <: AbstractAlgebra.NCRingElement end end +# The following functions should not expect that their input is a `NCRingElem` or similar. +# They should be usable in more general types, that don't even have a `parent/elem` correspondence function test_mutating_op_like_zero(f::Function, f!::Function, A) a = deepcopy(A) a = f!(a) From fb43ff138f1e46e28bf4a9aaaa13ae4ff41dd734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 4 Oct 2024 14:02:28 +0200 Subject: [PATCH 09/10] Add comments --- test/Rings-conformance-tests.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/Rings-conformance-tests.jl b/test/Rings-conformance-tests.jl index d20496e55b..0fe893d9ef 100644 --- a/test/Rings-conformance-tests.jl +++ b/test/Rings-conformance-tests.jl @@ -30,6 +30,7 @@ function test_mutating_op_like_zero(f::Function, f!::Function, A) end function test_mutating_op_like_neg(f::Function, f!::Function, A) + # initialize storage var with different values to check that its value is not used for z in [zero(A), deepcopy(A)] a = deepcopy(A) z = f!(z, a) @@ -43,6 +44,7 @@ function test_mutating_op_like_neg(f::Function, f!::Function, A) end function test_mutating_op_like_add(f::Function, f!::Function, A, B) + # initialize storage var with different values to check that its value is not used for z in [zero(A), deepcopy(A), deepcopy(B)] a = deepcopy(A) b = deepcopy(B) @@ -89,6 +91,8 @@ function test_mutating_op_like_addmul(f::Function, f!_::Function, Z, A, B) f!(z, a, b, ::Nothing) = f!_(z, a, b) f!(z, a, b, t) = f!_(z, a, b, t) + # initialize storage var with different values to check that its value is not used + # and `nothing` for the three-arg dispatch for t in [nothing, zero(A), deepcopy(A)] z = deepcopy(Z) a = deepcopy(A) From 8368dc4d006a98042d273bb0c75543e7391a1861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 4 Oct 2024 14:02:55 +0200 Subject: [PATCH 10/10] Bump version to 0.43.3 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 5a74c02ca4..e3732051e5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "AbstractAlgebra" uuid = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" -version = "0.43.2" +version = "0.43.3" [deps] InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"