@@ -6,15 +6,43 @@ Lightweight package that defines an interface to invert functions.
66"""
77module InverseFunctions
88
9- using Test
10-
119include (" functions.jl" )
1210include (" inverse.jl" )
1311include (" setinverse.jl" )
14- include (" test.jl" )
12+
13+ """
14+ InverseFunctions.test_inverse(f, x; compare=isapprox, kwargs...)
15+
16+ Test if [`inverse(f)`](@ref) is implemented correctly.
17+
18+ The function tests (as a `Test.@testset`) if
19+
20+ * `compare(inverse(f)(f(x)), x) == true` and
21+ * `compare(inverse(inverse(f))(x), f(x)) == true`.
22+
23+ `kwargs...` are forwarded to `compare`.
24+
25+ !!! Note
26+ On Julia >= 1.9, you have to load the `Test` standard library to be able to use
27+ this function.
28+ """
29+ function test_inverse end
1530
1631@static if ! isdefined (Base, :get_extension )
17- include (" ../ext/DatesExt.jl" )
32+ include (" ../ext/InverseFunctionsDatesExt.jl" )
33+ include (" ../ext/InverseFunctionsTestExt.jl" )
34+ end
35+
36+ # Better error message if users forget to load Test
37+ if isdefined (Base, :get_extension ) && isdefined (Base. Experimental, :register_error_hint )
38+ function __init__ ()
39+ Base. Experimental. register_error_hint (MethodError) do io, exc, _, _
40+ if exc. f === test_inverse &&
41+ (Base. get_extension (InverseFunctions, :InverseFunctionsTest ) === nothing )
42+ print (io, " \n Did you forget to load Test?" )
43+ end
44+ end
45+ end
1846end
1947
2048end # module
0 commit comments