MCPcopy Create free account
hub / github.com/numpy/numpy / test_divmod

Function test_divmod

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

Source from the content-addressed store, hash-verified

357
358
359def test_divmod(Poly):
360 # This checks commutation, not numerical correctness
361 c1 = list(random((4,)) + .5)
362 c2 = list(random((3,)) + .5)
363 c3 = list(random((2,)) + .5)
364 p1 = Poly(c1)
365 p2 = Poly(c2)
366 p3 = Poly(c3)
367 p4 = p1 * p2 + p3
368 c4 = list(p4.coef)
369 quo, rem = divmod(p4, p2)
370 assert_poly_almost_equal(quo, p1)
371 assert_poly_almost_equal(rem, p3)
372 quo, rem = divmod(p4, c2)
373 assert_poly_almost_equal(quo, p1)
374 assert_poly_almost_equal(rem, p3)
375 quo, rem = divmod(c4, p2)
376 assert_poly_almost_equal(quo, p1)
377 assert_poly_almost_equal(rem, p3)
378 quo, rem = divmod(p4, tuple(c2))
379 assert_poly_almost_equal(quo, p1)
380 assert_poly_almost_equal(rem, p3)
381 quo, rem = divmod(tuple(c4), p2)
382 assert_poly_almost_equal(quo, p1)
383 assert_poly_almost_equal(rem, p3)
384 quo, rem = divmod(p4, np.array(c2))
385 assert_poly_almost_equal(quo, p1)
386 assert_poly_almost_equal(rem, p3)
387 quo, rem = divmod(np.array(c4), p2)
388 assert_poly_almost_equal(quo, p1)
389 assert_poly_almost_equal(rem, p3)
390 quo, rem = divmod(p2, 2)
391 assert_poly_almost_equal(quo, 0.5*p2)
392 assert_poly_almost_equal(rem, Poly([0]))
393 quo, rem = divmod(2, p2)
394 assert_poly_almost_equal(quo, Poly([0]))
395 assert_poly_almost_equal(rem, Poly([2]))
396 assert_raises(TypeError, divmod, p1, Poly([0], domain=Poly.domain + 1))
397 assert_raises(TypeError, divmod, p1, Poly([0], window=Poly.window + 1))
398 if Poly is Polynomial:
399 assert_raises(TypeError, divmod, p1, Chebyshev([0]))
400 else:
401 assert_raises(TypeError, divmod, p1, Polynomial([0]))
402
403
404def 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