Hey,
Say I have an abstract type A
and many subtypes B, C, D
:
abstract type A end
struct B<:A end
struct C<:A end
should_return_one(::A) = 1
should_return_one(x::B) = # something else.
# remark that, on purpose, I did not overwrote the method for x::C
Suppose now that for testing reasons, I want to ensure that the subtypes are implementing the method correctly. I am testing it like that :
objects = (B(), C()) # there are a lot more objects here.
for o in objets
@test should_return_one(o) == 1
end
Now, if the method is very costly, testing the method for C
is not worth it because it will dispatch to the generic version. Thus, I’d like to only test when object do indeed overwrite the generic method:
objects = (B(), C()) # there are a lot more objects here.
for o in objets
condition = # the call will not dispatch to should_return_one(::A)
if condition
@test should_return_one(o) == 1
end
end
How can i write this condition ?