Skip to content

Commit

Permalink
#58 - added check for interface function existence
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Dec 19, 2017
1 parent 4aae8e0 commit eb744f4
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion src/helper_functions.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Base.<=

export sign_cadlag,
jump2pi
jump2pi,
check_method_implementation

"""
sign_cadlag(x::N)::N where {N<:Real}
Expand Down Expand Up @@ -86,3 +87,68 @@ direction (1, 0).
function <=(u::AbstractVector{Float64}, v::AbstractVector{Float64})::Bool
return jump2pi(atan2(u[2], u[1])) <= jump2pi(atan2(v[2], v[1]))
end

"""
check_method_implementation(interface::Type,
func_name,
args_funcs::AbstractVector{Function},
[print_results]::Bool=false
)::Bool
Check that a given (interface) function is implemented by all subtypes.
### Input
- `interface` -- parent interface type
- `func_name` -- function name
- `args_funcs` -- list of functions that each map a type to an argument
signature tuple
- `print_results` -- (optional, default: `false`) flag for printing intermediate
results
### Output
`true` iff all subtypes implement the given function.
### Notes
It is sufficient that a subinterface implements the function, i.e., it is not
required that every *concrete* type implements the function.
This function can also print all intermediate results to STDOUT.
### Examples
```julia
check_method_implementation(LazySet, σ,
Function[S -> (AbstractVector{Float64}, S)])
true
```
"""
function check_method_implementation(interface::Type,
func_name,
args_funcs::AbstractVector{Function};
print_results::Bool=false
)::Bool
for subtype in subtypes(interface)
found = false
for args_func in args_funcs
if method_exists(func_name, args_func(subtype))
if print_results
println("found implementation of $func_name for $subtype")
end
found = true
break
end
end
if !found && !check_method_implementation(subtype, func_name,
args_funcs,
print_results=print_results)
if print_results
println("no implementation of $func_name for $subtype")
end
return false
end
end
return true
end

0 comments on commit eb744f4

Please sign in to comment.