MCPcopy Create free account
hub / github.com/python/cpython / test_symmetry

Method test_symmetry

Lib/test/test_statistics.py:344–366  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

342 self.assertTrue(approx_equal(b, a, tol=0, rel=rel))
343
344 def test_symmetry(self):
345 # Test that approx_equal(a, b) == approx_equal(b, a)
346 args = [-23, -2, 5, 107, 93568]
347 delta = 2
348 for a in args:
349 for type_ in (int, float, Decimal, Fraction):
350 x = type_(a)*100
351 y = x + delta
352 r = abs(delta/max(x, y))
353 # There are five cases to check:
354 # 1) actual error <= tol, <= rel
355 self.do_symmetry_test(x, y, tol=delta, rel=r)
356 self.do_symmetry_test(x, y, tol=delta+1, rel=2*r)
357 # 2) actual error > tol, > rel
358 self.do_symmetry_test(x, y, tol=delta-1, rel=r/2)
359 # 3) actual error <= tol, > rel
360 self.do_symmetry_test(x, y, tol=delta, rel=r/2)
361 # 4) actual error > tol, <= rel
362 self.do_symmetry_test(x, y, tol=delta-1, rel=r)
363 self.do_symmetry_test(x, y, tol=delta-1, rel=2*r)
364 # 5) exact equality test
365 self.do_symmetry_test(x, x, tol=0, rel=0)
366 self.do_symmetry_test(x, y, tol=0, rel=0)
367
368 def do_symmetry_test(self, a, b, tol, rel):
369 template = "approx_equal comparisons don't match for %r"

Callers

nothing calls this directly

Calls 2

do_symmetry_testMethod · 0.95
absFunction · 0.85

Tested by

no test coverage detected