Future-proof elementwise array comparison

In v0.7, thanks to #16401,

julia> [1, 2, 3] == 1:3
true

but in v0.6.2 it is false. I am currently writing unit tests that make a lot of these comparisons, and I want it to work in both versions. Should I use all(a .== b) or something similar, or is there a smooth transition using Compat.jl?

I don’t think Compat can easily provide a solution which will work everywhere. You’d have to use @compat and replace the call to == with a custom operator. What packages have been doing until 0.7 is == collect(1:3), which is stricter than using all since it also checks the shape.

4 Likes