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

Method test_branches

numpy/core/tests/test_scalarmath.py:445–471  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

443 assert_equal(result.imag, ex[1])
444
445 def test_branches(self):
446 with np.errstate(all="ignore"):
447 for t in [np.complex64, np.complex128]:
448 # tupled (numerator, denominator, expected)
449 # for testing as expected == numerator/denominator
450 data = list()
451
452 # trigger branch: real(fabs(denom)) > imag(fabs(denom))
453 # followed by else condition as neither are == 0
454 data.append((( 2.0, 1.0), ( 2.0, 1.0), (1.0, 0.0)))
455
456 # trigger branch: real(fabs(denom)) > imag(fabs(denom))
457 # followed by if condition as both are == 0
458 # is performed in test_zero_division(), so this is skipped
459
460 # trigger else if branch: real(fabs(denom)) < imag(fabs(denom))
461 data.append((( 1.0, 2.0), ( 1.0, 2.0), (1.0, 0.0)))
462
463 for cases in data:
464 n = cases[0]
465 d = cases[1]
466 ex = cases[2]
467 result = t(complex(n[0], n[1])) / t(complex(d[0], d[1]))
468 # check real and imag parts separately to avoid comparison
469 # in array context, which does not account for signed zeros
470 assert_equal(result.real, ex[0])
471 assert_equal(result.imag, ex[1])
472
473
474class TestConversion:

Callers

nothing calls this directly

Calls 2

assert_equalFunction · 0.90
tFunction · 0.85

Tested by

no test coverage detected