Doctests with approx

Is there any way to use approximate equality tests in the doctests?

I have various numerical functions whose output changes by eps() or so with some regularity — apparently depending on all sorts of obscure choices made by julia and/or llvm. Is it possible to pass a flag to jldtoctest so that it doesn’t error if the expected and evaluated output are approx equal to each other? I would prefer not to distract with explicit calls to round or anything like that.

I don’t think it parses the output, it just compares strings? But the Documenter.jl manual has an example using filters to allow it to ignore the last few digits.

1 Like

Makes sense.

Ah, didn’t know about this. Thanks!

Lucky for me, I really only need to test ~12 digits after the decimal in any number in the documentation, so I can use a sledgehammer. I added this argument to the makedocs call:

    doctestfilters = [
        # Ignore any digit after the 12th digit after a decimal, throughout the docs
        r"(?<=\d\.\d{12})\d+",
    ],

Note that this issue means we currently can’t apply substitutions with this argument, but for me a lookbehind worked fine.