diff --git a/test/interface.jl b/test/interface.jl index bfbfc8e9..d92c7f23 100644 --- a/test/interface.jl +++ b/test/interface.jl @@ -95,16 +95,35 @@ 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 + Types = (Int, BigInt, Rational{Int}) + type_is_mutable = function (op::F, ::Type{T}, ::V) where {F,T,V<:Val} + f = _ -> T + return MA.mutability(T, op, ntuple(f, V())...) == MA.IsMutable() + end + @testset "$T" for T in Types + arity_is_mutable = (op, n) -> type_is_mutable(op, T, Val(n)) + x = T(7) + @testset "1-ary $op" for op in [+, *, gcd, lcm] + a = op(x) + b = MA.operate(op, x) + is_mutable = arity_is_mutable(op, 1) + @test a == b + is_mutable && (@test a !== b) 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) + is_mutable = arity_is_mutable(op, 4) + @test a == b + is_mutable && (@test a !== b) 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) + is_mutable = arity_is_mutable(op, 2) + @test a == b + is_mutable && (@test a !== b) end end end