(self)
| 2147 | |
| 2148 | @requires_IEEE_754 |
| 2149 | def test_mtestfile(self): |
| 2150 | fail_fmt = "{}: {}({!r}): {}" |
| 2151 | |
| 2152 | failures = [] |
| 2153 | for id, fn, arg, expected, flags in parse_mtestfile(math_testcases): |
| 2154 | func = getattr(math, fn) |
| 2155 | |
| 2156 | if 'invalid' in flags or 'divide-by-zero' in flags: |
| 2157 | expected = 'ValueError' |
| 2158 | elif 'overflow' in flags: |
| 2159 | expected = 'OverflowError' |
| 2160 | |
| 2161 | try: |
| 2162 | got = func(arg) |
| 2163 | except ValueError: |
| 2164 | got = 'ValueError' |
| 2165 | except OverflowError: |
| 2166 | got = 'OverflowError' |
| 2167 | |
| 2168 | # Default tolerances |
| 2169 | ulp_tol, abs_tol = 5, 0.0 |
| 2170 | |
| 2171 | # Exceptions to the defaults |
| 2172 | if fn == 'gamma': |
| 2173 | # Experimental results on one platform gave |
| 2174 | # an accuracy of <= 10 ulps across the entire float |
| 2175 | # domain. We weaken that to require 20 ulp accuracy. |
| 2176 | ulp_tol = 20 |
| 2177 | |
| 2178 | elif fn == 'lgamma': |
| 2179 | # we use a weaker accuracy test for lgamma; |
| 2180 | # lgamma only achieves an absolute error of |
| 2181 | # a few multiples of the machine accuracy, in |
| 2182 | # general. |
| 2183 | abs_tol = 1e-15 |
| 2184 | |
| 2185 | elif fn == 'erfc' and arg >= 0.0: |
| 2186 | # erfc has less-than-ideal accuracy for large |
| 2187 | # arguments (x ~ 25 or so), mainly due to the |
| 2188 | # error involved in computing exp(-x*x). |
| 2189 | # |
| 2190 | # Observed between CPython and mpmath at 25 dp: |
| 2191 | # x < 0 : err <= 2 ulp |
| 2192 | # 0 <= x < 1 : err <= 10 ulp |
| 2193 | # 1 <= x < 10 : err <= 100 ulp |
| 2194 | # 10 <= x < 20 : err <= 300 ulp |
| 2195 | # 20 <= x : < 600 ulp |
| 2196 | # |
| 2197 | if arg < 1.0: |
| 2198 | ulp_tol = 10 |
| 2199 | elif arg < 10.0: |
| 2200 | ulp_tol = 100 |
| 2201 | else: |
| 2202 | ulp_tol = 1000 |
| 2203 | |
| 2204 | failure = result_check(expected, got, ulp_tol, abs_tol) |
| 2205 | if failure is None: |
| 2206 | continue |
nothing calls this directly
no test coverage detected