MCPcopy Index your code
hub / github.com/python/cpython / assertClose

Method assertClose

Lib/test/test_complex.py:75–85  ·  view source on GitHub ↗

Return true iff complexes x and y "are close".

(self, x, y, eps=1e-9)

Source from the content-addressed store, hash-verified

73 unittest.TestCase.assertAlmostEqual(self, a, b)
74
75 def assertClose(self, x, y, eps=1e-9):
76 """Return true iff complexes x and y "are close"."""
77 # put the one with larger magnitude second
78 if abs(x) > abs(y):
79 x, y = y, x
80 if y == 0:
81 return abs(x) < eps
82 if x == 0:
83 return abs(y) < eps
84 # check that relative difference < eps
85 self.assertTrue(abs(x-y)/abs(y) < eps)
86
87 def check_div(self, x, y):
88 """Compute complex z=x*y, and check that z/x==y and z/y==x."""

Callers 1

check_divMethod · 0.95

Calls 2

absFunction · 0.85
assertTrueMethod · 0.80

Tested by

no test coverage detected