MCPcopy Create free account
hub / github.com/ActiveState/code / test

Function test

recipes/Python/580610_Auto_differentiation/recipe-580610.py:300–310  ·  view source on GitHub ↗
(x_array, *testcases)

Source from the content-addressed store, hash-verified

298 return (y1 - y0) / (2.0 * eps)
299
300 def test(x_array, *testcases):
301 for f in testcases:
302 print(f.__name__.center(40))
303 print('-' * 40)
304 for x in map(Var, x_array):
305 y = f(x)
306 actual = d(y)
307 expected = numeric_derivative(f, x, 2**-16)
308 print('%7.3f %12.4f %12.4f' % (x, actual, expected))
309 assert math.isclose(expected, actual, rel_tol=1e-5)
310 print('')
311
312 def test_pow_const_base(x):
313 return 3.1 ** (2.3 * x + 0.4)

Callers 1

recipe-580610.pyFile · 0.70

Calls 6

printFunction · 0.85
mapFunction · 0.85
numeric_derivativeFunction · 0.85
centerMethod · 0.80
fFunction · 0.50
dFunction · 0.50

Tested by

no test coverage detected