From ac7a8a98353f74ba7f3f24367e75a6b0de7ce8d2 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Mon, 27 Nov 2023 20:25:43 +0100 Subject: [PATCH] Fix incorrect `operate` test set (#242) --- test/interface.jl | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/test/interface.jl b/test/interface.jl index bfbfc8e..0f3c4e3 100644 --- a/test/interface.jl +++ b/test/interface.jl @@ -95,16 +95,32 @@ end end @testset "operate" begin - @testset "$(typeof(x))" for x in [2, big(3)] - @testset "$op" for op in [+, *, gcd, lcm] - @test MA.operate(op, x) !== x + @testset "$T" for T in (Int, BigInt, Rational{Int}) + x = T(7) + @testset "1-ary $op" for op in [+, *, gcd, lcm] + a = op(x) + b = MA.operate(op, x) + @test a == b + if MA.mutability(T, op, T) == MA.IsMutable() + @test a !== b + end end ops = [+, *, MA.add_mul, MA.sub_mul, MA.add_dot, gcd, lcm] - @testset "$op" for op in ops - @test MA.operate(op, x, x, x, x) !== op(x, x, x, x) + @testset "4-ary $op" for op in ops + a = op(x, x, x, x) + b = MA.operate(op, x, x, x, x) + @test a == b + if MA.mutability(T, op, T, T, T, T) == MA.IsMutable() + @test a !== b + end end - @testset "$op" for op in [-, /, div] - @test MA.operate(op, x, x) !== op(x, x) + @testset "2-ary $op" for op in [-, /, div] + a = op(x, x) + b = MA.operate(op, x, x) + @test a == b + if MA.mutability(T, op, T, T) == MA.IsMutable() + @test a !== b + end end end end