MCPcopy Index your code
hub / github.com/numpy/numpy / test_divmod

Function test_divmod

numpy/polynomial/tests/test_classes.py:377–419  ·  view source on GitHub ↗
(Poly)

Source from the content-addressed store, hash-verified

375
376
377def test_divmod(Poly):
378 # This checks commutation, not numerical correctness
379 c1 = list(random((4,)) + .5)
380 c2 = list(random((3,)) + .5)
381 c3 = list(random((2,)) + .5)
382 p1 = Poly(c1)
383 p2 = Poly(c2)
384 p3 = Poly(c3)
385 p4 = p1 * p2 + p3
386 c4 = list(p4.coef)
387 quo, rem = divmod(p4, p2)
388 assert_poly_almost_equal(quo, p1)
389 assert_poly_almost_equal(rem, p3)
390 quo, rem = divmod(p4, c2)
391 assert_poly_almost_equal(quo, p1)
392 assert_poly_almost_equal(rem, p3)
393 quo, rem = divmod(c4, p2)
394 assert_poly_almost_equal(quo, p1)
395 assert_poly_almost_equal(rem, p3)
396 quo, rem = divmod(p4, tuple(c2))
397 assert_poly_almost_equal(quo, p1)
398 assert_poly_almost_equal(rem, p3)
399 quo, rem = divmod(tuple(c4), p2)
400 assert_poly_almost_equal(quo, p1)
401 assert_poly_almost_equal(rem, p3)
402 quo, rem = divmod(p4, np.array(c2))
403 assert_poly_almost_equal(quo, p1)
404 assert_poly_almost_equal(rem, p3)
405 quo, rem = divmod(np.array(c4), p2)
406 assert_poly_almost_equal(quo, p1)
407 assert_poly_almost_equal(rem, p3)
408 quo, rem = divmod(p2, 2)
409 assert_poly_almost_equal(quo, 0.5 * p2)
410 assert_poly_almost_equal(rem, Poly([0]))
411 quo, rem = divmod(2, p2)
412 assert_poly_almost_equal(quo, Poly([0]))
413 assert_poly_almost_equal(rem, Poly([2]))
414 assert_raises(TypeError, divmod, p1, Poly([0], domain=Poly.domain + 1))
415 assert_raises(TypeError, divmod, p1, Poly([0], window=Poly.window + 1))
416 if Poly is Polynomial:
417 assert_raises(TypeError, divmod, p1, Chebyshev([0]))
418 else:
419 assert_raises(TypeError, divmod, p1, Polynomial([0]))
420
421
422def test_roots(Poly):

Callers

nothing calls this directly

Calls 5

assert_raisesFunction · 0.90
ChebyshevClass · 0.90
PolynomialClass · 0.90
PolyFunction · 0.85
assert_poly_almost_equalFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…